int TestWLog(int argc, char* argv[]) { wLog* log; wLogLayout* layout; wLogAppender* appender; log = WLog_New("CONSOLE_LOG_TEST"); WLog_SetLogLevel(log, WLOG_INFO); WLog_SetLogAppenderType(log, WLOG_APPENDER_CONSOLE); appender = WLog_GetLogAppender(log); layout = WLog_GetLogLayout(log); WLog_Layout_SetPrefixFormat(log, layout, "[%lv:%mn] [%fl|%fn|%ln] - "); WLog_ConsoleAppender_SetOutputStream(log, (wLogConsoleAppender*) appender, WLOG_CONSOLE_STDERR); WLog_OpenAppender(log); WLog_Print(log, WLOG_INFO, "this is a test"); WLog_Print(log, WLOG_WARN, "this is a %dnd %s", 2, "test"); WLog_Print(log, WLOG_ERROR, "this is an error"); WLog_Print(log, WLOG_TRACE, "this is a trace output"); WLog_CloseAppender(log); WLog_Free(log); log = WLog_New("FILE_LOG_TEST"); WLog_SetLogLevel(log, WLOG_WARN); WLog_SetLogAppenderType(log, WLOG_APPENDER_FILE); appender = WLog_GetLogAppender(log); layout = WLog_GetLogLayout(log); WLog_Layout_SetPrefixFormat(log, layout, "[%lv:%mn] [%fl|%fn|%ln] - "); WLog_FileAppender_SetOutputFileName(log, (wLogFileAppender*) appender, "/tmp/wlog_test.log"); WLog_OpenAppender(log); WLog_Print(log, WLOG_INFO, "this is a test"); WLog_Print(log, WLOG_WARN, "this is a %dnd %s", 2, "test"); WLog_Print(log, WLOG_ERROR, "this is an error"); WLog_Print(log, WLOG_TRACE, "this is a trace output"); WLog_CloseAppender(log); WLog_Free(log); return 0; }
int TestWLogCallback(int argc, char* argv[]) { wLog* root; wLog* logA; wLog* logB; wLogLayout* layout; wLogAppender* appender; wLogCallbacks callbacks; function = __FUNCTION__; WLog_Init(); root = WLog_GetRoot(); WLog_SetLogAppenderType(root, WLOG_APPENDER_CALLBACK); appender = WLog_GetLogAppender(root); 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"); 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; }
wLog* WLog_GetRoot(void) { char* env; DWORD nSize; DWORD logAppenderType; if (!g_RootLog) { if (!(g_RootLog = WLog_New("", NULL))) return NULL; g_RootLog->IsRoot = TRUE; WLog_ParseFilters(); logAppenderType = WLOG_APPENDER_CONSOLE; nSize = GetEnvironmentVariableA("WLOG_APPENDER", NULL, 0); if (nSize) { env = (LPSTR) malloc(nSize); if (!env) goto fail; if (!GetEnvironmentVariableA("WLOG_APPENDER", env, nSize)) { fprintf(stderr, "WLOG_APPENDER environment variable modified in my back"); free(env); goto fail; } if (_stricmp(env, "CONSOLE") == 0) logAppenderType = WLOG_APPENDER_CONSOLE; else if (_stricmp(env, "FILE") == 0) logAppenderType = WLOG_APPENDER_FILE; else if (_stricmp(env, "BINARY") == 0) logAppenderType = WLOG_APPENDER_BINARY; #ifdef HAVE_SYSLOG_H else if (_stricmp(env, "SYSLOG") == 0) logAppenderType = WLOG_APPENDER_SYSLOG; #endif /* HAVE_SYSLOG_H */ #ifdef HAVE_JOURNALD_H else if (_stricmp(env, "JOURNALD") == 0) logAppenderType = WLOG_APPENDER_JOURNALD; #endif else if (_stricmp(env, "UDP") == 0) logAppenderType = WLOG_APPENDER_UDP; free(env); } if (!WLog_SetLogAppenderType(g_RootLog, logAppenderType)) goto fail; } return g_RootLog; fail: free(g_RootLog); g_RootLog = NULL; return NULL; }
int TestWLog(int argc, char* argv[]) { wLog* root; wLog* logA; wLog* logB; wLogLayout* layout; wLogAppender* appender; char* tmp_path; char* wlog_file; if (!(tmp_path = GetKnownPath(KNOWN_PATH_TEMP))) { fprintf(stderr, "Failed to get temporary directory!\n"); return -1; } WLog_Init(); root = WLog_GetRoot(); WLog_SetLogAppenderType(root, WLOG_APPENDER_BINARY); appender = WLog_GetLogAppender(root); if(!WLog_ConfigureAppender(appender, "outputfilename", "test_w.log")) return 1; if(!WLog_ConfigureAppender(appender, "outputfilepath", tmp_path)) return 1; layout = WLog_GetLogLayout(root); WLog_Layout_SetPrefixFormat(root, layout, "[%lv:%mn] [%fl|%fn|%ln] - "); WLog_OpenAppender(root); logA = WLog_Get("com.test.ChannelA"); logB = WLog_Get("com.test.ChannelB"); WLog_SetLogLevel(logA, WLOG_INFO); WLog_SetLogLevel(logB, WLOG_ERROR); WLog_Print(logA, WLOG_INFO, "this is a test"); WLog_Print(logA, WLOG_WARN, "this is a %dnd %s", 2, "test"); WLog_Print(logA, WLOG_ERROR, "this is an error"); WLog_Print(logA, WLOG_TRACE, "this is a trace output"); WLog_Print(logB, WLOG_INFO, "just some info"); WLog_Print(logB, WLOG_WARN, "we're warning a %dnd %s", 2, "time"); WLog_Print(logB, WLOG_ERROR, "we've got an error"); WLog_Print(logB, WLOG_TRACE, "leaving a trace behind"); WLog_CloseAppender(root); WLog_Uninit(); if ((wlog_file = GetCombinedPath(tmp_path, "test_w.log"))) { DeleteFileA(wlog_file); free(wlog_file); } return 0; }