FreeRDP
Loading...
Searching...
No Matches
include/winpr/wlog.h
1
23#ifndef WINPR_LOG_H
24#define WINPR_LOG_H
25
26#ifdef __cplusplus
27extern "C"
28{
29#endif
30
31#include <stdarg.h>
32
33#include <winpr/platform.h>
34#include <winpr/wtypes.h>
35#include <winpr/winpr.h>
36#include <winpr/synch.h>
37#include <winpr/thread.h>
38
42#define WLOG_TRACE 0
43#define WLOG_DEBUG 1
44#define WLOG_INFO 2
45#define WLOG_WARN 3
46#define WLOG_ERROR 4
47#define WLOG_FATAL 5
48#define WLOG_OFF 6
49#define WLOG_LEVEL_INHERIT 0xFFFF
50
54#define WLOG_MESSAGE_TEXT 0
55#define WLOG_MESSAGE_DATA 1
56#define WLOG_MESSAGE_IMAGE 2
57#define WLOG_MESSAGE_PACKET 3
65#define WLOG_APPENDER_CONSOLE 0
66#define WLOG_APPENDER_FILE 1
67#define WLOG_APPENDER_BINARY 2
68#define WLOG_APPENDER_CALLBACK 3
69#define WLOG_APPENDER_SYSLOG 4
70#define WLOG_APPENDER_JOURNALD 5
71#define WLOG_APPENDER_UDP 6
72
73 typedef struct
74 {
75 DWORD Type;
76
77 DWORD Level;
78
79 LPSTR PrefixString;
80
81 LPCSTR FormatString;
82 LPCSTR TextString;
83
84 size_t LineNumber; /* __LINE__ */
85 LPCSTR FileName; /* __FILE__ */
86 LPCSTR FunctionName; /* __func__ */
87
88 /* Data Message */
89
90 void* Data;
91 size_t Length;
92
93 /* Image Message */
94
95 void* ImageData;
96 size_t ImageWidth;
97 size_t ImageHeight;
98 size_t ImageBpp;
99
100 /* Packet Message */
101
102 void* PacketData;
103 size_t PacketLength;
104 DWORD PacketFlags;
105 } wLogMessage;
106 typedef struct s_wLogLayout wLogLayout;
107 typedef struct s_wLogAppender wLogAppender;
108 typedef struct s_wLog wLog;
109
110#define WLOG_PACKET_INBOUND 1
111#define WLOG_PACKET_OUTBOUND 2
112
126 WINPR_ATTR_FORMAT_ARG(6, 7)
127 WINPR_API BOOL WLog_PrintTextMessage(wLog* log, DWORD level, size_t line, const char* file,
128 const char* function, WINPR_FORMAT_ARG const char* fmt,
129 ...);
130
144 WINPR_ATTR_FORMAT_ARG(6, 0)
145 WINPR_API BOOL WLog_PrintTextMessageVA(wLog* log, DWORD level, size_t line, const char* file,
146 const char* function, WINPR_FORMAT_ARG const char* fmt,
147 va_list args);
148
161 WINPR_API BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, size_t line,
162 const char* file, const char* function, ...);
163
176 WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, size_t line,
177 const char* file, const char* function, va_list args);
178
179 WINPR_API wLog* WLog_GetRoot(void);
180 WINPR_API wLog* WLog_Get(LPCSTR name);
181 WINPR_API DWORD WLog_GetLogLevel(wLog* log);
182 WINPR_API BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level);
183
194 WINPR_API BOOL WLog_SetContext(wLog* log, const char* (*fkt)(void*), void* context);
195
196#define WLog_Print_unchecked(_log, _log_level, ...) \
197 do \
198 { \
199 WLog_PrintTextMessage(_log, _log_level, __LINE__, __FILE__, __func__, __VA_ARGS__); \
200 } while (0)
201
202#define WLog_Print(_log, _log_level, ...) \
203 do \
204 { \
205 if (WLog_IsLevelActive(_log, _log_level)) \
206 { \
207 WLog_Print_unchecked(_log, _log_level, __VA_ARGS__); \
208 } \
209 } while (0)
210
211#define WLog_Print_tag(_tag, _log_level, ...) \
212 do \
213 { \
214 static wLog* _log_cached_ptr = NULL; \
215 if (!_log_cached_ptr) \
216 _log_cached_ptr = WLog_Get(_tag); \
217 WLog_Print(_log_cached_ptr, _log_level, __VA_ARGS__); \
218 } while (0)
219
220#define WLog_PrintVA_unchecked(_log, _log_level, _args) \
221 do \
222 { \
223 WLog_PrintTextMessageVA(_log, _log_level, __LINE__, __FILE__, __func__, _args); \
224 } while (0)
225
226#define WLog_PrintVA(_log, _log_level, _args) \
227 do \
228 { \
229 if (WLog_IsLevelActive(_log, _log_level)) \
230 { \
231 WLog_PrintVA_unchecked(_log, _log_level, _args); \
232 } \
233 } while (0)
234
235#define WLog_Data(_log, _log_level, ...) \
236 do \
237 { \
238 if (WLog_IsLevelActive(_log, _log_level)) \
239 { \
240 WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, __func__, \
241 __VA_ARGS__); \
242 } \
243 } while (0)
244
245#define WLog_Image(_log, _log_level, ...) \
246 do \
247 { \
248 if (WLog_IsLevelActive(_log, _log_level)) \
249 { \
250 WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, __func__, \
251 __VA_ARGS__); \
252 } \
253 } while (0)
254
255#define WLog_Packet(_log, _log_level, ...) \
256 do \
257 { \
258 if (WLog_IsLevelActive(_log, _log_level)) \
259 { \
260 WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, __LINE__, __FILE__, __func__, \
261 __VA_ARGS__); \
262 } \
263 } while (0)
264
265 WINPR_ATTR_FORMAT_ARG(6, 7)
266 static inline void WLog_Print_dbg_tag(const char* WINPR_RESTRICT tag, DWORD log_level,
267 size_t line, const char* file, const char* fkt,
268 WINPR_FORMAT_ARG const char* fmt, ...)
269 {
270 static wLog* log_cached_ptr = NULL;
271 if (!log_cached_ptr)
272 log_cached_ptr = WLog_Get(tag);
273
274 if (WLog_IsLevelActive(log_cached_ptr, log_level))
275 {
276 va_list ap;
277 va_start(ap, fmt);
278 WLog_PrintTextMessageVA(log_cached_ptr, log_level, line, file, fkt, fmt, ap);
279 va_end(ap);
280 }
281 }
282
283#define WLog_LVL(tag, lvl, ...) \
284 WLog_Print_dbg_tag(tag, lvl, __LINE__, __FILE__, __func__, __VA_ARGS__)
285#define WLog_VRB(tag, ...) \
286 WLog_Print_dbg_tag(tag, WLOG_TRACE, __LINE__, __FILE__, __func__, __VA_ARGS__)
287#define WLog_DBG(tag, ...) \
288 WLog_Print_dbg_tag(tag, WLOG_DEBUG, __LINE__, __FILE__, __func__, __VA_ARGS__)
289#define WLog_INFO(tag, ...) \
290 WLog_Print_dbg_tag(tag, WLOG_INFO, __LINE__, __FILE__, __func__, __VA_ARGS__)
291#define WLog_WARN(tag, ...) \
292 WLog_Print_dbg_tag(tag, WLOG_WARN, __LINE__, __FILE__, __func__, __VA_ARGS__)
293#define WLog_ERR(tag, ...) \
294 WLog_Print_dbg_tag(tag, WLOG_ERROR, __LINE__, __FILE__, __func__, __VA_ARGS__)
295#define WLog_FATAL(tag, ...) \
296 WLog_Print_dbg_tag(tag, WLOG_FATAL, __LINE__, __FILE__, __func__, __VA_ARGS__)
297
298 WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
299 WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level);
300 WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter);
301
302 WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
303 WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
304 WINPR_API BOOL WLog_OpenAppender(wLog* log);
305 WINPR_API BOOL WLog_CloseAppender(wLog* log);
306 WINPR_API BOOL WLog_ConfigureAppender(wLogAppender* appender, const char* setting, void* value);
307
308 WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
309 WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
310
311#if defined(WITH_WINPR_DEPRECATED)
313 WINPR_DEPRECATED(WINPR_API BOOL WLog_Init(void));
315 WINPR_DEPRECATED(WINPR_API BOOL WLog_Uninit(void));
316#endif
317
318 typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage* msg);
319 typedef BOOL (*wLogCallbackData_t)(const wLogMessage* msg);
320 typedef BOOL (*wLogCallbackImage_t)(const wLogMessage* msg);
321 typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage* msg);
322
323 typedef struct
324 {
325 wLogCallbackData_t data;
326 wLogCallbackImage_t image;
327 wLogCallbackMessage_t message;
328 wLogCallbackPackage_t package;
330
331#ifdef __cplusplus
332}
333#endif
334
335#endif /* WINPR_WLOG_H */