FreeRDP
include/winpr/wlog.h
1 
23 #ifndef WINPR_LOG_H
24 #define WINPR_LOG_H
25 
26 #ifdef __cplusplus
27 extern "C"
28 {
29 #endif
30 
31 #include <stdarg.h>
32 #include <winpr/wtypes.h>
33 #include <winpr/winpr.h>
34 #include <winpr/synch.h>
35 #include <winpr/thread.h>
36 
40 #define WLOG_TRACE 0
41 #define WLOG_DEBUG 1
42 #define WLOG_INFO 2
43 #define WLOG_WARN 3
44 #define WLOG_ERROR 4
45 #define WLOG_FATAL 5
46 #define WLOG_OFF 6
47 #define WLOG_LEVEL_INHERIT 0xFFFF
48 
52 #define WLOG_MESSAGE_TEXT 0
53 #define WLOG_MESSAGE_DATA 1
54 #define WLOG_MESSAGE_IMAGE 2
55 #define WLOG_MESSAGE_PACKET 3
56 
60 #define WLOG_APPENDER_CONSOLE 0
61 #define WLOG_APPENDER_FILE 1
62 #define WLOG_APPENDER_BINARY 2
63 #define WLOG_APPENDER_CALLBACK 3
64 #define WLOG_APPENDER_SYSLOG 4
65 #define WLOG_APPENDER_JOURNALD 5
66 #define WLOG_APPENDER_UDP 6
67 
68  typedef struct
69  {
70  DWORD Type;
71 
72  DWORD Level;
73 
74  LPSTR PrefixString;
75 
76  LPCSTR FormatString;
77  LPCSTR TextString;
78 
79  size_t LineNumber; /* __LINE__ */
80  LPCSTR FileName; /* __FILE__ */
81  LPCSTR FunctionName; /* __func__ */
82 
83  /* Data Message */
84 
85  void* Data;
86  size_t Length;
87 
88  /* Image Message */
89 
90  void* ImageData;
91  size_t ImageWidth;
92  size_t ImageHeight;
93  size_t ImageBpp;
94 
95  /* Packet Message */
96 
97  void* PacketData;
98  size_t PacketLength;
99  DWORD PacketFlags;
100  } wLogMessage;
101  typedef struct s_wLogLayout wLogLayout;
102  typedef struct s_wLogAppender wLogAppender;
103  typedef struct s_wLog wLog;
104 
105 #define WLOG_PACKET_INBOUND 1
106 #define WLOG_PACKET_OUTBOUND 2
107 
108  WINPR_API BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, size_t line,
109  const char* file, const char* function, ...);
110  WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, size_t line,
111  const char* file, const char* function, va_list args);
112 
113  WINPR_API wLog* WLog_GetRoot(void);
114  WINPR_API wLog* WLog_Get(LPCSTR name);
115  WINPR_API DWORD WLog_GetLogLevel(wLog* log);
116  WINPR_API BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level);
117 
128  WINPR_API BOOL WLog_SetContext(wLog* log, const char* (*fkt)(void*), void* context);
129 
130 #define WLog_Print_unchecked(_log, _log_level, ...) \
131  do \
132  { \
133  WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, _log_level, __LINE__, __FILE__, __func__, \
134  __VA_ARGS__); \
135  } while (0)
136 
137 #define WLog_Print(_log, _log_level, ...) \
138  do \
139  { \
140  if (WLog_IsLevelActive(_log, _log_level)) \
141  { \
142  WLog_Print_unchecked(_log, _log_level, __VA_ARGS__); \
143  } \
144  } while (0)
145 
146 #define WLog_Print_tag(_tag, _log_level, ...) \
147  do \
148  { \
149  static wLog* _log_cached_ptr = NULL; \
150  if (!_log_cached_ptr) \
151  _log_cached_ptr = WLog_Get(_tag); \
152  WLog_Print(_log_cached_ptr, _log_level, __VA_ARGS__); \
153  } while (0)
154 
155 #define WLog_PrintVA_unchecked(_log, _log_level, _args) \
156  do \
157  { \
158  WLog_PrintMessageVA(_log, WLOG_MESSAGE_TEXT, _log_level, __LINE__, __FILE__, __func__, \
159  _args); \
160  } while (0)
161 
162 #define WLog_PrintVA(_log, _log_level, _args) \
163  do \
164  { \
165  if (WLog_IsLevelActive(_log, _log_level)) \
166  { \
167  WLog_PrintVA_unchecked(_log, _log_level, _args); \
168  } \
169  } while (0)
170 
171 #define WLog_Data(_log, _log_level, ...) \
172  do \
173  { \
174  if (WLog_IsLevelActive(_log, _log_level)) \
175  { \
176  WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, __func__, \
177  __VA_ARGS__); \
178  } \
179  } while (0)
180 
181 #define WLog_Image(_log, _log_level, ...) \
182  do \
183  { \
184  if (WLog_IsLevelActive(_log, _log_level)) \
185  { \
186  WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, __func__, \
187  __VA_ARGS__); \
188  } \
189  } while (0)
190 
191 #define WLog_Packet(_log, _log_level, ...) \
192  do \
193  { \
194  if (WLog_IsLevelActive(_log, _log_level)) \
195  { \
196  WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, __LINE__, __FILE__, __func__, \
197  __VA_ARGS__); \
198  } \
199  } while (0)
200 
201 #define WLog_LVL(tag, lvl, ...) WLog_Print_tag(tag, lvl, __VA_ARGS__)
202 #define WLog_VRB(tag, ...) WLog_Print_tag(tag, WLOG_TRACE, __VA_ARGS__)
203 #define WLog_DBG(tag, ...) WLog_Print_tag(tag, WLOG_DEBUG, __VA_ARGS__)
204 #define WLog_INFO(tag, ...) WLog_Print_tag(tag, WLOG_INFO, __VA_ARGS__)
205 #define WLog_WARN(tag, ...) WLog_Print_tag(tag, WLOG_WARN, __VA_ARGS__)
206 #define WLog_ERR(tag, ...) WLog_Print_tag(tag, WLOG_ERROR, __VA_ARGS__)
207 #define WLog_FATAL(tag, ...) WLog_Print_tag(tag, WLOG_FATAL, __VA_ARGS__)
208 
209  WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
210  WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level);
211  WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter);
212 
213  WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
214  WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
215  WINPR_API BOOL WLog_OpenAppender(wLog* log);
216  WINPR_API BOOL WLog_CloseAppender(wLog* log);
217  WINPR_API BOOL WLog_ConfigureAppender(wLogAppender* appender, const char* setting, void* value);
218 
219  WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
220  WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
221 
222 #if defined(WITH_WINPR_DEPRECATED)
224  WINPR_API WINPR_DEPRECATED(BOOL WLog_Init(void));
226  WINPR_API WINPR_DEPRECATED(BOOL WLog_Uninit(void));
227 #endif
228 
229  typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage* msg);
230  typedef BOOL (*wLogCallbackData_t)(const wLogMessage* msg);
231  typedef BOOL (*wLogCallbackImage_t)(const wLogMessage* msg);
232  typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage* msg);
233 
234  typedef struct
235  {
236  wLogCallbackData_t data;
237  wLogCallbackImage_t image;
238  wLogCallbackMessage_t message;
239  wLogCallbackPackage_t package;
240  } wLogCallbacks;
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif /* WINPR_WLOG_H */