2 * WinPR: Windows Portable Runtime
5 * Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6 * Copyright 2015 Thincast Technologies GmbH
7 * Copyright 2015 Bernhard Miklautz <bernhard.miklautz@thincast.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
32 #include <winpr/wtypes.h>
33 #include <winpr/synch.h>
34 #include <winpr/thread.h>
46 #define WLOG_LEVEL_INHERIT 0xFFFF
51 #define WLOG_MESSAGE_TEXT 0
52 #define WLOG_MESSAGE_DATA 1
53 #define WLOG_MESSAGE_IMAGE 2
54 #define WLOG_MESSAGE_PACKET 3
59 #define WLOG_APPENDER_CONSOLE 0
60 #define WLOG_APPENDER_FILE 1
61 #define WLOG_APPENDER_BINARY 2
62 #define WLOG_APPENDER_CALLBACK 3
63 #define WLOG_APPENDER_SYSLOG 4
64 #define WLOG_APPENDER_JOURNALD 5
65 #define WLOG_APPENDER_UDP 6
78 DWORD LineNumber; /* __LINE__ */
79 LPCSTR FileName; /* __FILE__ */
80 LPCSTR FunctionName; /* __FUNCTION__ */
100 typedef struct _wLogMessage wLogMessage;
101 typedef struct _wLogLayout wLogLayout;
102 typedef struct _wLogAppender wLogAppender;
103 typedef struct _wLog wLog;
105 #define WLOG_PACKET_INBOUND 1
106 #define WLOG_PACKET_OUTBOUND 2
108 WINPR_API BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line,
109 const char* file, const char* function, ...);
110 WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, DWORD line,
111 const char* file, const char* function, va_list args);
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);
118 #define WLog_Print(_log, _log_level, ...) \
121 if (WLog_IsLevelActive(_log, _log_level)) \
123 WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, _log_level, __LINE__, __FILE__, \
124 __FUNCTION__, __VA_ARGS__); \
128 #define WLog_Print_tag(_tag, _log_level, ...) \
131 static wLog* _log_cached_ptr = NULL; \
132 if (!_log_cached_ptr) \
133 _log_cached_ptr = WLog_Get(_tag); \
134 WLog_Print(_log_cached_ptr, _log_level, __VA_ARGS__); \
137 #define WLog_PrintVA(_log, _log_level, _args) \
140 if (WLog_IsLevelActive(_log, _log_level)) \
142 WLog_PrintMessageVA(_log, WLOG_MESSAGE_TEXT, _log_level, __LINE__, __FILE__, \
143 __FUNCTION__, _args); \
147 #define WLog_Data(_log, _log_level, ...) \
150 if (WLog_IsLevelActive(_log, _log_level)) \
152 WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, \
153 __FUNCTION__, __VA_ARGS__); \
157 #define WLog_Image(_log, _log_level, ...) \
160 if (WLog_IsLevelActive(_log, _log_level)) \
162 WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, \
163 __FUNCTION__, __VA_ARGS__); \
167 #define WLog_Packet(_log, _log_level, ...) \
170 if (WLog_IsLevelActive(_log, _log_level)) \
172 WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, __LINE__, __FILE__, \
173 __FUNCTION__, __VA_ARGS__); \
177 #define WLog_LVL(tag, lvl, ...) WLog_Print_tag(tag, lvl, __VA_ARGS__)
178 #define WLog_VRB(tag, ...) WLog_Print_tag(tag, WLOG_TRACE, __VA_ARGS__)
179 #define WLog_DBG(tag, ...) WLog_Print_tag(tag, WLOG_DEBUG, __VA_ARGS__)
180 #define WLog_INFO(tag, ...) WLog_Print_tag(tag, WLOG_INFO, __VA_ARGS__)
181 #define WLog_WARN(tag, ...) WLog_Print_tag(tag, WLOG_WARN, __VA_ARGS__)
182 #define WLog_ERR(tag, ...) WLog_Print_tag(tag, WLOG_ERROR, __VA_ARGS__)
183 #define WLog_FATAL(tag, ...) WLog_Print_tag(tag, WLOG_FATAL, __VA_ARGS__)
185 WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
186 WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level);
187 WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter);
189 WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
190 WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
191 WINPR_API BOOL WLog_OpenAppender(wLog* log);
192 WINPR_API BOOL WLog_CloseAppender(wLog* log);
193 WINPR_API BOOL WLog_ConfigureAppender(wLogAppender* appender, const char* setting, void* value);
195 WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
196 WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
198 #if !defined(DEFINE_NO_DEPRECATED)
200 WINPR_API WINPR_DEPRECATED(BOOL WLog_Init(void));
202 WINPR_API WINPR_DEPRECATED(BOOL WLog_Uninit(void));
205 typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage* msg);
206 typedef BOOL (*wLogCallbackData_t)(const wLogMessage* msg);
207 typedef BOOL (*wLogCallbackImage_t)(const wLogMessage* msg);
208 typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage* msg);
210 struct _wLogCallbacks
212 wLogCallbackData_t data;
213 wLogCallbackImage_t image;
214 wLogCallbackMessage_t message;
215 wLogCallbackPackage_t package;
217 typedef struct _wLogCallbacks wLogCallbacks;
223 #endif /* WINPR_WLOG_H */