From bef63ad1ae8088ec5a88fcfd4a61447f22a1cd15 Mon Sep 17 00:00:00 2001 From: Mike McDonald Date: Thu, 12 Mar 2015 08:57:01 -0400 Subject: [PATCH] Added the ability to initialize a FileAppender from environment variables (WLOG_FILEAPPENDER_OUTPUT_FILE_PATH and WLOG_FILEAPPENDER_OUTPUT_FILE_NAME). --- winpr/libwinpr/utils/wlog/FileAppender.c | 32 +++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/winpr/libwinpr/utils/wlog/FileAppender.c b/winpr/libwinpr/utils/wlog/FileAppender.c index 90ce6cb56..42a7d255d 100644 --- a/winpr/libwinpr/utils/wlog/FileAppender.c +++ b/winpr/libwinpr/utils/wlog/FileAppender.c @@ -22,6 +22,7 @@ #endif #include +#include #include #include #include @@ -184,6 +185,9 @@ int WLog_FileAppender_WriteImageMessage(wLog* log, wLogFileAppender* appender, w wLogFileAppender* WLog_FileAppender_New(wLog* log) { + LPSTR env; + LPCSTR name; + DWORD nSize; wLogFileAppender* FileAppender; FileAppender = (wLogFileAppender*) malloc(sizeof(wLogFileAppender)); @@ -207,7 +211,33 @@ wLogFileAppender* WLog_FileAppender_New(wLog* log) FileAppender->FileName = NULL; FileAppender->FilePath = NULL; FileAppender->FullFileName = NULL; - } + + name = "WLOG_FILEAPPENDER_OUTPUT_FILE_PATH"; + nSize = GetEnvironmentVariableA(name, NULL, 0); + if (nSize) + { + env = (LPSTR) malloc(nSize); + if (env) + { + nSize = GetEnvironmentVariableA(name, env, nSize); + WLog_FileAppender_SetOutputFilePath(log, FileAppender, env); + free(env); + } + } + + name = "WLOG_FILEAPPENDER_OUTPUT_FILE_NAME"; + nSize = GetEnvironmentVariableA(name, NULL, 0); + if (nSize) + { + env = (LPSTR) malloc(nSize); + if (env) + { + nSize = GetEnvironmentVariableA(name, env, nSize); + WLog_FileAppender_SetOutputFileName(log, FileAppender, env); + free(env); + } + } + } return FileAppender; }