Added callback appender for wlog.
This commit is contained in:
parent
7a6c6b7436
commit
6de22298d0
@ -112,6 +112,7 @@ struct _wLogLayout
|
||||
#define WLOG_APPENDER_CONSOLE 0
|
||||
#define WLOG_APPENDER_FILE 1
|
||||
#define WLOG_APPENDER_BINARY 2
|
||||
#define WLOG_APPENDER_CALLBACK 3
|
||||
|
||||
#define WLOG_PACKET_INBOUND 1
|
||||
#define WLOG_PACKET_OUTBOUND 2
|
||||
@ -179,6 +180,22 @@ struct _wLogBinaryAppender
|
||||
};
|
||||
typedef struct _wLogBinaryAppender wLogBinaryAppender;
|
||||
|
||||
typedef void (*CallbackAppenderMessage_t)(const wLogMessage *msg);
|
||||
typedef void (*CallbackAppenderData_t)(const wLogMessage *msg);
|
||||
typedef void (*CallbackAppenderImage_t)(const wLogMessage *msg);
|
||||
typedef void (*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;
|
||||
|
||||
/**
|
||||
* Filter
|
||||
*/
|
||||
@ -309,6 +326,10 @@ WINPR_API void WLog_ConsoleAppender_SetOutputStream(wLog* log, wLogConsoleAppend
|
||||
WINPR_API void WLog_FileAppender_SetOutputFileName(wLog* log, wLogFileAppender* appender, const char* filename);
|
||||
WINPR_API void WLog_FileAppender_SetOutputFilePath(wLog* log, wLogFileAppender* appender, const char* filepath);
|
||||
|
||||
WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
|
||||
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
|
||||
CallbackAppenderData_t data);
|
||||
|
||||
WINPR_API wLogLayout* WLog_GetLogLayout(wLog* log);
|
||||
WINPR_API void WLog_Layout_SetPrefixFormat(wLog* log, wLogLayout* layout, const char* format);
|
||||
|
||||
|
@ -72,6 +72,8 @@ set(${MODULE_PREFIX}_WLOG_SRCS
|
||||
wlog/FileAppender.h
|
||||
wlog/BinaryAppender.c
|
||||
wlog/BinaryAppender.h
|
||||
wlog/CallbackAppender.c
|
||||
wlog/CallbackAppender.h
|
||||
wlog/ConsoleAppender.c
|
||||
wlog/ConsoleAppender.h)
|
||||
|
||||
|
@ -43,6 +43,10 @@ wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
|
||||
{
|
||||
appender = (wLogAppender*) WLog_BinaryAppender_New(log);
|
||||
}
|
||||
else if (logAppenderType == WLOG_APPENDER_CALLBACK)
|
||||
{
|
||||
appender = (wLogAppender*) WLog_CallbackAppender_New(log);
|
||||
}
|
||||
|
||||
if (!appender)
|
||||
appender = (wLogAppender*) WLog_ConsoleAppender_New(log);
|
||||
@ -78,6 +82,10 @@ void WLog_Appender_Free(wLog* log, wLogAppender* appender)
|
||||
{
|
||||
WLog_BinaryAppender_Free(log, (wLogBinaryAppender*) appender);
|
||||
}
|
||||
else if (appender->Type == WLOG_APPENDER_CALLBACK)
|
||||
{
|
||||
WLog_CallbackAppender_Free(log, (wLogCallbackAppender*) appender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "wlog/FileAppender.h"
|
||||
#include "wlog/BinaryAppender.h"
|
||||
#include "wlog/ConsoleAppender.h"
|
||||
#include "wlog/CallbackAppender.h"
|
||||
|
||||
void WLog_Appender_Free(wLog* log, wLogAppender* appender);
|
||||
|
||||
|
161
winpr/libwinpr/utils/wlog/CallbackAppender.c
Normal file
161
winpr/libwinpr/utils/wlog/CallbackAppender.c
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2014 Armin Novak <armin.novak@thincast.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.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/Message.h"
|
||||
|
||||
#include "wlog/CallbackAppender.h"
|
||||
|
||||
/**
|
||||
* Callback Appender
|
||||
*/
|
||||
|
||||
WINPR_API void WLog_CallbackAppender_SetCallbacks(wLog* log, wLogCallbackAppender* appender,
|
||||
CallbackAppenderMessage_t msg, CallbackAppenderImage_t img, CallbackAppenderPackage_t pkg,
|
||||
CallbackAppenderData_t data)
|
||||
{
|
||||
if (!appender)
|
||||
return;
|
||||
|
||||
if (appender->Type != WLOG_APPENDER_CALLBACK)
|
||||
return;
|
||||
|
||||
appender->message = msg;
|
||||
appender->image = img;
|
||||
appender->package = pkg;
|
||||
}
|
||||
|
||||
int WLog_CallbackAppender_Open(wLog* log, wLogCallbackAppender* appender)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WLog_CallbackAppender_Close(wLog* log, wLogCallbackAppender* appender)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WLog_CallbackAppender_WriteMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
{
|
||||
char prefix[WLOG_MAX_PREFIX_SIZE];
|
||||
|
||||
message->PrefixString = prefix;
|
||||
WLog_Layout_GetMessagePrefix(log, appender->Layout, message);
|
||||
|
||||
if (appender->message)
|
||||
{
|
||||
appender->message(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WLog_CallbackAppender_WriteDataMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->data)
|
||||
{
|
||||
appender->data(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WLog_CallbackAppender_WriteImageMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (appender->image)
|
||||
{
|
||||
appender->image(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WLog_CallbackAppender_WritePacketMessage(wLog* log, wLogCallbackAppender* appender, wLogMessage* message)
|
||||
{
|
||||
if (!appender->package)
|
||||
{
|
||||
appender->package(message);
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log)
|
||||
{
|
||||
wLogCallbackAppender* CallbackAppender;
|
||||
|
||||
CallbackAppender = (wLogCallbackAppender*) malloc(sizeof(wLogCallbackAppender));
|
||||
|
||||
if (CallbackAppender)
|
||||
{
|
||||
ZeroMemory(CallbackAppender, sizeof(wLogCallbackAppender));
|
||||
|
||||
CallbackAppender->Type = WLOG_APPENDER_CONSOLE;
|
||||
|
||||
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->message = NULL;
|
||||
CallbackAppender->image = NULL;
|
||||
CallbackAppender->package = NULL;
|
||||
}
|
||||
|
||||
return CallbackAppender;
|
||||
}
|
||||
|
||||
void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender)
|
||||
{
|
||||
if (appender)
|
||||
{
|
||||
free(appender);
|
||||
}
|
||||
}
|
30
winpr/libwinpr/utils/wlog/CallbackAppender.h
Normal file
30
winpr/libwinpr/utils/wlog/CallbackAppender.h
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* WinPR: Windows Portable Runtime
|
||||
* WinPR Logger
|
||||
*
|
||||
* Copyright 2014 Armin Novak <armin.novak@thincast.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_CALLBACK_APPENDER_PRIVATE_H
|
||||
#define WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H
|
||||
|
||||
#include <winpr/wlog.h>
|
||||
|
||||
#include "wlog/wlog.h"
|
||||
|
||||
WINPR_API wLogCallbackAppender* WLog_CallbackAppender_New(wLog* log);
|
||||
WINPR_API void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender);
|
||||
|
||||
#endif /* WINPR_WLOG_CALLBACK_APPENDER_PRIVATE_H */
|
Loading…
Reference in New Issue
Block a user