HyperPlatform Programmer's Reference
Macros | Functions | Variables
log.h File Reference

Declares interfaces to logging functions. More...

#include <fltKernel.h>
Include dependency graph for log.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define HYPERPLATFORM_LOG_DEBUG(format, ...)   LogpPrint(kLogpLevelDebug, __FUNCTION__, (format), __VA_ARGS__)
 Logs a message as respective severity. More...
 
#define HYPERPLATFORM_LOG_INFO(format, ...)   LogpPrint(kLogpLevelInfo, __FUNCTION__, (format), __VA_ARGS__)
 
#define HYPERPLATFORM_LOG_WARN(format, ...)   LogpPrint(kLogpLevelWarn, __FUNCTION__, (format), __VA_ARGS__)
 
#define HYPERPLATFORM_LOG_ERROR(format, ...)   LogpPrint(kLogpLevelError, __FUNCTION__, (format), __VA_ARGS__)
 
#define HYPERPLATFORM_LOG_DEBUG_SAFE(format, ...)
 Buffers a message as respective severity. More...
 
#define HYPERPLATFORM_LOG_INFO_SAFE(format, ...)
 
#define HYPERPLATFORM_LOG_WARN_SAFE(format, ...)
 
#define HYPERPLATFORM_LOG_ERROR_SAFE(format, ...)
 

Functions

NTSTATUS LogInitialization (_In_ ULONG flag, _In_opt_ const wchar_t *file_path)
 Initializes the log system. More...
 
void LogRegisterReinitialization (_In_ PDRIVER_OBJECT driver_object)
 Registers re-initialization. More...
 
void LogIrpShutdownHandler ()
 Terminates the log system. Should be called from an IRP_MJ_SHUTDOWN handler. More...
 
void LogTermination ()
 Terminates the log system. Should be called from a DriverUnload routine. More...
 
NTSTATUS LogpPrint (_In_ ULONG level, _In_z_ const char *function_name, _In_z_ _Printf_format_string_ const char *format,...)
 Logs a message; use HYPERPLATFORM_LOG_*() macros instead. More...
 

Variables

static const auto kLogpLevelOptSafe = 0x1ul
 Save this log to buffer and not try to write to a log file. More...
 
static const auto kLogpLevelDebug = 0x10ul
 Bit mask for DEBUG level logs. More...
 
static const auto kLogpLevelInfo = 0x20ul
 Bit mask for INFO level logs. More...
 
static const auto kLogpLevelWarn = 0x40ul
 Bit mask for WARN level logs. More...
 
static const auto kLogpLevelError = 0x80ul
 Bit mask for ERROR level logs. More...
 
static const auto kLogPutLevelDebug
 For LogInitialization(). Enables all levels of logs. More...
 
static const auto kLogPutLevelInfo
 For LogInitialization(). Enables ERROR, WARN and INFO levels of logs. More...
 
static const auto kLogPutLevelWarn = kLogpLevelError | kLogpLevelWarn
 For LogInitialization(). Enables ERROR and WARN levels of logs. More...
 
static const auto kLogPutLevelError = kLogpLevelError
 For LogInitialization(). Enables an ERROR level of logs. More...
 
static const auto kLogPutLevelDisable = 0x00ul
 For LogInitialization(). Disables all levels of logs. More...
 
static const auto kLogOptDisableTime = 0x100ul
 For LogInitialization(). Do not log a current time. More...
 
static const auto kLogOptDisableFunctionName = 0x200ul
 For LogInitialization(). Do not log a current function name. More...
 
static const auto kLogOptDisableProcessorNumber = 0x400ul
 For LogInitialization(). Do not log a current processor number. More...
 
static const auto kLogOptDisableDbgPrint = 0x800ul
 For LogInitialization(). Do not log to debug buffer. More...
 

Detailed Description

Declares interfaces to logging functions.

Definition in file log.h.

Macro Definition Documentation

◆ HYPERPLATFORM_LOG_DEBUG

#define HYPERPLATFORM_LOG_DEBUG (   format,
  ... 
)    LogpPrint(kLogpLevelDebug, __FUNCTION__, (format), __VA_ARGS__)

Logs a message as respective severity.

Parameters
formatA format string
Returns
STATUS_SUCCESS on success

Debug prints or buffers a log message with information about current execution context such as time, PID and TID as respective severity. Here are some guide lines to decide which level is appropriate:

  • DEBUG: info for only developers.
  • INFO: info for all users.
  • WARN: info may require some attention but does not prevent the program working properly.
  • ERROR: info about issues may stop the program working properly.

A message should not exceed 512 bytes after all string construction is done; otherwise this macro fails to log and returns non STATUS_SUCCESS.

Definition at line 34 of file log.h.

◆ HYPERPLATFORM_LOG_DEBUG_SAFE

#define HYPERPLATFORM_LOG_DEBUG_SAFE (   format,
  ... 
)
Value:
LogpPrint(kLogpLevelDebug | kLogpLevelOptSafe, __FUNCTION__, (format), \
__VA_ARGS__)
static const auto kLogpLevelOptSafe
Save this log to buffer and not try to write to a log file.
Definition: log.h:82
static const auto kLogpLevelDebug
Bit mask for DEBUG level logs.
Definition: log.h:84
NTSTATUS LogpPrint(_In_ ULONG level, _In_z_ const char *function_name, _In_z_ _Printf_format_string_ const char *format,...)
Logs a message; use HYPERPLATFORM_LOG_*() macros instead.

Buffers a message as respective severity.

Parameters
formatA format string
Returns
STATUS_SUCCESS on success

Buffers the log to buffer and neither calls DbgPrint() nor writes to a file. It is strongly recommended to use it when a status of a system is not expectable in order to avoid system instability.

See also
HYPERPLATFORM_LOG_DEBUG

Definition at line 57 of file log.h.

◆ HYPERPLATFORM_LOG_ERROR

#define HYPERPLATFORM_LOG_ERROR (   format,
  ... 
)    LogpPrint(kLogpLevelError, __FUNCTION__, (format), __VA_ARGS__)
See also
HYPERPLATFORM_LOG_DEBUG

Definition at line 46 of file log.h.

◆ HYPERPLATFORM_LOG_ERROR_SAFE

#define HYPERPLATFORM_LOG_ERROR_SAFE (   format,
  ... 
)
Value:
LogpPrint(kLogpLevelError | kLogpLevelOptSafe, __FUNCTION__, (format), \
__VA_ARGS__)
static const auto kLogpLevelOptSafe
Save this log to buffer and not try to write to a log file.
Definition: log.h:82
static const auto kLogpLevelError
Bit mask for ERROR level logs.
Definition: log.h:87
NTSTATUS LogpPrint(_In_ ULONG level, _In_z_ const char *function_name, _In_z_ _Printf_format_string_ const char *format,...)
Logs a message; use HYPERPLATFORM_LOG_*() macros instead.
See also
HYPERPLATFORM_LOG_DEBUG_SAFE

Definition at line 72 of file log.h.

◆ HYPERPLATFORM_LOG_INFO

#define HYPERPLATFORM_LOG_INFO (   format,
  ... 
)    LogpPrint(kLogpLevelInfo, __FUNCTION__, (format), __VA_ARGS__)
See also
HYPERPLATFORM_LOG_DEBUG

Definition at line 38 of file log.h.

◆ HYPERPLATFORM_LOG_INFO_SAFE

#define HYPERPLATFORM_LOG_INFO_SAFE (   format,
  ... 
)
Value:
LogpPrint(kLogpLevelInfo | kLogpLevelOptSafe, __FUNCTION__, (format), \
__VA_ARGS__)
static const auto kLogpLevelOptSafe
Save this log to buffer and not try to write to a log file.
Definition: log.h:82
static const auto kLogpLevelInfo
Bit mask for INFO level logs.
Definition: log.h:85
NTSTATUS LogpPrint(_In_ ULONG level, _In_z_ const char *function_name, _In_z_ _Printf_format_string_ const char *format,...)
Logs a message; use HYPERPLATFORM_LOG_*() macros instead.
See also
HYPERPLATFORM_LOG_DEBUG_SAFE

Definition at line 62 of file log.h.

◆ HYPERPLATFORM_LOG_WARN

#define HYPERPLATFORM_LOG_WARN (   format,
  ... 
)    LogpPrint(kLogpLevelWarn, __FUNCTION__, (format), __VA_ARGS__)
See also
HYPERPLATFORM_LOG_DEBUG

Definition at line 42 of file log.h.

◆ HYPERPLATFORM_LOG_WARN_SAFE

#define HYPERPLATFORM_LOG_WARN_SAFE (   format,
  ... 
)
Value:
LogpPrint(kLogpLevelWarn | kLogpLevelOptSafe, __FUNCTION__, (format), \
__VA_ARGS__)
static const auto kLogpLevelOptSafe
Save this log to buffer and not try to write to a log file.
Definition: log.h:82
NTSTATUS LogpPrint(_In_ ULONG level, _In_z_ const char *function_name, _In_z_ _Printf_format_string_ const char *format,...)
Logs a message; use HYPERPLATFORM_LOG_*() macros instead.
static const auto kLogpLevelWarn
Bit mask for WARN level logs.
Definition: log.h:86
See also
HYPERPLATFORM_LOG_DEBUG_SAFE

Definition at line 67 of file log.h.

Function Documentation

◆ LogInitialization()

NTSTATUS LogInitialization ( _In_ ULONG  flag,
_In_opt_ const wchar_t *  file_path 
)

Initializes the log system.

Parameters
flagA OR-ed flag to control a log level and options
file_pathA log file path
Returns
STATUS_SUCCESS on success, STATUS_REINITIALIZATION_NEEDED when re-initialization with LogRegisterReinitialization() is required, or else on failure.

Allocates internal log buffers, initializes related resources, starts a log flush thread and creates a log file if requested. This function returns STATUS_REINITIALIZATION_NEEDED if a file-system is not initialized yet. In that case, a driver must call LogRegisterReinitialization() for completing initialization.

flag is a OR-ed value of kLogPutLevel* and kLogOpt*. For example, kLogPutLevelDebug | kLogOptDisableFunctionName.

◆ LogIrpShutdownHandler()

void LogIrpShutdownHandler ( )

Terminates the log system. Should be called from an IRP_MJ_SHUTDOWN handler.

Definition at line 331 of file log.cpp.

Here is the call graph for this function:

◆ LogpPrint()

NTSTATUS LogpPrint ( _In_ ULONG  level,
_In_z_ const char *  function_name,
_In_z_ _Printf_format_string_ const char *  format,
  ... 
)

Logs a message; use HYPERPLATFORM_LOG_*() macros instead.

Parameters
levelSeverity of a message
function_nameA name of a function called this function
formatA format string
Returns
STATUS_SUCCESS on success
See also
HYPERPLATFORM_LOG_DEBUG
HYPERPLATFORM_LOG_DEBUG_SAFE

◆ LogRegisterReinitialization()

void LogRegisterReinitialization ( _In_ PDRIVER_OBJECT  driver_object)

Registers re-initialization.

Parameters
driver_objectA driver object being loaded

A driver must call this function, or call LogTermination() and return non STATUS_SUCCESS from DriverEntry() if LogInitialization() returned STATUS_REINITIALIZATION_NEEDED. If this function is called, DriverEntry() must return STATUS_SUCCESS.

◆ LogTermination()

void LogTermination ( )

Terminates the log system. Should be called from a DriverUnload routine.

Definition at line 348 of file log.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ kLogOptDisableDbgPrint

const auto kLogOptDisableDbgPrint = 0x800ul
static

For LogInitialization(). Do not log to debug buffer.

Definition at line 116 of file log.h.

◆ kLogOptDisableFunctionName

const auto kLogOptDisableFunctionName = 0x200ul
static

For LogInitialization(). Do not log a current function name.

Definition at line 110 of file log.h.

◆ kLogOptDisableProcessorNumber

const auto kLogOptDisableProcessorNumber = 0x400ul
static

For LogInitialization(). Do not log a current processor number.

Definition at line 113 of file log.h.

◆ kLogOptDisableTime

const auto kLogOptDisableTime = 0x100ul
static

For LogInitialization(). Do not log a current time.

Definition at line 107 of file log.h.

◆ kLogpLevelDebug

const auto kLogpLevelDebug = 0x10ul
static

Bit mask for DEBUG level logs.

Definition at line 84 of file log.h.

◆ kLogpLevelError

const auto kLogpLevelError = 0x80ul
static

Bit mask for ERROR level logs.

Definition at line 87 of file log.h.

◆ kLogpLevelInfo

const auto kLogpLevelInfo = 0x20ul
static

Bit mask for INFO level logs.

Definition at line 85 of file log.h.

◆ kLogpLevelOptSafe

const auto kLogpLevelOptSafe = 0x1ul
static

Save this log to buffer and not try to write to a log file.

Definition at line 82 of file log.h.

◆ kLogpLevelWarn

const auto kLogpLevelWarn = 0x40ul
static

Bit mask for WARN level logs.

Definition at line 86 of file log.h.

◆ kLogPutLevelDebug

const auto kLogPutLevelDebug
static
Initial value:
=
static const auto kLogpLevelDebug
Bit mask for DEBUG level logs.
Definition: log.h:84
static const auto kLogpLevelInfo
Bit mask for INFO level logs.
Definition: log.h:85
static const auto kLogpLevelError
Bit mask for ERROR level logs.
Definition: log.h:87
static const auto kLogpLevelWarn
Bit mask for WARN level logs.
Definition: log.h:86

For LogInitialization(). Enables all levels of logs.

Definition at line 90 of file log.h.

◆ kLogPutLevelDisable

const auto kLogPutLevelDisable = 0x00ul
static

For LogInitialization(). Disables all levels of logs.

Definition at line 104 of file log.h.

◆ kLogPutLevelError

const auto kLogPutLevelError = kLogpLevelError
static

For LogInitialization(). Enables an ERROR level of logs.

Definition at line 101 of file log.h.

◆ kLogPutLevelInfo

const auto kLogPutLevelInfo
static
Initial value:
=
static const auto kLogpLevelInfo
Bit mask for INFO level logs.
Definition: log.h:85
static const auto kLogpLevelError
Bit mask for ERROR level logs.
Definition: log.h:87
static const auto kLogpLevelWarn
Bit mask for WARN level logs.
Definition: log.h:86

For LogInitialization(). Enables ERROR, WARN and INFO levels of logs.

Definition at line 94 of file log.h.

◆ kLogPutLevelWarn

const auto kLogPutLevelWarn = kLogpLevelError | kLogpLevelWarn
static

For LogInitialization(). Enables ERROR and WARN levels of logs.

Definition at line 98 of file log.h.