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; }
wLogFileAppender* WLog_FileAppender_New(wLog* log) { LPSTR env; LPCSTR name; DWORD nSize; wLogFileAppender* FileAppender; BOOL status; FileAppender = (wLogFileAppender*) calloc(1, sizeof(wLogFileAppender)); if (!FileAppender) return NULL; 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; name = "WLOG_FILEAPPENDER_OUTPUT_FILE_PATH"; nSize = GetEnvironmentVariableA(name, NULL, 0); if (nSize) { env = (LPSTR) malloc(nSize); if (!env) goto error_free; nSize = GetEnvironmentVariableA(name, env, nSize); status = WLog_FileAppender_SetOutputFilePath(log, FileAppender, env); free(env); if (!status) goto error_free; } name = "WLOG_FILEAPPENDER_OUTPUT_FILE_NAME"; nSize = GetEnvironmentVariableA(name, NULL, 0); if (nSize) { env = (LPSTR) malloc(nSize); if (!env) goto error_output_file_name; nSize = GetEnvironmentVariableA(name, env, nSize); status = WLog_FileAppender_SetOutputFileName(log, FileAppender, env); free(env); if (!status) goto error_output_file_name; } return FileAppender; error_output_file_name: free(FileAppender->FilePath); error_free: free(FileAppender); return NULL; }