HyperPlatform Programmer's Reference
log.h
Go to the documentation of this file.
1 // Copyright (c) 2015-2017, Satoshi Tanda. All rights reserved.
2 // Use of this source code is governed by a MIT-style license that can be
3 // found in the LICENSE file.
4 
7 
8 #ifndef HYPERPLATFORM_LOG_H_
9 #define HYPERPLATFORM_LOG_H_
10 
11 #include <fltKernel.h>
12 
13 extern "C" {
15 //
16 // macro utilities
17 //
18 
34 #define HYPERPLATFORM_LOG_DEBUG(format, ...) \
35  LogpPrint(kLogpLevelDebug, __FUNCTION__, (format), __VA_ARGS__)
36 
38 #define HYPERPLATFORM_LOG_INFO(format, ...) \
39  LogpPrint(kLogpLevelInfo, __FUNCTION__, (format), __VA_ARGS__)
40 
42 #define HYPERPLATFORM_LOG_WARN(format, ...) \
43  LogpPrint(kLogpLevelWarn, __FUNCTION__, (format), __VA_ARGS__)
44 
46 #define HYPERPLATFORM_LOG_ERROR(format, ...) \
47  LogpPrint(kLogpLevelError, __FUNCTION__, (format), __VA_ARGS__)
48 
57 #define HYPERPLATFORM_LOG_DEBUG_SAFE(format, ...) \
58  LogpPrint(kLogpLevelDebug | kLogpLevelOptSafe, __FUNCTION__, (format), \
59  __VA_ARGS__)
60 
62 #define HYPERPLATFORM_LOG_INFO_SAFE(format, ...) \
63  LogpPrint(kLogpLevelInfo | kLogpLevelOptSafe, __FUNCTION__, (format), \
64  __VA_ARGS__)
65 
67 #define HYPERPLATFORM_LOG_WARN_SAFE(format, ...) \
68  LogpPrint(kLogpLevelWarn | kLogpLevelOptSafe, __FUNCTION__, (format), \
69  __VA_ARGS__)
70 
72 #define HYPERPLATFORM_LOG_ERROR_SAFE(format, ...) \
73  LogpPrint(kLogpLevelError | kLogpLevelOptSafe, __FUNCTION__, (format), \
74  __VA_ARGS__)
75 
77 //
78 // constants and macros
79 //
80 
82 static const auto kLogpLevelOptSafe = 0x1ul;
83 
84 static const auto kLogpLevelDebug = 0x10ul;
85 static const auto kLogpLevelInfo = 0x20ul;
86 static const auto kLogpLevelWarn = 0x40ul;
87 static const auto kLogpLevelError = 0x80ul;
88 
90 static const auto kLogPutLevelDebug =
92 
94 static const auto kLogPutLevelInfo =
96 
99 
101 static const auto kLogPutLevelError = kLogpLevelError;
102 
104 static const auto kLogPutLevelDisable = 0x00ul;
105 
107 static const auto kLogOptDisableTime = 0x100ul;
108 
110 static const auto kLogOptDisableFunctionName = 0x200ul;
111 
113 static const auto kLogOptDisableProcessorNumber = 0x400ul;
114 
116 static const auto kLogOptDisableDbgPrint = 0x800ul;
117 
119 //
120 // types
121 //
122 
124 //
125 // prototypes
126 //
127 
143 _IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS
144  LogInitialization(_In_ ULONG flag, _In_opt_ const wchar_t *file_path);
145 
153 _IRQL_requires_max_(PASSIVE_LEVEL) void LogRegisterReinitialization(
154  _In_ PDRIVER_OBJECT driver_object);
155 
157 _IRQL_requires_max_(PASSIVE_LEVEL) void LogIrpShutdownHandler();
158 
160 _IRQL_requires_max_(PASSIVE_LEVEL) void LogTermination();
161 
169 NTSTATUS LogpPrint(_In_ ULONG level, _In_z_ const char *function_name,
170  _In_z_ _Printf_format_string_ const char *format, ...);
171 
173 //
174 // variables
175 //
176 
178 //
179 // implementations
180 //
181 
182 } // extern "C"
183 
184 #endif // HYPERPLATFORM_LOG_H_
static const auto kLogPutLevelError
For LogInitialization(). Enables an ERROR level of logs.
Definition: log.h:101
void LogIrpShutdownHandler()
Terminates the log system. Should be called from an IRP_MJ_SHUTDOWN handler.
Definition: log.cpp:331
void LogRegisterReinitialization(_In_ PDRIVER_OBJECT driver_object)
Registers re-initialization.
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 kLogOptDisableFunctionName
For LogInitialization(). Do not log a current function name.
Definition: log.h:110
NTSTATUS LogInitialization(_In_ ULONG flag, _In_opt_ const wchar_t *file_path)
Initializes the log system.
void LogTermination()
Terminates the log system. Should be called from a DriverUnload routine.
Definition: log.cpp:348
static const auto kLogPutLevelDisable
For LogInitialization(). Disables all levels of logs.
Definition: log.h:104
static const auto kLogpLevelDebug
Bit mask for DEBUG level logs.
Definition: log.h:84
static const auto kLogOptDisableProcessorNumber
For LogInitialization(). Do not log a current processor number.
Definition: log.h:113
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 kLogPutLevelWarn
For LogInitialization(). Enables ERROR and WARN levels of logs.
Definition: log.h:98
static const auto kLogOptDisableDbgPrint
For LogInitialization(). Do not log to debug buffer.
Definition: log.h:116
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 kLogOptDisableTime
For LogInitialization(). Do not log a current time.
Definition: log.h:107
static const auto kLogpLevelWarn
Bit mask for WARN level logs.
Definition: log.h:86
static const auto kLogPutLevelInfo
For LogInitialization(). Enables ERROR, WARN and INFO levels of logs.
Definition: log.h:94
static const auto kLogPutLevelDebug
For LogInitialization(). Enables all levels of logs.
Definition: log.h:90