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