wlog.h (8546B)
1/** 2 * WinPR: Windows Portable Runtime 3 * WinPR Logger 4 * 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> 8 * 9 * 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 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 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. 21 */ 22 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#include <winpr/wtypes.h> 33#include <winpr/winpr.h> 34#include <winpr/synch.h> 35#include <winpr/thread.h> 36 37/** 38 * Log Levels 39 */ 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 49/** 50 * Log Message 51 */ 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 57/** 58 * Log Appenders 59 */ 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 struct _wLogMessage 69 { 70 DWORD Type; 71 72 DWORD Level; 73 74 LPSTR PrefixString; 75 76 LPCSTR FormatString; 77 LPSTR TextString; 78 79 DWORD LineNumber; /* __LINE__ */ 80 LPCSTR FileName; /* __FILE__ */ 81 LPCSTR FunctionName; /* __FUNCTION__ */ 82 83 /* Data Message */ 84 85 void* Data; 86 int Length; 87 88 /* Image Message */ 89 90 void* ImageData; 91 int ImageWidth; 92 int ImageHeight; 93 int ImageBpp; 94 95 /* Packet Message */ 96 97 void* PacketData; 98 int PacketLength; 99 DWORD PacketFlags; 100 }; 101 typedef struct _wLogMessage wLogMessage; 102 typedef struct _wLogLayout wLogLayout; 103 typedef struct _wLogAppender wLogAppender; 104 typedef struct _wLog wLog; 105 106#define WLOG_PACKET_INBOUND 1 107#define WLOG_PACKET_OUTBOUND 2 108 109 WINPR_API BOOL WLog_PrintMessage(wLog* log, DWORD type, DWORD level, DWORD line, 110 const char* file, const char* function, ...); 111 WINPR_API BOOL WLog_PrintMessageVA(wLog* log, DWORD type, DWORD level, DWORD line, 112 const char* file, const char* function, va_list args); 113 114 WINPR_API wLog* WLog_GetRoot(void); 115 WINPR_API wLog* WLog_Get(LPCSTR name); 116 WINPR_API DWORD WLog_GetLogLevel(wLog* log); 117 WINPR_API BOOL WLog_IsLevelActive(wLog* _log, DWORD _log_level); 118 119#define WLog_Print(_log, _log_level, ...) \ 120 do \ 121 { \ 122 if (WLog_IsLevelActive(_log, _log_level)) \ 123 { \ 124 WLog_PrintMessage(_log, WLOG_MESSAGE_TEXT, _log_level, __LINE__, __FILE__, \ 125 __FUNCTION__, __VA_ARGS__); \ 126 } \ 127 } while (0) 128 129#define WLog_Print_tag(_tag, _log_level, ...) \ 130 do \ 131 { \ 132 static wLog* _log_cached_ptr = NULL; \ 133 if (!_log_cached_ptr) \ 134 _log_cached_ptr = WLog_Get(_tag); \ 135 WLog_Print(_log_cached_ptr, _log_level, __VA_ARGS__); \ 136 } while (0) 137 138#define WLog_PrintVA(_log, _log_level, _args) \ 139 do \ 140 { \ 141 if (WLog_IsLevelActive(_log, _log_level)) \ 142 { \ 143 WLog_PrintMessageVA(_log, WLOG_MESSAGE_TEXT, _log_level, __LINE__, __FILE__, \ 144 __FUNCTION__, _args); \ 145 } \ 146 } while (0) 147 148#define WLog_Data(_log, _log_level, ...) \ 149 do \ 150 { \ 151 if (WLog_IsLevelActive(_log, _log_level)) \ 152 { \ 153 WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, \ 154 __FUNCTION__, __VA_ARGS__); \ 155 } \ 156 } while (0) 157 158#define WLog_Image(_log, _log_level, ...) \ 159 do \ 160 { \ 161 if (WLog_IsLevelActive(_log, _log_level)) \ 162 { \ 163 WLog_PrintMessage(_log, WLOG_MESSAGE_DATA, _log_level, __LINE__, __FILE__, \ 164 __FUNCTION__, __VA_ARGS__); \ 165 } \ 166 } while (0) 167 168#define WLog_Packet(_log, _log_level, ...) \ 169 do \ 170 { \ 171 if (WLog_IsLevelActive(_log, _log_level)) \ 172 { \ 173 WLog_PrintMessage(_log, WLOG_MESSAGE_PACKET, _log_level, __LINE__, __FILE__, \ 174 __FUNCTION__, __VA_ARGS__); \ 175 } \ 176 } while (0) 177 178#define WLog_LVL(tag, lvl, ...) WLog_Print_tag(tag, lvl, __VA_ARGS__) 179#define WLog_VRB(tag, ...) WLog_Print_tag(tag, WLOG_TRACE, __VA_ARGS__) 180#define WLog_DBG(tag, ...) WLog_Print_tag(tag, WLOG_DEBUG, __VA_ARGS__) 181#define WLog_INFO(tag, ...) WLog_Print_tag(tag, WLOG_INFO, __VA_ARGS__) 182#define WLog_WARN(tag, ...) WLog_Print_tag(tag, WLOG_WARN, __VA_ARGS__) 183#define WLog_ERR(tag, ...) WLog_Print_tag(tag, WLOG_ERROR, __VA_ARGS__) 184#define WLog_FATAL(tag, ...) WLog_Print_tag(tag, WLOG_FATAL, __VA_ARGS__) 185 186 WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel); 187 WINPR_API BOOL WLog_SetStringLogLevel(wLog* log, LPCSTR level); 188 WINPR_API BOOL WLog_AddStringLogFilters(LPCSTR filter); 189 190 WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType); 191 WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log); 192 WINPR_API BOOL WLog_OpenAppender(wLog* log); 193 WINPR_API BOOL WLog_CloseAppender(wLog* log); 194 WINPR_API BOOL WLog_ConfigureAppender(wLogAppender* appender, const char* setting, void* value); 195 196 WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log); 197 WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format); 198 199#if !defined(DEFINE_NO_DEPRECATED) 200 /** Deprecated */ 201 WINPR_API WINPR_DEPRECATED(BOOL WLog_Init(void)); 202 /** Deprecated */ 203 WINPR_API WINPR_DEPRECATED(BOOL WLog_Uninit(void)); 204#endif 205 206 typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage* msg); 207 typedef BOOL (*wLogCallbackData_t)(const wLogMessage* msg); 208 typedef BOOL (*wLogCallbackImage_t)(const wLogMessage* msg); 209 typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage* msg); 210 211 struct _wLogCallbacks 212 { 213 wLogCallbackData_t data; 214 wLogCallbackImage_t image; 215 wLogCallbackMessage_t message; 216 wLogCallbackPackage_t package; 217 }; 218 typedef struct _wLogCallbacks wLogCallbacks; 219 220#ifdef __cplusplus 221} 222#endif 223 224#endif /* WINPR_WLOG_H */