Merge pull request #2213 from akallabeth/wlog_callback_appender

Wlog callback appender
This commit is contained in:
Marc-André Moreau 2014-11-17 09:41:58 -05:00
commit 8a7a71a7b6
17 changed files with 440 additions and 70 deletions

View File

@ -23,6 +23,7 @@
#include <unistd.h>
#include <sys/mman.h>
#include <freerdp/log.h>
#include <freerdp/freerdp.h>
#include <freerdp/client/cmdline.h>
#include <freerdp/channels/channels.h>
@ -30,6 +31,8 @@
#include <wayland-client.h>
#define TAG CLIENT_TAG("wayland")
struct display
{
struct wl_display* display;
@ -101,7 +104,7 @@ static void window_redraw(void* data, struct wl_callback* callback, uint32_t tim
fdt = ftruncate(fd, window->width * window->height * 4);
if (fdt != 0)
{
fprintf(stderr, "window_redraw: could not allocate memory\n");
WLog_ERR(TAG, "window_redraw: could not allocate memory");
close(fd);
return;
}
@ -109,7 +112,7 @@ static void window_redraw(void* data, struct wl_callback* callback, uint32_t tim
buffer->shm_data = mmap(0, window->width * window->height * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buffer->shm_data == MAP_FAILED)
{
fprintf(stderr, "window_redraw: failed to memory map buffer\n");
WLog_ERR(TAG, "window_redraw: failed to memory map buffer");
close(fd);
return;
}
@ -232,8 +235,8 @@ BOOL wl_pre_connect(freerdp* instance)
if (!display->display)
{
fprintf(stderr, "wl_pre_connect: failed to connect to Wayland compositor\n");
fprintf(stderr, "Please check that the XDG_RUNTIME_DIR environment variable is properly set.\n");
WLog_ERR(TAG, "wl_pre_connect: failed to connect to Wayland compositor");
WLog_ERR(TAG, "Please check that the XDG_RUNTIME_DIR environment variable is properly set.");
free(display);
return FALSE;
}
@ -244,7 +247,7 @@ BOOL wl_pre_connect(freerdp* instance)
if (!display->compositor || !display->shell || !display->shm)
{
fprintf(stderr, "wl_pre_connect: failed to find needed compositor interfaces\n");
WLog_ERR(TAG, "wl_pre_connect: failed to find needed compositor interfaces");
free(display);
return FALSE;
}

View File

@ -20,11 +20,14 @@
#include "config.h"
#endif
#include <freerdp/log.h>
#include <winpr/tchar.h>
#include <winpr/print.h>
#include "wf_rail.h"
#define TAG CLIENT_TAG("windows")
#define GET_X_LPARAM(lParam) ((UINT16) (lParam & 0xFFFF))
#define GET_Y_LPARAM(lParam) ((UINT16) ((lParam >> 16) & 0xFFFF))
@ -99,7 +102,7 @@ void PrintWindowStyles(UINT32 style)
{
int i;
fprintf(stderr, "\tWindow Styles:\n\t{\n");
WLog_INFO(TAG, "\tWindow Styles:\t{");
for (i = 0; i < ARRAYSIZE(WINDOW_STYLES); i++)
{
if (style & WINDOW_STYLES[i].style)
@ -110,17 +113,16 @@ void PrintWindowStyles(UINT32 style)
continue;
}
fprintf(stderr, "\t\t%s\n", WINDOW_STYLES[i].name);
WLog_INFO(TAG, "\t\t%s", WINDOW_STYLES[i].name);
}
}
fprintf(stderr, "\t}\n");
}
void PrintExtendedWindowStyles(UINT32 style)
{
int i;
fprintf(stderr, "\tExtended Window Styles:\n\t{\n");
WLog_INFO(TAG, "\tExtended Window Styles:\t{");
for (i = 0; i < ARRAYSIZE(EXTENDED_WINDOW_STYLES); i++)
{
if (style & EXTENDED_WINDOW_STYLES[i].style)
@ -131,29 +133,28 @@ void PrintExtendedWindowStyles(UINT32 style)
continue;
}
fprintf(stderr, "\t\t%s\n", EXTENDED_WINDOW_STYLES[i].name);
WLog_INFO(TAG, "\t\t%s", EXTENDED_WINDOW_STYLES[i].name);
}
}
fprintf(stderr, "\t}\n");
}
void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* windowState)
{
if (orderInfo->fieldFlags & WINDOW_ORDER_STATE_NEW)
fprintf(stderr, "WindowCreate: WindowId: 0x%04X\n", orderInfo->windowId);
WLog_INFO(TAG, "WindowCreate: WindowId: 0x%04X", orderInfo->windowId);
else
fprintf(stderr, "WindowUpdate: WindowId: 0x%04X\n", orderInfo->windowId);
WLog_INFO(TAG, "WindowUpdate: WindowId: 0x%04X", orderInfo->windowId);
fprintf(stderr, "{\n");
WLog_INFO(TAG, "{");
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_OWNER)
{
fprintf(stderr, "\tOwnerWindowId: 0x%04X\n", windowState->ownerWindowId);
WLog_INFO(TAG, "\tOwnerWindowId: 0x%04X", windowState->ownerWindowId);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_STYLE)
{
fprintf(stderr, "\tStyle: 0x%04X ExtendedStyle: 0x%04X\n",
WLog_INFO(TAG, "\tStyle: 0x%04X ExtendedStyle: 0x%04X",
windowState->style, windowState->extendedStyle);
PrintWindowStyles(windowState->style);
@ -162,7 +163,7 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_SHOW)
{
fprintf(stderr, "\tShowState: %d\n", windowState->showState);
WLog_INFO(TAG, "\tShowState: %d", windowState->showState);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_TITLE)
@ -172,7 +173,7 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind
ConvertFromUnicode(CP_UTF8, 0, (WCHAR*) windowState->titleInfo.string,
windowState->titleInfo.length / 2, &title, 0, NULL, NULL);
fprintf(stderr, "\tTitleInfo: %s (length = %d)\n", title,
WLog_INFO(TAG, "\tTitleInfo: %s (length = %d)", title,
windowState->titleInfo.length);
free(title);
@ -180,41 +181,41 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_OFFSET)
{
fprintf(stderr, "\tClientOffsetX: %d ClientOffsetY: %d\n",
WLog_INFO(TAG, "\tClientOffsetX: %d ClientOffsetY: %d",
windowState->clientOffsetX, windowState->clientOffsetY);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_CLIENT_AREA_SIZE)
{
fprintf(stderr, "\tClientAreaWidth: %d ClientAreaHeight: %d\n",
WLog_INFO(TAG, "\tClientAreaWidth: %d ClientAreaHeight: %d",
windowState->clientAreaWidth, windowState->clientAreaHeight);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_RP_CONTENT)
{
fprintf(stderr, "\tRPContent: %d\n", windowState->RPContent);
WLog_INFO(TAG, "\tRPContent: %d", windowState->RPContent);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ROOT_PARENT)
{
fprintf(stderr, "\tRootParentHandle: 0x%04X\n", windowState->rootParentHandle);
WLog_INFO(TAG, "\tRootParentHandle: 0x%04X", windowState->rootParentHandle);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_OFFSET)
{
fprintf(stderr, "\tWindowOffsetX: %d WindowOffsetY: %d\n",
WLog_INFO(TAG, "\tWindowOffsetX: %d WindowOffsetY: %d",
windowState->windowOffsetX, windowState->windowOffsetY);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_CLIENT_DELTA)
{
fprintf(stderr, "\tWindowClientDeltaX: %d WindowClientDeltaY: %d\n",
WLog_INFO(TAG, "\tWindowClientDeltaX: %d WindowClientDeltaY: %d",
windowState->windowClientDeltaX, windowState->windowClientDeltaY);
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_WND_SIZE)
{
fprintf(stderr, "\tWindowWidth: %d WindowHeight: %d\n",
WLog_INFO(TAG, "\tWindowWidth: %d WindowHeight: %d",
windowState->windowWidth, windowState->windowHeight);
}
@ -223,20 +224,20 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind
UINT32 index;
RECTANGLE_16* rect;
fprintf(stderr, "\tnumWindowRects: %d\n", windowState->numWindowRects);
WLog_INFO(TAG, "\tnumWindowRects: %d", windowState->numWindowRects);
for (index = 0; index < windowState->numWindowRects; index++)
{
rect = &windowState->windowRects[index];
fprintf(stderr, "\twindowRect[%d]: left: %d top: %d right: %d bottom: %d\n",
WLog_INFO(TAG, "\twindowRect[%d]: left: %d top: %d right: %d bottom: %d",
index, rect->left, rect->top, rect->right, rect->bottom);
}
}
if (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_VIS_OFFSET)
{
fprintf(stderr, "\tvisibileOffsetX: %d visibleOffsetY: %d\n",
WLog_INFO(TAG, "\tvisibileOffsetX: %d visibleOffsetY: %d",
windowState->visibleOffsetX, windowState->visibleOffsetY);
}
@ -245,39 +246,39 @@ void PrintRailWindowState(WINDOW_ORDER_INFO* orderInfo, WINDOW_STATE_ORDER* wind
UINT32 index;
RECTANGLE_16* rect;
fprintf(stderr, "\tnumVisibilityRects: %d\n", windowState->numVisibilityRects);
WLog_INFO(TAG, "\tnumVisibilityRects: %d", windowState->numVisibilityRects);
for (index = 0; index < windowState->numVisibilityRects; index++)
{
rect = &windowState->visibilityRects[index];
fprintf(stderr, "\tvisibilityRect[%d]: left: %d top: %d right: %d bottom: %d\n",
WLog_INFO(TAG, "\tvisibilityRect[%d]: left: %d top: %d right: %d bottom: %d",
index, rect->left, rect->top, rect->right, rect->bottom);
}
}
fprintf(stderr, "}\n");
WLog_INFO(TAG, "}");
}
static void PrintRailIconInfo(WINDOW_ORDER_INFO* orderInfo, ICON_INFO* iconInfo)
{
fprintf(stderr, "ICON_INFO\n");
fprintf(stderr, "{\n");
WLog_INFO(TAG, "ICON_INFO");
WLog_INFO(TAG, "{");
fprintf(stderr, "\tbigIcon: %s\n", (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? "true" : "false");
fprintf(stderr, "\tcacheEntry; 0x%04X\n", iconInfo->cacheEntry);
fprintf(stderr, "\tcacheId: 0x%04X\n", iconInfo->cacheId);
fprintf(stderr, "\tbpp: %d\n", iconInfo->bpp);
fprintf(stderr, "\twidth: %d\n", iconInfo->width);
fprintf(stderr, "\theight: %d\n", iconInfo->height);
fprintf(stderr, "\tcbColorTable: %d\n", iconInfo->cbColorTable);
fprintf(stderr, "\tcbBitsMask: %d\n", iconInfo->cbBitsMask);
fprintf(stderr, "\tcbBitsColor: %d\n", iconInfo->cbBitsColor);
fprintf(stderr, "\tcolorTable: %p\n", iconInfo->colorTable);
fprintf(stderr, "\tbitsMask: %p\n", iconInfo->bitsMask);
fprintf(stderr, "\tbitsColor: %p\n", iconInfo->bitsColor);
WLog_INFO(TAG, "\tbigIcon: %s", (orderInfo->fieldFlags & WINDOW_ORDER_FIELD_ICON_BIG) ? "true" : "false");
WLog_INFO(TAG, "\tcacheEntry; 0x%04X", iconInfo->cacheEntry);
WLog_INFO(TAG, "\tcacheId: 0x%04X", iconInfo->cacheId);
WLog_INFO(TAG, "\tbpp: %d", iconInfo->bpp);
WLog_INFO(TAG, "\twidth: %d", iconInfo->width);
WLog_INFO(TAG, "\theight: %d", iconInfo->height);
WLog_INFO(TAG, "\tcbColorTable: %d", iconInfo->cbColorTable);
WLog_INFO(TAG, "\tcbBitsMask: %d", iconInfo->cbBitsMask);
WLog_INFO(TAG, "\tcbBitsColor: %d", iconInfo->cbBitsColor);
WLog_INFO(TAG, "\tcolorTable: %p", iconInfo->colorTable);
WLog_INFO(TAG, "\tbitsMask: %p", iconInfo->bitsMask);
WLog_INFO(TAG, "\tbitsColor: %p", iconInfo->bitsColor);
fprintf(stderr, "}\n");
WLog_INFO(TAG, "}");
}
LRESULT CALLBACK wf_RailWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
@ -650,7 +651,7 @@ static void wf_rail_window_delete(rdpContext* context, WINDOW_ORDER_INFO* orderI
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailWindowDelete\n");
WLog_DBG(TAG, "RailWindowDelete");
railWindow = (wfRailWindow*) HashTable_GetItemValue(wfc->railWindows,
(void*) (UINT_PTR) orderInfo->windowId);
@ -680,7 +681,7 @@ static void wf_rail_window_icon(rdpContext* context, WINDOW_ORDER_INFO* orderInf
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailWindowIcon\n");
WLog_DBG(TAG, "RailWindowIcon");
PrintRailIconInfo(orderInfo, windowIcon->iconInfo);
@ -750,7 +751,7 @@ static void wf_rail_window_icon(rdpContext* context, WINDOW_ORDER_INFO* orderInf
static void wf_rail_window_cached_icon(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, WINDOW_CACHED_ICON_ORDER* windowCachedIcon)
{
fprintf(stderr, "RailWindowCachedIcon\n");
WLog_DBG(TAG, "RailWindowCachedIcon");
}
static void wf_rail_notify_icon_common(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, NOTIFY_ICON_STATE_ORDER* notifyIconState)
@ -793,7 +794,7 @@ static void wf_rail_notify_icon_create(rdpContext* context, WINDOW_ORDER_INFO* o
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailNotifyIconCreate\n");
WLog_DBG(TAG, "RailNotifyIconCreate");
wf_rail_notify_icon_common(context, orderInfo, notifyIconState);
}
@ -803,7 +804,7 @@ static void wf_rail_notify_icon_update(rdpContext* context, WINDOW_ORDER_INFO* o
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailNotifyIconUpdate\n");
WLog_DBG(TAG, "RailNotifyIconUpdate");
wf_rail_notify_icon_common(context, orderInfo, notifyIconState);
}
@ -813,7 +814,7 @@ static void wf_rail_notify_icon_delete(rdpContext* context, WINDOW_ORDER_INFO* o
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailNotifyIconDelete\n");
WLog_DBG(TAG, "RailNotifyIconDelete");
}
static void wf_rail_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO* orderInfo, MONITORED_DESKTOP_ORDER* monitoredDesktop)
@ -821,7 +822,7 @@ static void wf_rail_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO* or
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailMonitorDesktop\n");
WLog_DBG(TAG, "RailMonitorDesktop");
}
static void wf_rail_non_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO* orderInfo)
@ -829,7 +830,7 @@ static void wf_rail_non_monitored_desktop(rdpContext* context, WINDOW_ORDER_INFO
wfContext* wfc = (wfContext*) context;
RailClientContext* rail = wfc->rail;
fprintf(stderr, "RailNonMonitorDesktop\n");
WLog_DBG(TAG, "RailNonMonitorDesktop");
}
void wf_rail_register_update_callbacks(rdpUpdate* update)
@ -852,7 +853,7 @@ void wf_rail_register_update_callbacks(rdpUpdate* update)
static int wf_rail_server_execute_result(RailClientContext* context, RAIL_EXEC_RESULT_ORDER* execResult)
{
fprintf(stderr, "RailServerExecuteResult: 0x%04X\n", execResult->rawResult);
WLog_DBG(TAG, "RailServerExecuteResult: 0x%04X", execResult->rawResult);
return 1;
}

View File

@ -28,10 +28,13 @@
#include <winpr/crt.h>
#include <freerdp/api.h>
#include <freerdp/log.h>
#include <freerdp/freerdp.h>
#include <freerdp/primitives.h>
#include <freerdp/codec/color.h>
#define TAG FREERDP_TAG("color")
int freerdp_get_pixel(BYTE* data, int x, int y, int width, int height, int bpp)
{
int start;
@ -1372,7 +1375,7 @@ int freerdp_image_copy_from_monochrome(BYTE* pDstData, UINT32 DstFormat, int nDs
return 1;
}
fprintf(stderr, "freerdp_image_copy_from_monochrome failure: dstBytesPerPixel: %d dstBitsPerPixel: %d\n",
WLog_ERR(TAG, "failure: dstBytesPerPixel: %d dstBitsPerPixel: %d",
dstBytesPerPixel, dstBitsPerPixel);
return -1;
@ -1563,7 +1566,7 @@ int freerdp_image_copy_from_pointer_data(BYTE* pDstData, UINT32 DstFormat, int n
}
}
fprintf(stderr, "freerdp_image_copy_from_pointer_data: failed to convert from %d bpp to %d bpp\n",
WLog_ERR(TAG, "failed to convert from %d bpp to %d bpp",
xorBpp, dstBitsPerPixel);
return -1;
@ -3315,7 +3318,7 @@ int freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, int nDstStep, int nXDst,
dstBitsPerPixel = FREERDP_PIXEL_FORMAT_DEPTH(DstFormat);
dstBytesPerPixel = (FREERDP_PIXEL_FORMAT_BPP(DstFormat) / 8);
fprintf(stderr, "freerdp_image_copy failure: src: %d/%d dst: %d/%d\n",
WLog_ERR(TAG, "failure: src: %d/%d dst: %d/%d",
srcBitsPerPixel, srcBytesPerPixel, dstBitsPerPixel, dstBytesPerPixel);
}

View File

@ -22,6 +22,9 @@
#endif
#include <freerdp/codec/interleaved.h>
#include <freerdp/log.h>
#define TAG FREERDP_TAG("codec")
/*
RLE Compressed Bitmap Stream (RLE_BITMAP_STREAM)
@ -363,13 +366,13 @@ int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData
if (nWidth % 4)
{
fprintf(stderr, "interleaved_compress: width is not a multiple of 4\n");
WLog_ERR(TAG, "interleaved_compress: width is not a multiple of 4");
return -1;
}
if ((nWidth > 64) || (nHeight > 64))
{
fprintf(stderr, "interleaved_compress: width (%d) or height (%d) is greater than 64\n", nWidth, nHeight);
WLog_ERR(TAG, "interleaved_compress: width (%d) or height (%d) is greater than 64", nWidth, nHeight);
return -1;
}

View File

@ -2731,7 +2731,7 @@ BOOL rdp_read_bitmap_codecs_capability_set(wStream* s, UINT16 length, rdpSetting
if (Stream_GetPosition(s) != end)
{
fprintf(stderr, "error while reading codec properties: actual offset: %d expected offset: %d\n",
WLog_ERR(TAG, "error while reading codec properties: actual offset: %d expected offset: %d",
(int) Stream_GetPosition(s), end);
Stream_SetPosition(s, end);
}

View File

@ -603,7 +603,7 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
status = getaddrinfo(hostname, port_str, &hints, &result);
if (status) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(status));
WLog_ERR(TAG, "getaddrinfo: %s", gai_strerror(status));
return FALSE;
}
@ -627,7 +627,7 @@ BOOL tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout)
}
if (connect(tcp->sockfd, tmp->ai_addr, tmp->ai_addrlen) < 0) {
fprintf(stderr, "connect: %s\n", strerror(errno));
WLog_ERR(TAG, "connect: %s", strerror(errno));
freeaddrinfo(result);
return FALSE;
}

View File

@ -20,10 +20,13 @@
#include "config.h"
#endif
#include <freerdp/log.h>
#include <rdtk/rdtk.h>
#include <X11/Xlib.h>
#define TAG "rdtk.sample"
int main(int argc, char** argv)
{
GC gc;
@ -56,7 +59,7 @@ int main(int argc, char** argv)
if (!display)
{
fprintf(stderr, "Cannot open display\n");
WLog_ERR(TAG, "Cannot open display");
exit(1);
}

View File

@ -171,7 +171,7 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user,
if (pam_status != PAM_SUCCESS)
{
fprintf(stderr, "pam_start failure: %s\n", pam_strerror(info->handle, pam_status));
WLog_ERR(TAG, "pam_start failure: %s", pam_strerror(info->handle, pam_status));
free(info);
return -1;
}
@ -180,7 +180,7 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user,
if (pam_status != PAM_SUCCESS)
{
fprintf(stderr, "pam_authenticate failure: %s\n", pam_strerror(info->handle, pam_status));
WLog_ERR(TAG, "pam_authenticate failure: %s", pam_strerror(info->handle, pam_status));
free(info);
return -1;
}
@ -189,7 +189,7 @@ int x11_shadow_pam_authenticate(x11ShadowSubsystem* subsystem, const char* user,
if (pam_status != PAM_SUCCESS)
{
fprintf(stderr, "pam_acct_mgmt failure: %s\n", pam_strerror(info->handle, pam_status));
WLog_ERR(TAG, "pam_acct_mgmt failure: %s", pam_strerror(info->handle, pam_status));
free(info);
return -1;
}
@ -1136,7 +1136,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
if ((subsystem->depth != 24) && (subsystem->depth != 32))
{
fprintf(stderr, "x11_shadow_subsystem_init: unsupported X11 server color depth: %d\n", subsystem->depth);
WLog_ERR(TAG, "unsupported X11 server color depth: %d", subsystem->depth);
return -1;
}

View File

@ -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);

View File

@ -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)

View File

@ -16,6 +16,7 @@ set(${MODULE_PREFIX}_TESTS
TestListDictionary.c
TestCmdLine.c
TestWLog.c
TestWLogCallback.c
TestHashTable.c
TestBufferPool.c
TestStreamPool.c

View File

@ -0,0 +1,129 @@
#include <winpr/crt.h>
#include <winpr/tchar.h>
#include <winpr/path.h>
#include <winpr/wlog.h>
typedef struct
{
int level;
char *msg;
char *channel;
} test_t;
static const char *function = NULL;
static const char *channels[] =
{
"com.test.channelA",
"com.test.channelB"
};
static const test_t messages[] =
{
{WLOG_INFO, "this is a test", "com.test.channelA"},
{WLOG_INFO, "Just some info", "com.test.channelB"},
{WLOG_WARN, "this is a %dnd %s", "com.test.channelA"},
{WLOG_WARN, "we're warning a %dnd %s", "com.test.channelB"},
{WLOG_ERROR, "this is an error", "com.test.channelA"},
{WLOG_ERROR, "we've got an error", "com.test.channelB"},
{WLOG_TRACE, "this is a trace output", "com.test.channelA"},
{WLOG_TRACE, "leaving a trace behind", "com.test.channelB"}
};
static BOOL success = TRUE;
static int pos = 0;
static BOOL check(const wLogMessage *msg)
{
BOOL rc = TRUE;
if (!msg)
rc = FALSE;
else if (strcmp(msg->FileName, __FILE__))
rc = FALSE;
else if (strcmp(msg->FunctionName, function))
rc = FALSE;
else if (strcmp(msg->PrefixString, messages[pos].channel))
rc = FALSE;
else if (msg->Level != messages[pos].level)
rc = FALSE;
else if (strcmp(msg->FormatString, messages[pos].msg))
rc = FALSE;
pos++;
if (!rc)
{
fprintf(stderr, "Test failed!\n");
success = FALSE;
}
return rc;
}
void CallbackAppenderMessage(const wLogMessage *msg)
{
check(msg);
}
void CallbackAppenderData(const wLogMessage *msg)
{
fprintf(stdout, "%s\n", __FUNCTION__);
}
void CallbackAppenderImage(const wLogMessage *msg)
{
fprintf(stdout, "%s\n", __FUNCTION__);
}
void CallbackAppenderPackage(const wLogMessage *msg)
{
fprintf(stdout, "%s\n", __FUNCTION__);
}
int TestWLogCallback(int argc, char* argv[])
{
wLog* root;
wLog* logA;
wLog* logB;
wLogLayout* layout;
wLogAppender* appender;
function = __FUNCTION__;
WLog_Init();
root = WLog_GetRoot();
WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK);
appender = WLog_GetLogAppender(root);
WLog_CallbackAppender_SetCallbacks(root, (wLogCallbackAppender*) appender,
CallbackAppenderMessage, CallbackAppenderImage, CallbackAppenderPackage,
CallbackAppenderData);
layout = WLog_GetLogLayout(root);
WLog_Layout_SetPrefixFormat(root, layout, "%mn");
WLog_OpenAppender(root);
logA = WLog_Get(channels[0]);
logB = WLog_Get(channels[1]);
WLog_SetLogLevel(logA, WLOG_TRACE);
WLog_SetLogLevel(logB, WLOG_TRACE);
WLog_Print(logA, messages[0].level, messages[0].msg);
WLog_Print(logB, messages[1].level, messages[1].msg);
WLog_Print(logA, messages[2].level, messages[2].msg, 2, "test");
WLog_Print(logB, messages[3].level, messages[3].msg, 2, "time");
WLog_Print(logA, messages[4].level, messages[4].msg);
WLog_Print(logB, messages[5].level, messages[5].msg);
WLog_Print(logA, messages[6].level, messages[6].msg);
WLog_Print(logB, messages[7].level, messages[7].msg);
WLog_CloseAppender(root);
WLog_Uninit();
return success ? 0 : -1;
}

View File

@ -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);
}
}
}

View File

@ -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);

View File

@ -0,0 +1,163 @@
/**
* 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;
appender->data = data;
}
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_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->message = NULL;
CallbackAppender->image = NULL;
CallbackAppender->package = NULL;
CallbackAppender->data = NULL;
}
return CallbackAppender;
}
void WLog_CallbackAppender_Free(wLog* log, wLogCallbackAppender* appender)
{
if (appender)
{
free(appender);
}
}

View 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 */

View File

@ -31,8 +31,10 @@
#include "wtsapi_win32.h"
#include "wtsapi.h"
#include "../log.h"
#define WTSAPI_CHANNEL_MAGIC 0x44484356
#define TAG WINPR_TAG("wtsapi")
struct _WTSAPI_CHANNEL
{
@ -108,13 +110,13 @@ BOOL Win32_WTSVirtualChannelReadAsync(WTSAPI_CHANNEL* pChannel)
if (status)
{
fprintf(stderr, "Unexpected ReadFile status: %d numBytes: %d\n", status, numBytes);
WLog_ERR(TAG, "Unexpected ReadFile status: %d numBytes: %d", status, numBytes);
return FALSE; /* ReadFile should return FALSE and set ERROR_IO_PENDING */
}
if (GetLastError() != ERROR_IO_PENDING)
{
fprintf(stderr, "ReadFile: GetLastError() = %d\n", GetLastError());
WLog_ERR(TAG, "ReadFile: GetLastError() = %d", GetLastError());
return FALSE;
}