wlog: rework, cleanup and stabilize API
* only expose necessary functions and types in header * don't expose appender internals * add generic function WLog_ConfigureAppender to have the possibility to configure appender specific settings * detect appender availability if WLog_SetLogAppenderType or WLog_Appender_New return FALSE or NULL respectively the appender isn't available or the initialization failed. This is very useful for the use with optional appenders. * add Free to the appender interface. At the time of the Free the appender is known and available so it can be called directly (instead of calling the right function according to the type) * make all appender internal function static * all appenders return the generic wLogAppender type now. Typecasts are internally done where necessary this abstracts the appenders more cleanly
This commit is contained in:
parent
d73c4898c1
commit
07417599ce
@ -3,6 +3,9 @@
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
* Copyright 2015 Thincast Technologies GmbH
|
||||
* Copyright 2015 Bernhard Miklautz <bernhard.miklautz@thincast.com>
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -34,32 +37,36 @@ extern "C" {
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/winsock.h>
|
||||
|
||||
typedef struct _wLog wLog;
|
||||
typedef struct _wLogMessage wLogMessage;
|
||||
typedef struct _wLogLayout wLogLayout;
|
||||
typedef struct _wLogAppender wLogAppender;
|
||||
|
||||
/**
|
||||
* Log Levels
|
||||
*/
|
||||
|
||||
#define WLOG_TRACE 0
|
||||
#define WLOG_DEBUG 1
|
||||
#define WLOG_INFO 2
|
||||
#define WLOG_WARN 3
|
||||
#define WLOG_ERROR 4
|
||||
#define WLOG_FATAL 5
|
||||
#define WLOG_OFF 6
|
||||
#define WLOG_TRACE 0
|
||||
#define WLOG_DEBUG 1
|
||||
#define WLOG_INFO 2
|
||||
#define WLOG_WARN 3
|
||||
#define WLOG_ERROR 4
|
||||
#define WLOG_FATAL 5
|
||||
#define WLOG_OFF 6
|
||||
#define WLOG_LEVEL_INHERIT 0xFFFF
|
||||
|
||||
/**
|
||||
* Log Message
|
||||
*/
|
||||
#define WLOG_MESSAGE_TEXT 0
|
||||
#define WLOG_MESSAGE_DATA 1
|
||||
#define WLOG_MESSAGE_IMAGE 2
|
||||
#define WLOG_MESSAGE_PACKET 3
|
||||
|
||||
#define WLOG_MESSAGE_TEXT 0
|
||||
#define WLOG_MESSAGE_DATA 1
|
||||
#define WLOG_MESSAGE_IMAGE 2
|
||||
#define WLOG_MESSAGE_PACKET 3
|
||||
/**
|
||||
* Log Appenders
|
||||
*/
|
||||
#define WLOG_APPENDER_CONSOLE 0
|
||||
#define WLOG_APPENDER_FILE 1
|
||||
#define WLOG_APPENDER_BINARY 2
|
||||
#define WLOG_APPENDER_CALLBACK 3
|
||||
#define WLOG_APPENDER_SYSLOG 4
|
||||
#define WLOG_APPENDER_JOURNALD 5
|
||||
#define WLOG_APPENDER_UDP 6
|
||||
|
||||
struct _wLogMessage
|
||||
{
|
||||
@ -94,169 +101,13 @@ struct _wLogMessage
|
||||
int PacketLength;
|
||||
DWORD PacketFlags;
|
||||
};
|
||||
typedef struct _wLogMessage wLogMessage;
|
||||
typedef struct _wLogLayout wLogLayout;
|
||||
typedef struct _wLogAppender wLogAppender;
|
||||
typedef struct _wLog wLog;
|
||||
|
||||
/**
|
||||
* Log Layout
|
||||
*/
|
||||
|
||||
struct _wLogLayout
|
||||
{
|
||||
DWORD Type;
|
||||
|
||||
LPSTR FormatString;
|
||||
};
|
||||
|
||||
/**
|
||||
* Log Appenders
|
||||
*/
|
||||
|
||||
#define WLOG_APPENDER_CONSOLE 0
|
||||
#define WLOG_APPENDER_FILE 1
|
||||
#define WLOG_APPENDER_BINARY 2
|
||||
#define WLOG_APPENDER_CALLBACK 3
|
||||
#define WLOG_APPENDER_SYSLOG 4
|
||||
#define WLOG_APPENDER_JOURNALD 5
|
||||
#define WLOG_APPENDER_UDP 6
|
||||
|
||||
#define WLOG_PACKET_INBOUND 1
|
||||
#define WLOG_PACKET_OUTBOUND 2
|
||||
|
||||
typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
|
||||
#define WLOG_APPENDER_COMMON() \
|
||||
DWORD Type; \
|
||||
DWORD State; \
|
||||
wLogLayout* Layout; \
|
||||
CRITICAL_SECTION lock; \
|
||||
BOOL recursive; \
|
||||
void* TextMessageContext; \
|
||||
void* DataMessageContext; \
|
||||
void* ImageMessageContext; \
|
||||
void* PacketMessageContext; \
|
||||
WLOG_APPENDER_OPEN_FN Open; \
|
||||
WLOG_APPENDER_CLOSE_FN Close; \
|
||||
WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \
|
||||
WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \
|
||||
WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \
|
||||
WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage
|
||||
|
||||
struct _wLogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
|
||||
#define WLOG_CONSOLE_DEFAULT 0
|
||||
#define WLOG_CONSOLE_STDOUT 1
|
||||
#define WLOG_CONSOLE_STDERR 2
|
||||
#define WLOG_CONSOLE_DEBUG 4
|
||||
|
||||
struct _wLogConsoleAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
int outputStream;
|
||||
};
|
||||
typedef struct _wLogConsoleAppender wLogConsoleAppender;
|
||||
|
||||
struct _wLogFileAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogFileAppender wLogFileAppender;
|
||||
|
||||
struct _wLogBinaryAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
||||
|
||||
typedef BOOL (*CallbackAppenderMessage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*CallbackAppenderData_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*CallbackAppenderImage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*CallbackAppenderPackage_t)(const wLogMessage *msg);
|
||||
|
||||
struct _wLogCallbackAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
CallbackAppenderMessage_t message;
|
||||
CallbackAppenderData_t data;
|
||||
CallbackAppenderImage_t image;
|
||||
CallbackAppenderPackage_t package;
|
||||
};
|
||||
typedef struct _wLogCallbackAppender wLogCallbackAppender;
|
||||
|
||||
struct _wLogSyslogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
typedef struct _wLogSyslogAppender wLogSyslogAppender;
|
||||
|
||||
struct _wLogJournaldAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *identifier;
|
||||
FILE *stream;
|
||||
};
|
||||
typedef struct _wLogJournaldAppender wLogJournaldAppender;
|
||||
|
||||
struct _wLogUdpAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *host;
|
||||
struct sockaddr targetAddr;
|
||||
int targetAddrLen;
|
||||
SOCKET sock;
|
||||
};
|
||||
typedef struct _wLogUdpAppender wLogUdpAppender;
|
||||
|
||||
|
||||
/**
|
||||
* Filter
|
||||
*/
|
||||
|
||||
struct _wLogFilter
|
||||
{
|
||||
DWORD Level;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
};
|
||||
typedef struct _wLogFilter wLogFilter;
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
|
||||
struct _wLog
|
||||
{
|
||||
LPSTR Name;
|
||||
DWORD Level;
|
||||
|
||||
BOOL IsRoot;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
wLogAppender* Appender;
|
||||
|
||||
wLog* Parent;
|
||||
wLog** Children;
|
||||
DWORD ChildrenCount;
|
||||
DWORD ChildrenSize;
|
||||
};
|
||||
#define WLOG_PACKET_INBOUND 1
|
||||
#define WLOG_PACKET_OUTBOUND 2
|
||||
|
||||
WINPR_API BOOL WLog_PrintMessage(wLog* log, wLogMessage* message, ...);
|
||||
WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args);
|
||||
@ -345,20 +196,11 @@ WINPR_API BOOL WLog_PrintMessageVA(wLog* log, wLogMessage* message, va_list args
|
||||
WINPR_API DWORD WLog_GetLogLevel(wLog* log);
|
||||
WINPR_API BOOL WLog_SetLogLevel(wLog* log, DWORD logLevel);
|
||||
|
||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType);
|
||||
|
||||
WINPR_API wLogAppender* WLog_GetLogAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_OpenAppender(wLog* log);
|
||||
WINPR_API BOOL WLog_CloseAppender(wLog* log);
|
||||
|
||||
WINPR_API BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream);
|
||||
|
||||
WINPR_API BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
|
||||
WINPR_API BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
|
||||
|
||||
WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
|
||||
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
|
||||
CallbackAppenderData_t data);
|
||||
WINPR_API BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value);
|
||||
|
||||
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
|
||||
WINPR_API BOOL WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
|
||||
@ -369,6 +211,19 @@ WINPR_API wLog* WLog_Get(LPCSTR name);
|
||||
WINPR_API BOOL WLog_Init(void);
|
||||
WINPR_API BOOL WLog_Uninit(void);
|
||||
|
||||
typedef BOOL (*wLogCallbackMessage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackData_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackImage_t)(const wLogMessage *msg);
|
||||
typedef BOOL (*wLogCallbackPackage_t)(const wLogMessage *msg);
|
||||
|
||||
struct _wLogCallbacks {
|
||||
wLogCallbackData_t data;
|
||||
wLogCallbackImage_t image;
|
||||
wLogCallbackMessage_t message;
|
||||
wLogCallbackPackage_t package;
|
||||
};
|
||||
typedef struct _wLogCallbacks wLogCallbacks;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -1269,7 +1269,7 @@ SCardApiFunctionTable Inspect_SCardApiFunctionTable =
|
||||
void Inspect_InitLog()
|
||||
{
|
||||
wLogLayout* layout;
|
||||
wLogFileAppender* appender;
|
||||
wLogAppender* appender;
|
||||
const char* filepath = SMARTCARD_INSPECT_FILEPATH;
|
||||
|
||||
if (g_Log)
|
||||
@ -1284,10 +1284,12 @@ void Inspect_InitLog()
|
||||
|
||||
WLog_SetLogLevel(g_Log, WLOG_DEBUG);
|
||||
WLog_SetLogAppenderType(g_Log, WLOG_APPENDER_FILE);
|
||||
appender = (wLogFileAppender*) WLog_GetLogAppender(g_Log);
|
||||
appender = WLog_GetLogAppender(g_Log);
|
||||
if (!appender)
|
||||
return;
|
||||
|
||||
WLog_FileAppender_SetOutputFileName(g_Log, appender, "WinSCard.txt");
|
||||
WLog_FileAppender_SetOutputFilePath(g_Log, appender, filepath);
|
||||
WLog_ConfigureAppender(appender, "outputfilename", "WinSCard.txt");
|
||||
WLog_ConfigureAppender(appender, "outputfilepath", (void *)filepath);
|
||||
|
||||
layout = WLog_GetLogLayout(g_Log);
|
||||
WLog_Layout_SetPrefixFormat(g_Log, layout, "[%mn] ");
|
||||
|
@ -77,7 +77,6 @@ set(${MODULE_PREFIX}_WLOG_SRCS
|
||||
wlog/Message.c
|
||||
wlog/Message.h
|
||||
wlog/TextMessage.c
|
||||
wlog/TextMessage.h
|
||||
wlog/DataMessage.c
|
||||
wlog/DataMessage.h
|
||||
wlog/ImageMessage.c
|
||||
|
@ -19,7 +19,10 @@ int TestWLog(int argc, char* argv[])
|
||||
WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY);
|
||||
|
||||
appender = WLog_GetLogAppender(root);
|
||||
WLog_ConsoleAppender_SetOutputStream(root, (wLogConsoleAppender*) appender, WLOG_CONSOLE_STDERR);
|
||||
if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log"))
|
||||
return 1;
|
||||
if(!WLog_ConfigureAppender(appender, "outputfilepath", "/tmp/"))
|
||||
return 1;
|
||||
|
||||
layout = WLog_GetLogLayout(root);
|
||||
WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - ");
|
||||
|
@ -90,6 +90,7 @@ int TestWLogCallback(int argc, char* argv[])
|
||||
wLog* logB;
|
||||
wLogLayout* layout;
|
||||
wLogAppender* appender;
|
||||
wLogCallbacks callbacks;
|
||||
|
||||
function = __FUNCTION__;
|
||||
WLog_Init();
|
||||
@ -100,9 +101,13 @@ int TestWLogCallback(int argc, char* argv[])
|
||||
|
||||
appender = WLog_GetLogAppender(root);
|
||||
|
||||
WLog_CallbackAppender_SetCallbacks(root, (wLogCallbackAppender*) appender,
|
||||
CallbackAppenderMessage, CallbackAppenderImage, CallbackAppenderPackage,
|
||||
CallbackAppenderData);
|
||||
callbacks.data = CallbackAppenderData;
|
||||
callbacks.image = CallbackAppenderImage;
|
||||
callbacks.message = CallbackAppenderMessage;
|
||||
callbacks.package = CallbackAppenderPackage;
|
||||
|
||||
if (!WLog_ConfigureAppender(appender, "callbacks", (void *)&callbacks))
|
||||
return -1;
|
||||
|
||||
layout = WLog_GetLogLayout(root);
|
||||
WLog_Layout_SetPrefixFormat(root, layout, "%mn");
|
||||
|
@ -21,68 +21,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Layout.h"
|
||||
|
||||
#include "wlog/Appender.h"
|
||||
|
||||
wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
wLogAppender* appender;
|
||||
|
||||
if (!log)
|
||||
return NULL;
|
||||
|
||||
switch (logAppenderType)
|
||||
{
|
||||
case WLOG_APPENDER_CONSOLE:
|
||||
appender = (wLogAppender*) WLog_ConsoleAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_FILE:
|
||||
appender = (wLogAppender*) WLog_FileAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_BINARY:
|
||||
appender = (wLogAppender*) WLog_BinaryAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_CALLBACK:
|
||||
appender = (wLogAppender*) WLog_CallbackAppender_New(log);
|
||||
break;
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
case WLOG_APPENDER_SYSLOG:
|
||||
appender = (wLogAppender*) WLog_SyslogAppender_New(log);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
case WLOG_APPENDER_JOURNALD:
|
||||
appender = (wLogAppender*) WLog_JournaldAppender_New(log);
|
||||
break;
|
||||
#endif
|
||||
case WLOG_APPENDER_UDP:
|
||||
appender = (wLogAppender*) WLog_UdpAppender_New(log);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType);
|
||||
appender = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!appender)
|
||||
appender = (wLogAppender*) WLog_ConsoleAppender_New(log);
|
||||
|
||||
if (!appender)
|
||||
return NULL;
|
||||
|
||||
if (!(appender->Layout = WLog_Layout_New(log)))
|
||||
{
|
||||
WLog_Appender_Free(log, appender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InitializeCriticalSectionAndSpinCount(&appender->lock, 4000);
|
||||
|
||||
return appender;
|
||||
}
|
||||
#include "Appender.h"
|
||||
|
||||
void WLog_Appender_Free(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
@ -96,38 +35,7 @@ void WLog_Appender_Free(wLog* log, wLogAppender* appender)
|
||||
}
|
||||
|
||||
DeleteCriticalSection(&appender->lock);
|
||||
|
||||
switch (appender->Type)
|
||||
{
|
||||
case WLOG_APPENDER_CONSOLE:
|
||||
WLog_ConsoleAppender_Free(log, (wLogConsoleAppender*) appender);
|
||||
break;
|
||||
case WLOG_APPENDER_FILE:
|
||||
WLog_FileAppender_Free(log, (wLogFileAppender*) appender);
|
||||
break;
|
||||
case WLOG_APPENDER_BINARY:
|
||||
WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender);
|
||||
break;
|
||||
case WLOG_APPENDER_CALLBACK:
|
||||
WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender);
|
||||
break;
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
case WLOG_APPENDER_SYSLOG:
|
||||
WLog_SyslogAppender_Free(log, (wLogSyslogAppender *) appender);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
case WLOG_APPENDER_JOURNALD:
|
||||
WLog_JournaldAppender_Free(log, (wLogJournaldAppender *) appender);
|
||||
break;
|
||||
#endif
|
||||
case WLOG_APPENDER_UDP:
|
||||
WLog_UdpAppender_Free(log, (wLogUdpAppender *) appender);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: don't know how to free appender type %d\n", __FUNCTION__, appender->Type);
|
||||
break;
|
||||
}
|
||||
appender->Free(appender);
|
||||
}
|
||||
|
||||
wLogAppender* WLog_GetLogAppender(wLog* log)
|
||||
@ -141,18 +49,6 @@ wLogAppender* WLog_GetLogAppender(wLog* log)
|
||||
return log->Appender;
|
||||
}
|
||||
|
||||
BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
if (log->Appender)
|
||||
{
|
||||
WLog_Appender_Free(log, log->Appender);
|
||||
log->Appender = NULL;
|
||||
}
|
||||
|
||||
log->Appender = WLog_Appender_New(log, logAppenderType);
|
||||
return log->Appender != NULL;
|
||||
}
|
||||
|
||||
BOOL WLog_OpenAppender(wLog* log)
|
||||
{
|
||||
int status = 0;
|
||||
@ -196,3 +92,87 @@ BOOL WLog_CloseAppender(wLog* log)
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
wLogAppender* appender;
|
||||
|
||||
if (!log)
|
||||
return NULL;
|
||||
|
||||
switch (logAppenderType)
|
||||
{
|
||||
case WLOG_APPENDER_CONSOLE:
|
||||
appender = WLog_ConsoleAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_FILE:
|
||||
appender = WLog_FileAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_BINARY:
|
||||
appender = WLog_BinaryAppender_New(log);
|
||||
break;
|
||||
case WLOG_APPENDER_CALLBACK:
|
||||
appender = WLog_CallbackAppender_New(log);
|
||||
break;
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
case WLOG_APPENDER_SYSLOG:
|
||||
appender = WLog_SyslogAppender_New(log);
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
case WLOG_APPENDER_JOURNALD:
|
||||
appender = WLog_JournaldAppender_New(log);
|
||||
break;
|
||||
#endif
|
||||
case WLOG_APPENDER_UDP:
|
||||
appender = (wLogAppender*) WLog_UdpAppender_New(log);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "%s: unknown handler type %d\n", __FUNCTION__, logAppenderType);
|
||||
appender = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!appender)
|
||||
appender = (wLogAppender*) WLog_ConsoleAppender_New(log);
|
||||
|
||||
if (!appender)
|
||||
return NULL;
|
||||
|
||||
if (!(appender->Layout = WLog_Layout_New(log)))
|
||||
{
|
||||
WLog_Appender_Free(log, appender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
InitializeCriticalSectionAndSpinCount(&appender->lock, 4000);
|
||||
|
||||
return appender;
|
||||
}
|
||||
|
||||
BOOL WLog_SetLogAppenderType(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
if (!log)
|
||||
return FALSE;
|
||||
|
||||
if (log->Appender)
|
||||
{
|
||||
WLog_Appender_Free(log, log->Appender);
|
||||
log->Appender = NULL;
|
||||
}
|
||||
|
||||
log->Appender = WLog_Appender_New(log, logAppenderType);
|
||||
return log->Appender != NULL;
|
||||
}
|
||||
|
||||
BOOL WLog_ConfigureAppender(wLogAppender *appender, const char *setting, void *value)
|
||||
{
|
||||
if (!appender || !setting || !strlen(setting))
|
||||
return FALSE;
|
||||
|
||||
if (appender->Set)
|
||||
return appender->Set(appender, setting, value);
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
@ -20,25 +20,21 @@
|
||||
#ifndef WINPR_WLOG_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/FileAppender.h"
|
||||
#include "wlog/BinaryAppender.h"
|
||||
#include "wlog/ConsoleAppender.h"
|
||||
#include "wlog/CallbackAppender.h"
|
||||
#include "wlog/UdpAppender.h"
|
||||
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include "wlog/SyslogAppender.h"
|
||||
#endif
|
||||
#include "wlog.h"
|
||||
|
||||
#include "FileAppender.h"
|
||||
#include "ConsoleAppender.h"
|
||||
#include "BinaryAppender.h"
|
||||
#include "CallbackAppender.h"
|
||||
#ifdef HAVE_JOURNALD_H
|
||||
#include "wlog/JournaldAppender.h"
|
||||
#include "JournaldAppender.h"
|
||||
#endif
|
||||
#ifdef HAVE_SYSLOG_H
|
||||
#include "SyslogAppender.h"
|
||||
#endif
|
||||
#include "UdpAppender.h"
|
||||
|
||||
void WLog_Appender_Free(wLog* log, wLogAppender* appender);
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
#endif /* WINPR_WLOG_APPENDER_PRIVATE_H */
|
||||
|
||||
|
@ -23,107 +23,87 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "BinaryAppender.h"
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/thread.h>
|
||||
#include <winpr/stream.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/BinaryAppender.h"
|
||||
|
||||
/**
|
||||
* Binary Appender
|
||||
*/
|
||||
|
||||
BOOL WLog_BinaryAppender_SetOutputFileName(wLog* log, wLogBinaryAppender* appender, const char* filename)
|
||||
struct _wLogBinaryAppender
|
||||
{
|
||||
if (!appender || !filename)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_BINARY)
|
||||
return FALSE;
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
||||
|
||||
appender->FileName = _strdup(filename);
|
||||
if (!appender->FileName)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_SetOutputFilePath(wLog* log, wLogBinaryAppender* appender, const char* filepath)
|
||||
{
|
||||
if (!appender || !filepath)
|
||||
return FALSE;
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_BINARY)
|
||||
return FALSE;
|
||||
|
||||
appender->FilePath = _strdup(filepath);
|
||||
if (!appender->FilePath)
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_Open(wLog* log, wLogBinaryAppender* appender)
|
||||
static BOOL WLog_BinaryAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogBinaryAppender* binaryAppender;
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->FileName)
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
if (!binaryAppender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!appender->FileName)
|
||||
binaryAppender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!binaryAppender->FileName)
|
||||
return FALSE;
|
||||
sprintf_s(appender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId());
|
||||
sprintf_s(binaryAppender->FileName, MAX_PATH, "%u.wlog", (unsigned int) GetCurrentProcessId());
|
||||
}
|
||||
|
||||
if (!appender->FilePath)
|
||||
if (!binaryAppender->FilePath)
|
||||
{
|
||||
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!appender->FilePath)
|
||||
binaryAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!binaryAppender->FilePath)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
if (!binaryAppender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
if (!appender->FullFileName)
|
||||
binaryAppender->FullFileName = GetCombinedPath(binaryAppender->FilePath, binaryAppender->FileName);
|
||||
if (!binaryAppender->FullFileName)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
if (!PathFileExistsA(binaryAppender->FilePath))
|
||||
{
|
||||
if (!PathMakePathA(appender->FilePath, 0))
|
||||
if (!PathMakePathA(binaryAppender->FilePath, 0))
|
||||
return FALSE;
|
||||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
UnixChangeFileMode(binaryAppender->FilePath, 0xFFFF);
|
||||
}
|
||||
|
||||
appender->FileDescriptor = fopen(appender->FullFileName, "a+");
|
||||
binaryAppender->FileDescriptor = fopen(binaryAppender->FullFileName, "a+");
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
if (!binaryAppender->FileDescriptor)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_Close(wLog* log, wLogBinaryAppender* appender)
|
||||
static BOOL WLog_BinaryAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!appender->FileDescriptor)
|
||||
wLogBinaryAppender* binaryAppender;
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
if (!binaryAppender->FileDescriptor)
|
||||
return TRUE;
|
||||
|
||||
fclose(appender->FileDescriptor);
|
||||
fclose(binaryAppender->FileDescriptor);
|
||||
|
||||
appender->FileDescriptor = NULL;
|
||||
binaryAppender->FileDescriptor = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
FILE* fp;
|
||||
wStream* s;
|
||||
@ -132,11 +112,14 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w
|
||||
int FunctionNameLength;
|
||||
int TextStringLength;
|
||||
BOOL ret = TRUE;
|
||||
wLogBinaryAppender* binaryAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
fp = appender->FileDescriptor;
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
|
||||
fp = binaryAppender->FileDescriptor;
|
||||
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
@ -180,17 +163,55 @@ BOOL WLog_BinaryAppender_WriteMessage(wLog* log, wLogBinaryAppender* appender, w
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_BinaryAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogBinaryAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_BinaryAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log)
|
||||
static BOOL WLog_BinaryAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogBinaryAppender *binaryAppender = (wLogBinaryAppender *) appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp("outputfilename", setting))
|
||||
{
|
||||
binaryAppender->FileName = _strdup((const char *)value);
|
||||
if (!binaryAppender->FileName)
|
||||
return FALSE;
|
||||
}
|
||||
else if (!strcmp("outputfilepath", setting))
|
||||
{
|
||||
binaryAppender->FilePath = _strdup((const char *)value);
|
||||
if (!binaryAppender->FilePath)
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void WLog_BinaryAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogBinaryAppender *binaryAppender;
|
||||
if (appender)
|
||||
{
|
||||
binaryAppender = (wLogBinaryAppender *)appender;
|
||||
free(binaryAppender->FileName);
|
||||
free(binaryAppender->FilePath);
|
||||
free(binaryAppender->FullFileName);
|
||||
free(binaryAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_BinaryAppender_New(wLog* log)
|
||||
{
|
||||
wLogBinaryAppender* BinaryAppender;
|
||||
|
||||
@ -199,25 +220,13 @@ wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log)
|
||||
return NULL;
|
||||
|
||||
BinaryAppender->Type = WLOG_APPENDER_BINARY;
|
||||
BinaryAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Open;
|
||||
BinaryAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_BinaryAppender_Close;
|
||||
BinaryAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_BinaryAppender_WriteMessage;
|
||||
BinaryAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_BinaryAppender_WriteDataMessage;
|
||||
BinaryAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_BinaryAppender_WriteImageMessage;
|
||||
BinaryAppender->Open = WLog_BinaryAppender_Open;
|
||||
BinaryAppender->Close = WLog_BinaryAppender_Close;
|
||||
BinaryAppender->WriteMessage = WLog_BinaryAppender_WriteMessage;
|
||||
BinaryAppender->WriteDataMessage = WLog_BinaryAppender_WriteDataMessage;
|
||||
BinaryAppender->WriteImageMessage = WLog_BinaryAppender_WriteImageMessage;
|
||||
BinaryAppender->Free = WLog_BinaryAppender_Free;
|
||||
BinaryAppender->Set = WLog_BinaryAppender_Set;
|
||||
|
||||
return BinaryAppender;
|
||||
}
|
||||
|
||||
void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
free(appender->FileName);
|
||||
free(appender->FilePath);
|
||||
free(appender->FullFileName);
|
||||
free(appender);
|
||||
}
|
||||
return (wLogAppender *)BinaryAppender;
|
||||
}
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_BINARY_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_BINARY_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogBinaryAppender* WLog_BinaryAppender_New(wLog* log);
|
||||
WINPR_API void WLog_BinaryAppender_Free(wLog* log, wLogBinaryAppender* appender);
|
||||
WINPR_API wLogAppender* WLog_BinaryAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_BINARY_APPENDER_PRIVATE_H */
|
||||
|
@ -21,100 +21,114 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
#include "CallbackAppender.h"
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/CallbackAppender.h"
|
||||
|
||||
/**
|
||||
* Callback Appender
|
||||
*/
|
||||
|
||||
WINPR_API BOOL WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
|
||||
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
|
||||
CallbackAppenderData_t data)
|
||||
struct _wLogCallbackAppender
|
||||
{
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_CALLBACK)
|
||||
return FALSE;
|
||||
wLogCallbacks *callbacks;
|
||||
};
|
||||
typedef struct _wLogCallbackAppender wLogCallbackAppender;
|
||||
|
||||
appender->message = msg;
|
||||
appender->image = img;
|
||||
appender->package = pkg;
|
||||
appender->data = data;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender)
|
||||
static BOOL WLog_CallbackAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender)
|
||||
static BOOL WLog_CallbackAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
if (appender->message)
|
||||
{
|
||||
return appender->message(message);
|
||||
}
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->message)
|
||||
return callbackAppender->callbacks->message(message);
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->data)
|
||||
{
|
||||
return appender->data(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->data)
|
||||
return callbackAppender->callbacks->data(message);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->image)
|
||||
{
|
||||
return appender->image(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->image)
|
||||
return callbackAppender->callbacks->image(message);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->package)
|
||||
{
|
||||
return appender->package(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
wLogCallbackAppender* callbackAppender;
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
if (callbackAppender->callbacks && callbackAppender->callbacks->package)
|
||||
return callbackAppender->callbacks->package(message);
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
static BOOL WLog_CallbackAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogCallbackAppender *callbackAppender = (wLogCallbackAppender *)appender;
|
||||
|
||||
if (!value || strcmp(setting, "callbacks"))
|
||||
return FALSE;
|
||||
|
||||
if (!(callbackAppender->callbacks = calloc(1, sizeof(wLogCallbacks)))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
callbackAppender->callbacks = memcpy(callbackAppender->callbacks, value, sizeof(wLogCallbacks));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void WLog_CallbackAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogCallbackAppender *callbackAppender;
|
||||
if (!appender) {
|
||||
return;
|
||||
}
|
||||
|
||||
callbackAppender = (wLogCallbackAppender *)appender;
|
||||
|
||||
free(callbackAppender->callbacks);
|
||||
free(appender);
|
||||
}
|
||||
|
||||
wLogAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
{
|
||||
wLogCallbackAppender* CallbackAppender;
|
||||
|
||||
@ -124,21 +138,14 @@ wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
|
||||
CallbackAppender->Type = WLOG_APPENDER_CALLBACK;
|
||||
|
||||
CallbackAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Open;
|
||||
CallbackAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_CallbackAppender_Close;
|
||||
CallbackAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_CallbackAppender_WriteMessage;
|
||||
CallbackAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_CallbackAppender_WriteDataMessage;
|
||||
CallbackAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_CallbackAppender_WriteImageMessage;
|
||||
CallbackAppender->WritePacketMessage =
|
||||
(WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_CallbackAppender_WritePacketMessage;
|
||||
CallbackAppender->Open = WLog_CallbackAppender_Open;
|
||||
CallbackAppender->Close = WLog_CallbackAppender_Close;
|
||||
CallbackAppender->WriteMessage = WLog_CallbackAppender_WriteMessage;
|
||||
CallbackAppender->WriteDataMessage = WLog_CallbackAppender_WriteDataMessage;
|
||||
CallbackAppender->WriteImageMessage = WLog_CallbackAppender_WriteImageMessage;
|
||||
CallbackAppender->WritePacketMessage = WLog_CallbackAppender_WritePacketMessage;
|
||||
CallbackAppender->Free = WLog_CallbackAppender_Free;
|
||||
CallbackAppender->Set = WLog_CallbackAppender_Set;
|
||||
|
||||
return CallbackAppender;
|
||||
}
|
||||
|
||||
void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender)
|
||||
{
|
||||
free(appender);
|
||||
return (wLogAppender *)CallbackAppender;
|
||||
}
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log);
|
||||
WINPR_API void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender);
|
||||
wLogAppender* WLog_CallbackAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H */
|
||||
|
@ -21,57 +21,45 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/ConsoleAppender.h"
|
||||
#include "ConsoleAppender.h"
|
||||
#include "Message.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Console Appender
|
||||
*/
|
||||
#define WLOG_CONSOLE_DEFAULT 0
|
||||
#define WLOG_CONSOLE_STDOUT 1
|
||||
#define WLOG_CONSOLE_STDERR 2
|
||||
#define WLOG_CONSOLE_DEBUG 4
|
||||
|
||||
BOOL WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppender* appender, int outputStream)
|
||||
struct _wLogConsoleAppender
|
||||
{
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_CONSOLE)
|
||||
return FALSE;
|
||||
int outputStream;
|
||||
};
|
||||
typedef struct _wLogConsoleAppender wLogConsoleAppender;
|
||||
|
||||
if (outputStream < 0)
|
||||
outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
|
||||
if (outputStream == WLOG_CONSOLE_STDOUT)
|
||||
appender->outputStream = WLOG_CONSOLE_STDOUT;
|
||||
else if (outputStream == WLOG_CONSOLE_STDERR)
|
||||
appender->outputStream = WLOG_CONSOLE_STDERR;
|
||||
else
|
||||
appender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_ConsoleAppender_Open(wLog* log, wLogConsoleAppender* appender)
|
||||
static BOOL WLog_ConsoleAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_ConsoleAppender_Close(wLog* log, wLogConsoleAppender* appender)
|
||||
static BOOL WLog_ConsoleAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
FILE* fp;
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender;
|
||||
|
||||
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
@ -124,7 +112,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
|
||||
__android_log_print(level, log->Name, "%s%s", message->PrefixString, message->TextString);
|
||||
|
||||
#else
|
||||
switch(appender->outputStream)
|
||||
switch(consoleAppender->outputStream)
|
||||
{
|
||||
case WLOG_CONSOLE_STDOUT:
|
||||
fp = stdout;
|
||||
@ -155,7 +143,7 @@ BOOL WLog_ConsoleAppender_WriteMessage(wLog* log, wLogConsoleAppender* appender,
|
||||
|
||||
static int g_DataId = 0;
|
||||
|
||||
BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int DataId;
|
||||
char* FullFileName;
|
||||
@ -172,7 +160,7 @@ BOOL WLog_ConsoleAppender_WriteDataMessage(wLog* log, wLogConsoleAppender* appen
|
||||
|
||||
static int g_ImageId = 0;
|
||||
|
||||
BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int ImageId;
|
||||
char* FullFileName;
|
||||
@ -190,7 +178,7 @@ BOOL WLog_ConsoleAppender_WriteImageMessage(wLog* log, wLogConsoleAppender* appe
|
||||
|
||||
static int g_PacketId = 0;
|
||||
|
||||
BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int PacketId;
|
||||
char* FullFileName;
|
||||
@ -210,41 +198,31 @@ BOOL WLog_ConsoleAppender_WritePacketMessage(wLog* log, wLogConsoleAppender* app
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log)
|
||||
static BOOL WLog_ConsoleAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogConsoleAppender* ConsoleAppender;
|
||||
wLogConsoleAppender *consoleAppender = (wLogConsoleAppender *)appender;
|
||||
|
||||
ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender));
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (!ConsoleAppender)
|
||||
return NULL;
|
||||
if (strcmp("outputstream", setting))
|
||||
return FALSE;
|
||||
|
||||
ConsoleAppender->Type = WLOG_APPENDER_CONSOLE;
|
||||
if (!strcmp("stdout", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_STDOUT;
|
||||
else if (!strcmp("stderr", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_STDERR;
|
||||
else if (!strcmp("default", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
else if (!strcmp("debug", value))
|
||||
consoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
ConsoleAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Open;
|
||||
ConsoleAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_ConsoleAppender_Close;
|
||||
|
||||
ConsoleAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_ConsoleAppender_WriteMessage;
|
||||
ConsoleAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_ConsoleAppender_WriteDataMessage;
|
||||
ConsoleAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_ConsoleAppender_WriteImageMessage;
|
||||
ConsoleAppender->WritePacketMessage =
|
||||
(WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN) WLog_ConsoleAppender_WritePacketMessage;
|
||||
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsDebuggerPresent())
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
|
||||
#endif
|
||||
|
||||
return ConsoleAppender;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender)
|
||||
static void WLog_ConsoleAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
@ -256,3 +234,34 @@ void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender)
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_ConsoleAppender_New(wLog* log)
|
||||
{
|
||||
wLogConsoleAppender* ConsoleAppender;
|
||||
|
||||
ConsoleAppender = (wLogConsoleAppender*) calloc(1, sizeof(wLogConsoleAppender));
|
||||
|
||||
if (!ConsoleAppender)
|
||||
return NULL;
|
||||
|
||||
ConsoleAppender->Type = WLOG_APPENDER_CONSOLE;
|
||||
|
||||
ConsoleAppender->Open = WLog_ConsoleAppender_Open;
|
||||
ConsoleAppender->Close = WLog_ConsoleAppender_Close;
|
||||
ConsoleAppender->WriteMessage = WLog_ConsoleAppender_WriteMessage;
|
||||
ConsoleAppender->WriteDataMessage = WLog_ConsoleAppender_WriteDataMessage;
|
||||
ConsoleAppender->WriteImageMessage = WLog_ConsoleAppender_WriteImageMessage;
|
||||
ConsoleAppender->WritePacketMessage = WLog_ConsoleAppender_WritePacketMessage;
|
||||
ConsoleAppender->Set = WLog_ConsoleAppender_Set;
|
||||
ConsoleAppender->Free = WLog_ConsoleAppender_Free;
|
||||
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEFAULT;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (IsDebuggerPresent())
|
||||
ConsoleAppender->outputStream = WLOG_CONSOLE_DEBUG;
|
||||
#endif
|
||||
|
||||
return (wLogAppender *)ConsoleAppender;
|
||||
}
|
||||
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogConsoleAppender* WLog_ConsoleAppender_New(wLog* log);
|
||||
WINPR_API void WLog_ConsoleAppender_Free(wLog* log, wLogConsoleAppender* appender);
|
||||
wLogAppender* WLog_ConsoleAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_CONSOLE_APPENDER_PRIVATE_H */
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/DataMessage.h"
|
||||
|
||||
|
@ -20,10 +20,6 @@
|
||||
#ifndef WINPR_WLOG_DATA_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_DATA_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
BOOL WLog_DataMessage_Write(char* filename, void* data, int length);
|
||||
|
||||
#endif /* WINPR_WLOG_DATA_MESSAGE_PRIVATE_H */
|
||||
|
@ -21,30 +21,28 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "FileAppender.h"
|
||||
#include "Message.h"
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/FileAppender.h"
|
||||
|
||||
/**
|
||||
* File Appender
|
||||
*/
|
||||
|
||||
BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename)
|
||||
struct _wLogFileAppender
|
||||
{
|
||||
if (!appender || !filename)
|
||||
return FALSE;
|
||||
WLOG_APPENDER_COMMON();
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_FILE)
|
||||
return FALSE;
|
||||
char* FileName;
|
||||
char* FilePath;
|
||||
char* FullFileName;
|
||||
FILE* FileDescriptor;
|
||||
};
|
||||
typedef struct _wLogFileAppender wLogFileAppender;
|
||||
|
||||
|
||||
static BOOL WLog_FileAppender_SetOutputFileName(wLogFileAppender* appender, const char* filename)
|
||||
{
|
||||
appender->FileName = _strdup(filename);
|
||||
if (!appender->FileName)
|
||||
return FALSE;
|
||||
@ -52,14 +50,8 @@ BOOL WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath)
|
||||
static BOOL WLog_FileAppender_SetOutputFilePath(wLogFileAppender* appender, const char* filepath)
|
||||
{
|
||||
if (!appender || !filepath)
|
||||
return FALSE;
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_FILE)
|
||||
return FALSE;
|
||||
|
||||
appender->FilePath = _strdup(filepath);
|
||||
if (!appender->FilePath)
|
||||
return FALSE;
|
||||
@ -67,73 +59,83 @@ BOOL WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_Open(wLog* log, wLogFileAppender* appender)
|
||||
static BOOL WLog_FileAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogFileAppender *fileAppender;
|
||||
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->FilePath)
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
|
||||
if (!fileAppender->FilePath)
|
||||
{
|
||||
appender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!appender->FilePath)
|
||||
fileAppender->FilePath = GetKnownSubPath(KNOWN_PATH_TEMP, "wlog");
|
||||
if (!fileAppender->FilePath)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!appender->FileName)
|
||||
if (!fileAppender->FileName)
|
||||
{
|
||||
appender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!appender->FileName)
|
||||
fileAppender->FileName = (char*) malloc(MAX_PATH);
|
||||
if (!fileAppender->FileName)
|
||||
return FALSE;
|
||||
|
||||
sprintf_s(appender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId());
|
||||
sprintf_s(fileAppender->FileName, MAX_PATH, "%u.log", (unsigned int) GetCurrentProcessId());
|
||||
}
|
||||
|
||||
if (!appender->FullFileName)
|
||||
if (!fileAppender->FullFileName)
|
||||
{
|
||||
appender->FullFileName = GetCombinedPath(appender->FilePath, appender->FileName);
|
||||
if (!appender->FullFileName)
|
||||
fileAppender->FullFileName = GetCombinedPath(fileAppender->FilePath, fileAppender->FileName);
|
||||
if (!fileAppender->FullFileName)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!PathFileExistsA(appender->FilePath))
|
||||
if (!PathFileExistsA(fileAppender->FilePath))
|
||||
{
|
||||
if (!PathMakePathA(appender->FilePath, 0))
|
||||
if (!PathMakePathA(fileAppender->FilePath, 0))
|
||||
return FALSE;
|
||||
UnixChangeFileMode(appender->FilePath, 0xFFFF);
|
||||
UnixChangeFileMode(fileAppender->FilePath, 0xFFFF);
|
||||
}
|
||||
|
||||
appender->FileDescriptor = fopen(appender->FullFileName, "a+");
|
||||
fileAppender->FileDescriptor = fopen(fileAppender->FullFileName, "a+");
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
if (!fileAppender->FileDescriptor)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_Close(wLog* log, wLogFileAppender* appender)
|
||||
static BOOL WLog_FileAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogFileAppender *fileAppender;
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (!appender->FileDescriptor)
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
|
||||
if (!fileAppender->FileDescriptor)
|
||||
return TRUE;
|
||||
|
||||
fclose(appender->FileDescriptor);
|
||||
fclose(fileAppender->FileDescriptor);
|
||||
|
||||
appender->FileDescriptor = NULL;
|
||||
fileAppender->FileDescriptor = NULL;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
FILE* fp;
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogFileAppender *fileAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
fp = appender->FileDescriptor;
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
|
||||
fp = fileAppender->FileDescriptor;
|
||||
|
||||
if (!fp)
|
||||
return FALSE;
|
||||
@ -150,7 +152,7 @@ BOOL WLog_FileAppender_WriteMessage(wLog* log, wLogFileAppender* appender, wLogM
|
||||
|
||||
static int g_DataId = 0;
|
||||
|
||||
BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int DataId;
|
||||
char* FullFileName;
|
||||
@ -170,7 +172,7 @@ BOOL WLog_FileAppender_WriteDataMessage(wLog* log, wLogFileAppender* appender, w
|
||||
|
||||
static int g_ImageId = 0;
|
||||
|
||||
int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, wLogMessage* message)
|
||||
static int WLog_FileAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int ImageId;
|
||||
char* FullFileName;
|
||||
@ -189,7 +191,38 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
static BOOL WLog_FileAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogFileAppender *fileAppender = (wLogFileAppender *) appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (!strcmp("outputfilename", setting))
|
||||
return WLog_FileAppender_SetOutputFileName(fileAppender, (const char *)value);
|
||||
else if (!strcmp("outputfilepath", setting))
|
||||
return WLog_FileAppender_SetOutputFilePath(fileAppender, (const char *)value);
|
||||
else
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void WLog_FileAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogFileAppender* fileAppender = NULL;
|
||||
|
||||
if (appender)
|
||||
{
|
||||
fileAppender = (wLogFileAppender *)appender;
|
||||
free(fileAppender->FileName);
|
||||
free(fileAppender->FilePath);
|
||||
free(fileAppender->FullFileName);
|
||||
free(fileAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_FileAppender_New(wLog* log)
|
||||
{
|
||||
LPSTR env;
|
||||
LPCSTR name;
|
||||
@ -203,14 +236,13 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
|
||||
FileAppender->Type = WLOG_APPENDER_FILE;
|
||||
|
||||
FileAppender->Open = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Open;
|
||||
FileAppender->Close = (WLOG_APPENDER_OPEN_FN) WLog_FileAppender_Close;
|
||||
FileAppender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_FileAppender_WriteMessage;
|
||||
FileAppender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_FileAppender_WriteDataMessage;
|
||||
FileAppender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_FileAppender_WriteImageMessage;
|
||||
FileAppender->Open = WLog_FileAppender_Open;
|
||||
FileAppender->Close = WLog_FileAppender_Close;
|
||||
FileAppender->WriteMessage = WLog_FileAppender_WriteMessage;
|
||||
FileAppender->WriteDataMessage = WLog_FileAppender_WriteDataMessage;
|
||||
FileAppender->WriteImageMessage = WLog_FileAppender_WriteImageMessage;
|
||||
FileAppender->Free = WLog_FileAppender_Free;
|
||||
FileAppender->Set = WLog_FileAppender_Set;
|
||||
|
||||
name = "WLOG_FILEAPPENDER_OUTPUT_FILE_PATH";
|
||||
nSize = GetEnvironmentVariableA(name, NULL, 0);
|
||||
@ -221,7 +253,7 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
goto error_free;
|
||||
|
||||
nSize = GetEnvironmentVariableA(name, env, nSize);
|
||||
status = WLog_FileAppender_SetOutputFilePath(log, FileAppender, env);
|
||||
status = WLog_FileAppender_SetOutputFilePath(FileAppender, env);
|
||||
free(env);
|
||||
|
||||
if (!status)
|
||||
@ -236,15 +268,15 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log)
|
||||
if (!env)
|
||||
goto error_output_file_name;
|
||||
|
||||
nSize = GetEnvironmentVariableA(name, env, nSize);
|
||||
status = WLog_FileAppender_SetOutputFileName(log, FileAppender, env);
|
||||
GetEnvironmentVariableA(name, env, nSize);
|
||||
status = WLog_FileAppender_SetOutputFileName(FileAppender, env);
|
||||
free(env);
|
||||
|
||||
if (!status)
|
||||
goto error_output_file_name;
|
||||
}
|
||||
|
||||
return FileAppender;
|
||||
return (wLogAppender *)FileAppender;
|
||||
|
||||
error_output_file_name:
|
||||
free(FileAppender->FilePath);
|
||||
@ -252,14 +284,3 @@ error_free:
|
||||
free(FileAppender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
free(appender->FileName);
|
||||
free(appender->FilePath);
|
||||
free(appender->FullFileName);
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
@ -20,11 +20,8 @@
|
||||
#ifndef WINPR_WLOG_FILE_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_FILE_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogFileAppender* WLog_FileAppender_New(wLog* log);
|
||||
WINPR_API void WLog_FileAppender_Free(wLog* log, wLogFileAppender* appender);
|
||||
wLogAppender* WLog_FileAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_WLOG_FILE_APPENDER_PRIVATE_H */
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
#include <winpr/image.h>
|
||||
|
||||
#include "wlog/ImageMessage.h"
|
||||
|
@ -20,10 +20,6 @@
|
||||
#ifndef WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
BOOL WLog_ImageMessage_Write(char* filename, void* data, int width, int height, int bpp);
|
||||
|
||||
#endif /* WINPR_WLOG_IMAGE_MESSAGE_PRIVATE_H */
|
||||
|
@ -22,59 +22,52 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "JournaldAppender.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <syslog.h>
|
||||
#include <systemd/sd-journal.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "wlog/JournaldAppender.h"
|
||||
|
||||
BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id)
|
||||
struct _wLogJournaldAppender
|
||||
{
|
||||
if (appender->identifier)
|
||||
free(appender->identifier);
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *identifier;
|
||||
FILE *stream;
|
||||
};
|
||||
typedef struct _wLogJournaldAppender wLogJournaldAppender;
|
||||
|
||||
if (appender->stream)
|
||||
{
|
||||
fclose(appender->stream);
|
||||
appender->stream = NULL;
|
||||
}
|
||||
|
||||
return ((appender->identifier = _strdup(id)) != NULL);
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_Open(wLog* log, wLogJournaldAppender* appender)
|
||||
static BOOL WLog_JournaldAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
int fd;
|
||||
wLogJournaldAppender *journaldAppender;
|
||||
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
|
||||
if (appender->stream)
|
||||
journaldAppender = (wLogJournaldAppender*)appender;
|
||||
if (journaldAppender->stream)
|
||||
return TRUE;
|
||||
|
||||
fd = sd_journal_stream_fd(appender->identifier, LOG_INFO, 1);
|
||||
fd = sd_journal_stream_fd(journaldAppender->identifier, LOG_INFO, 1);
|
||||
if (fd < 0)
|
||||
return FALSE;
|
||||
|
||||
appender->stream = fdopen(fd, "w");
|
||||
if (!appender->stream)
|
||||
journaldAppender->stream = fdopen(fd, "w");
|
||||
if (!journaldAppender->stream)
|
||||
{
|
||||
close(fd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
setbuffer(appender->stream, NULL, 0);
|
||||
setbuffer(journaldAppender->stream, NULL, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appender)
|
||||
static BOOL WLog_JournaldAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -82,13 +75,16 @@ static BOOL WLog_JournaldAppender_Close(wLog* log, wLogJournaldAppender* appende
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char *formatStr;
|
||||
wLogJournaldAppender* journaldAppender;
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
journaldAppender = (wLogJournaldAppender *)appender;
|
||||
|
||||
switch (message->Level)
|
||||
{
|
||||
case WLOG_TRACE:
|
||||
@ -114,11 +110,11 @@ static BOOL WLog_JournaldAppender_WriteMessage(wLog* log, wLogJournaldAppender*
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fprintf(appender->stream, formatStr, message->TextString);
|
||||
fprintf(journaldAppender->stream, formatStr, message->TextString);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -126,7 +122,7 @@ static BOOL WLog_JournaldAppender_WriteDataMessage(wLog* log, wLogJournaldAppend
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -135,7 +131,40 @@ static BOOL WLog_JournaldAppender_WriteImageMessage(wLog* log, wLogJournaldAppen
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
static BOOL WLog_JournaldAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogJournaldAppender* journaldAppender = (wLogJournaldAppender *)appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (strcmp("identifier", setting))
|
||||
return FALSE;
|
||||
|
||||
/* If the stream is already open the identifier can't be changed */
|
||||
if (journaldAppender->stream)
|
||||
return FALSE;
|
||||
|
||||
if (journaldAppender->identifier)
|
||||
free(journaldAppender->identifier);
|
||||
|
||||
return ((journaldAppender->identifier = _strdup((const char *)value)) != NULL);
|
||||
}
|
||||
|
||||
static void WLog_JournaldAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogJournaldAppender *journaldAppender;
|
||||
if (appender)
|
||||
{
|
||||
journaldAppender = (wLogJournaldAppender*)appender;
|
||||
if (journaldAppender->stream)
|
||||
fclose(journaldAppender->stream);
|
||||
free(journaldAppender->identifier);
|
||||
free(journaldAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
{
|
||||
wLogJournaldAppender* appender;
|
||||
DWORD nSize;
|
||||
@ -146,15 +175,13 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
return NULL;
|
||||
|
||||
appender->Type = WLOG_APPENDER_JOURNALD;
|
||||
|
||||
appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Open;
|
||||
appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_JournaldAppender_Close;
|
||||
appender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_JournaldAppender_WriteMessage;
|
||||
appender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_JournaldAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_JournaldAppender_WriteImageMessage;
|
||||
appender->Open = WLog_JournaldAppender_Open;
|
||||
appender->Close = WLog_JournaldAppender_Close;
|
||||
appender->WriteMessage = WLog_JournaldAppender_WriteMessage;
|
||||
appender->WriteDataMessage = WLog_JournaldAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage = WLog_JournaldAppender_WriteImageMessage;
|
||||
appender->Set = WLog_JournaldAppender_Set;
|
||||
appender->Free = WLog_JournaldAppender_Free;
|
||||
|
||||
name = "WLOG_JOURNALD_ID";
|
||||
nSize = GetEnvironmentVariableA(name, NULL, 0);
|
||||
@ -166,7 +193,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
|
||||
GetEnvironmentVariableA(name, appender->identifier, nSize);
|
||||
|
||||
if (!WLog_JournaldAppender_Open(log, appender))
|
||||
if (!WLog_JournaldAppender_Open(log, (wLogAppender *)appender))
|
||||
goto error_open;
|
||||
}
|
||||
else
|
||||
@ -176,7 +203,7 @@ wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log)
|
||||
goto error_env_malloc;
|
||||
}
|
||||
|
||||
return appender;
|
||||
return (wLogAppender *)appender;
|
||||
|
||||
error_open:
|
||||
free(appender->identifier);
|
||||
@ -184,14 +211,3 @@ error_env_malloc:
|
||||
free(appender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
if (appender->stream)
|
||||
fclose(appender->stream);
|
||||
free(appender->identifier);
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
@ -24,13 +24,8 @@
|
||||
#ifndef WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_
|
||||
#define WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogJournaldAppender* WLog_JournaldAppender_New(wLog* log);
|
||||
WINPR_API void WLog_JournaldAppender_Free(wLog* log, wLogJournaldAppender* appender);
|
||||
WINPR_API BOOL Wlog_JournaldAppender_SetIdentifier(wLogJournaldAppender* appender, const char *id);
|
||||
#include "wlog.h"
|
||||
|
||||
wLogAppender* WLog_JournaldAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_LIBWINPR_UTILS_WLOG_JOURNALDAPPENDER_H_ */
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <winpr/sysinfo.h>
|
||||
#include <winpr/environment.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/Layout.h"
|
||||
|
||||
|
@ -20,7 +20,18 @@
|
||||
#ifndef WINPR_WLOG_LAYOUT_PRIVATE_H
|
||||
#define WINPR_WLOG_LAYOUT_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
/**
|
||||
* Log Layout
|
||||
*/
|
||||
|
||||
struct _wLogLayout
|
||||
{
|
||||
DWORD Type;
|
||||
|
||||
LPSTR FormatString;
|
||||
};
|
||||
|
||||
wLogLayout* WLog_Layout_New(wLog* log);
|
||||
void WLog_Layout_Free(wLog* log, wLogLayout* layout);
|
||||
|
@ -25,9 +25,9 @@
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/file.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "Message.h"
|
||||
|
||||
char* WLog_Message_GetOutputFileName(int id, const char* ext)
|
||||
{
|
||||
|
@ -20,14 +20,9 @@
|
||||
#ifndef WINPR_WLOG_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
#include "wlog/TextMessage.h"
|
||||
#include "wlog/DataMessage.h"
|
||||
#include "wlog/ImageMessage.h"
|
||||
#include "wlog/PacketMessage.h"
|
||||
#include "DataMessage.h"
|
||||
#include "ImageMessage.h"
|
||||
#include "PacketMessage.h"
|
||||
|
||||
char* WLog_Message_GetOutputFileName(int id, const char* ext);
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/PacketMessage.h"
|
||||
|
||||
|
@ -20,9 +20,7 @@
|
||||
#ifndef WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_PACKET_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
#include "wlog.h"
|
||||
|
||||
#define PCAP_MAGIC_NUMBER 0xA1B2C3D4
|
||||
|
||||
|
@ -2,7 +2,8 @@
|
||||
* WinPR: Windows Portable Runtime
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2013 David FORT <contact@hardening-consulting.com>
|
||||
* Copyright © 2015 Thincast Technologies GmbH
|
||||
* Copyright © 2015 David FORT <contact@hardening-consulting.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -21,16 +22,14 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "SyslogAppender.h"
|
||||
#include <syslog.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "wlog/SyslogAppender.h"
|
||||
struct _wLogSyslogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
typedef struct _wLogSyslogAppender wLogSyslogAppender;
|
||||
|
||||
static int getSyslogLevel(DWORD level)
|
||||
{
|
||||
@ -53,7 +52,7 @@ static int getSyslogLevel(DWORD level)
|
||||
}
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender)
|
||||
static BOOL WLog_SyslogAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -61,7 +60,7 @@ static BOOL WLog_SyslogAppender_Open(wLog* log, wLogSyslogAppender* appender)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender)
|
||||
static BOOL WLog_SyslogAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -69,7 +68,7 @@ static BOOL WLog_SyslogAppender_Close(wLog* log, wLogSyslogAppender* appender)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int syslogLevel;
|
||||
|
||||
@ -83,7 +82,7 @@ static BOOL WLog_SyslogAppender_WriteMessage(wLog* log, wLogSyslogAppender* appe
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int syslogLevel;
|
||||
|
||||
@ -97,7 +96,7 @@ static BOOL WLog_SyslogAppender_WriteDataMessage(wLog* log, wLogSyslogAppender*
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
int syslogLevel;
|
||||
|
||||
@ -111,7 +110,12 @@ static BOOL WLog_SyslogAppender_WriteImageMessage(wLog* log, wLogSyslogAppender*
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log)
|
||||
void WLog_SyslogAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
free(appender);
|
||||
}
|
||||
|
||||
wLogAppender* WLog_SyslogAppender_New(wLog* log)
|
||||
{
|
||||
wLogSyslogAppender* appender;
|
||||
|
||||
@ -121,20 +125,12 @@ wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log)
|
||||
|
||||
appender->Type = WLOG_APPENDER_SYSLOG;
|
||||
|
||||
appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Open;
|
||||
appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_SyslogAppender_Close;
|
||||
appender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_SyslogAppender_WriteMessage;
|
||||
appender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_SyslogAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_SyslogAppender_WriteImageMessage;
|
||||
appender->Open = WLog_SyslogAppender_Open;
|
||||
appender->Close = WLog_SyslogAppender_Close;
|
||||
appender->WriteMessage = WLog_SyslogAppender_WriteMessage;
|
||||
appender->WriteDataMessage = WLog_SyslogAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage = WLog_SyslogAppender_WriteImageMessage;
|
||||
appender->Free = WLog_SyslogAppender_Free;
|
||||
|
||||
return appender;
|
||||
}
|
||||
|
||||
void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
free(appender);
|
||||
return (wLogAppender*)appender;
|
||||
}
|
||||
|
@ -24,12 +24,8 @@
|
||||
#ifndef WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_
|
||||
#define WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogSyslogAppender* WLog_SyslogAppender_New(wLog* log);
|
||||
WINPR_API void WLog_SyslogAppender_Free(wLog* log, wLogSyslogAppender* appender);
|
||||
#include "wlog.h"
|
||||
|
||||
wLogAppender* WLog_SyslogAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_LIBWINPR_UTILS_WLOG_SYSLOGAPPENDER_H_ */
|
||||
|
@ -21,10 +21,6 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/TextMessage.h"
|
||||
|
||||
void wlog_TextMessage_dummy()
|
||||
{
|
||||
/* avoid no symbol ranlib warning */
|
||||
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H
|
||||
#define WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
|
||||
|
||||
#endif /* WINPR_WLOG_TEXT_MESSAGE_PRIVATE_H */
|
||||
|
@ -25,39 +25,42 @@
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/environment.h>
|
||||
#include <winpr/thread.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/Message.h"
|
||||
#include "wlog/UdpAppender.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender)
|
||||
struct _wLogUdpAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
char *host;
|
||||
struct sockaddr targetAddr;
|
||||
int targetAddrLen;
|
||||
SOCKET sock;
|
||||
};
|
||||
typedef struct _wLogUdpAppender wLogUdpAppender;
|
||||
|
||||
static BOOL WLog_UdpAppender_Open(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
wLogUdpAppender *udpAppender;
|
||||
char addressString[256];
|
||||
struct addrinfo hints;
|
||||
struct addrinfo* result;
|
||||
int status, addrLen;
|
||||
char *colonPos;
|
||||
|
||||
|
||||
if (!appender)
|
||||
return FALSE;
|
||||
|
||||
if (appender->targetAddrLen) /* already opened */
|
||||
udpAppender = (wLogUdpAppender*)appender;
|
||||
|
||||
if (udpAppender->targetAddrLen) /* already opened */
|
||||
return TRUE;
|
||||
|
||||
colonPos = strchr(appender->host, ':');
|
||||
colonPos = strchr(udpAppender->host, ':');
|
||||
if (!colonPos)
|
||||
return FALSE;
|
||||
addrLen = colonPos - appender->host;
|
||||
memcpy(addressString, appender->host, addrLen);
|
||||
addrLen = colonPos - udpAppender->host;
|
||||
memcpy(addressString, udpAppender->host, addrLen);
|
||||
addressString[addrLen] = '\0';
|
||||
|
||||
ZeroMemory(&hints, sizeof(hints));
|
||||
@ -68,31 +71,19 @@ static BOOL WLog_UdpAppender_Open(wLog* log, wLogUdpAppender* appender)
|
||||
if (status != 0)
|
||||
return FALSE;
|
||||
|
||||
if (result->ai_addrlen > sizeof(appender->targetAddr))
|
||||
if (result->ai_addrlen > sizeof(udpAppender->targetAddr))
|
||||
{
|
||||
freeaddrinfo(result);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
memcpy(&appender->targetAddr, result->ai_addr, result->ai_addrlen);
|
||||
appender->targetAddrLen = result->ai_addrlen;
|
||||
|
||||
memcpy(&udpAppender->targetAddr, result->ai_addr, result->ai_addrlen);
|
||||
udpAppender->targetAddrLen = result->ai_addrlen;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host)
|
||||
{
|
||||
|
||||
appender->targetAddrLen = 0;
|
||||
if (appender->host)
|
||||
free(appender->host);
|
||||
|
||||
appender->host = _strdup(host);
|
||||
return (appender->host != NULL) && WLog_UdpAppender_Open(NULL, appender);
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender)
|
||||
static BOOL WLog_UdpAppender_Close(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
if (!log || !appender)
|
||||
return FALSE;
|
||||
@ -100,28 +91,32 @@ static BOOL WLog_UdpAppender_Close(wLog* log, wLogUdpAppender* appender)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
wLogUdpAppender *udpAppender;
|
||||
|
||||
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
|
||||
udpAppender = (wLogUdpAppender *)appender;
|
||||
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
_sendto(appender->sock, message->PrefixString, strlen(message->PrefixString),
|
||||
0, &appender->targetAddr, appender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, message->PrefixString, strlen(message->PrefixString),
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
_sendto(appender->sock, message->TextString, strlen(message->TextString),
|
||||
0, &appender->targetAddr, appender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, message->TextString, strlen(message->TextString),
|
||||
0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
_sendto(appender->sock, "\n", 1, 0, &appender->targetAddr, appender->targetAddrLen);
|
||||
_sendto(udpAppender->sock, "\n", 1, 0, &udpAppender->targetAddr, udpAppender->targetAddrLen);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -129,7 +124,7 @@ static BOOL WLog_UdpAppender_WriteDataMessage(wLog* log, wLogUdpAppender* append
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appender, wLogMessage* message)
|
||||
static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!log || !appender || !message)
|
||||
return FALSE;
|
||||
@ -138,7 +133,41 @@ static BOOL WLog_UdpAppender_WriteImageMessage(wLog* log, wLogUdpAppender* appen
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
static BOOL WLog_UdpAppender_Set(wLogAppender* appender, const char *setting, void *value)
|
||||
{
|
||||
wLogUdpAppender *udpAppender = (wLogUdpAppender *)appender;
|
||||
|
||||
if (!value || !strlen(value))
|
||||
return FALSE;
|
||||
|
||||
if (strcmp("target", setting))
|
||||
return FALSE;
|
||||
|
||||
udpAppender->targetAddrLen = 0;
|
||||
if (udpAppender->host)
|
||||
free(udpAppender->host);
|
||||
|
||||
udpAppender->host = _strdup((const char *)value);
|
||||
return (udpAppender->host != NULL) && WLog_UdpAppender_Open(NULL, appender);
|
||||
}
|
||||
|
||||
static void WLog_UdpAppender_Free(wLogAppender* appender)
|
||||
{
|
||||
wLogUdpAppender* udpAppender;
|
||||
if (appender)
|
||||
{
|
||||
udpAppender = (wLogUdpAppender *)appender;
|
||||
if (udpAppender->sock != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(udpAppender->sock);
|
||||
udpAppender->sock = INVALID_SOCKET;
|
||||
}
|
||||
free(udpAppender->host);
|
||||
free(udpAppender);
|
||||
}
|
||||
}
|
||||
|
||||
wLogAppender* WLog_UdpAppender_New(wLog* log)
|
||||
{
|
||||
wLogUdpAppender* appender;
|
||||
DWORD nSize;
|
||||
@ -150,14 +179,13 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
|
||||
appender->Type = WLOG_APPENDER_UDP;
|
||||
|
||||
appender->Open = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Open;
|
||||
appender->Close = (WLOG_APPENDER_OPEN_FN) WLog_UdpAppender_Close;
|
||||
appender->WriteMessage =
|
||||
(WLOG_APPENDER_WRITE_MESSAGE_FN) WLog_UdpAppender_WriteMessage;
|
||||
appender->WriteDataMessage =
|
||||
(WLOG_APPENDER_WRITE_DATA_MESSAGE_FN) WLog_UdpAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage =
|
||||
(WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN) WLog_UdpAppender_WriteImageMessage;
|
||||
appender->Open = WLog_UdpAppender_Open;
|
||||
appender->Close = WLog_UdpAppender_Close;
|
||||
appender->WriteMessage = WLog_UdpAppender_WriteMessage;
|
||||
appender->WriteDataMessage = WLog_UdpAppender_WriteDataMessage;
|
||||
appender->WriteImageMessage = WLog_UdpAppender_WriteImageMessage;
|
||||
appender->Free = WLog_UdpAppender_Free;
|
||||
appender->Set = WLog_UdpAppender_Set;
|
||||
|
||||
appender->sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
if (appender->sock == INVALID_SOCKET)
|
||||
@ -173,7 +201,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
|
||||
GetEnvironmentVariableA(name, appender->host, nSize);
|
||||
|
||||
if (!WLog_UdpAppender_Open(log, appender))
|
||||
if (!WLog_UdpAppender_Open(log, (wLogAppender *)appender))
|
||||
goto error_open;
|
||||
}
|
||||
else
|
||||
@ -183,7 +211,7 @@ wLogUdpAppender* WLog_UdpAppender_New(wLog* log)
|
||||
goto error_host_alloc;
|
||||
}
|
||||
|
||||
return appender;
|
||||
return (wLogAppender*)appender;
|
||||
|
||||
error_open:
|
||||
free(appender->host);
|
||||
@ -193,17 +221,3 @@ error_sock:
|
||||
free(appender);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
if (appender->sock != INVALID_SOCKET)
|
||||
{
|
||||
closesocket(appender->sock);
|
||||
appender->sock = INVALID_SOCKET;
|
||||
}
|
||||
free(appender->host);
|
||||
free(appender);
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,6 @@
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogUdpAppender* WLog_UdpAppender_New(wLog* log);
|
||||
WINPR_API void WLog_UdpAppender_Free(wLog* log, wLogUdpAppender* appender);
|
||||
WINPR_API BOOL Wlog_UdpAppender_SetTarget(wLogUdpAppender* appender, const char *host);
|
||||
wLogAppender* WLog_UdpAppender_New(wLog* log);
|
||||
|
||||
#endif /* WINPR_LIBWINPR_UTILS_WLOG_UDPAPPENDER_H_ */
|
||||
|
@ -33,11 +33,16 @@
|
||||
#include <android/log.h>
|
||||
#endif
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
#include "wlog.h"
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
#include "../../log.h"
|
||||
struct _wLogFilter
|
||||
{
|
||||
DWORD Level;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
};
|
||||
typedef struct _wLogFilter wLogFilter;
|
||||
|
||||
/**
|
||||
* References for general logging concepts:
|
||||
|
@ -25,9 +25,62 @@
|
||||
#define WLOG_MAX_PREFIX_SIZE 512
|
||||
#define WLOG_MAX_STRING_SIZE 8192
|
||||
|
||||
|
||||
typedef BOOL (*WLOG_APPENDER_OPEN_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_CLOSE_FN)(wLog* log, wLogAppender* appender);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_DATA_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN)(wLog* log, wLogAppender* appender, wLogMessage* message);
|
||||
typedef BOOL (*WLOG_APPENDER_SET)(wLogAppender* appender, const char *setting, void *value);
|
||||
typedef void (*WLOG_APPENDER_FREE)(wLogAppender* appender);
|
||||
|
||||
#define WLOG_APPENDER_COMMON() \
|
||||
DWORD Type; \
|
||||
DWORD State; \
|
||||
wLogLayout* Layout; \
|
||||
CRITICAL_SECTION lock; \
|
||||
BOOL recursive; \
|
||||
void* TextMessageContext; \
|
||||
void* DataMessageContext; \
|
||||
void* ImageMessageContext; \
|
||||
void* PacketMessageContext; \
|
||||
WLOG_APPENDER_OPEN_FN Open; \
|
||||
WLOG_APPENDER_CLOSE_FN Close; \
|
||||
WLOG_APPENDER_WRITE_MESSAGE_FN WriteMessage; \
|
||||
WLOG_APPENDER_WRITE_DATA_MESSAGE_FN WriteDataMessage; \
|
||||
WLOG_APPENDER_WRITE_IMAGE_MESSAGE_FN WriteImageMessage; \
|
||||
WLOG_APPENDER_WRITE_PACKET_MESSAGE_FN WritePacketMessage; \
|
||||
WLOG_APPENDER_FREE Free; \
|
||||
WLOG_APPENDER_SET Set
|
||||
|
||||
|
||||
struct _wLogAppender
|
||||
{
|
||||
WLOG_APPENDER_COMMON();
|
||||
};
|
||||
|
||||
struct _wLog
|
||||
{
|
||||
LPSTR Name;
|
||||
DWORD Level;
|
||||
|
||||
BOOL IsRoot;
|
||||
LPSTR* Names;
|
||||
DWORD NameCount;
|
||||
wLogAppender* Appender;
|
||||
|
||||
wLog* Parent;
|
||||
wLog** Children;
|
||||
DWORD ChildrenCount;
|
||||
DWORD ChildrenSize;
|
||||
};
|
||||
|
||||
|
||||
BOOL WLog_Layout_GetMessagePrefix(wLog* log, wLogLayout* layout, wLogMessage* message);
|
||||
|
||||
#include "wlog/Layout.h"
|
||||
#include "wlog/Appender.h"
|
||||
|
||||
|
||||
#endif /* WINPR_WLOG_PRIVATE_H */
|
||||
|
Loading…
Reference in New Issue
Block a user