diff --git a/src/Win32_Interop/Win32_EventLog.cpp b/src/Win32_Interop/Win32_EventLog.cpp index aad15d91..89c93f90 100644 --- a/src/Win32_Interop/Win32_EventLog.cpp +++ b/src/Win32_Interop/Win32_EventLog.cpp @@ -32,129 +32,190 @@ using namespace std; #include "Win32_SmartHandle.h" #include "EventLog.h" -void RedisEventLog::UninstallEventLogSource() { - SmartRegistryHandle appKey; - if (ERROR_SUCCESS == RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogApplicitonPath.c_str(), appKey)) { - SmartRegistryHandle eventLogNameKey; - if (ERROR_SUCCESS == RegOpenKeyA(appKey, eventLogName.c_str(), eventLogNameKey)) { - if (ERROR_SUCCESS != RegDeleteKeyA(appKey, eventLogName.c_str())) { - throw std::system_error(GetLastError(), system_category(), "RegDeleteKeyA failed"); - } - } - } +static bool eventLogEnabled = true; +static string eventLogIdentity = "redis"; - SmartRegistryHandle eventLogKey; - if (ERROR_SUCCESS == RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogPath.c_str(), eventLogKey)) { - SmartRegistryHandle eventServiceKey; - if (ERROR_SUCCESS == RegOpenKeyA(eventLogKey, cRedis.c_str(), eventServiceKey)) { - SmartRegistryHandle eventServiceSubKey; - if (ERROR_SUCCESS == RegOpenKeyA(eventServiceKey, cRedisServer.c_str(), eventServiceSubKey)) { - if (ERROR_SUCCESS != RegDeleteKeyA(eventServiceKey, cRedisServer.c_str())) { - throw std::system_error(GetLastError(), system_category(), "RegDeleteKeyA failed"); - } - if (ERROR_SUCCESS != RegDeleteKeyA(eventLogKey, cRedis.c_str())) { - throw std::system_error(GetLastError(), system_category(), "RegDeleteKeyA failed"); - } - } - } - } +void RedisEventLog::SetEventLogIdentity(const char* identity) { + eventLogIdentity = string(identity); +} + +void RedisEventLog::UninstallEventLogSource() { + SmartRegistryHandle appKey; + if (ERROR_SUCCESS == RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogApplicitonPath.c_str(), appKey)) { + SmartRegistryHandle eventLogNameKey; + if (ERROR_SUCCESS == RegOpenKeyA(appKey, eventLogName.c_str(), eventLogNameKey)) { + if (ERROR_SUCCESS != RegDeleteKeyA(appKey, eventLogName.c_str())) { + throw std::system_error(GetLastError(), system_category(), "RegDeleteKeyA failed"); + } + } + } + + SmartRegistryHandle eventLogKey; + if (ERROR_SUCCESS == RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogPath.c_str(), eventLogKey)) { + SmartRegistryHandle eventServiceKey; + if (ERROR_SUCCESS == RegOpenKeyA(eventLogKey, cRedis.c_str(), eventServiceKey)) { + SmartRegistryHandle eventServiceSubKey; + if (ERROR_SUCCESS == RegOpenKeyA(eventServiceKey, cRedisServer.c_str(), eventServiceSubKey)) { + if (ERROR_SUCCESS != RegDeleteKeyA(eventServiceKey, cRedisServer.c_str())) { + throw std::system_error(GetLastError(), system_category(), "RegDeleteKeyA failed"); + } + if (ERROR_SUCCESS != RegDeleteKeyA(eventLogKey, cRedis.c_str())) { + throw std::system_error(GetLastError(), system_category(), "RegDeleteKeyA failed"); + } + } + } + } } // sets up the registry keys required for the EventViewer message filter void RedisEventLog::InstallEventLogSource(string appPath) { - SmartRegistryHandle eventLogKey; - if (ERROR_SUCCESS != RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogPath.c_str(), eventLogKey)) { - throw std::system_error(GetLastError(), system_category(), "RegOpenKey failed"); - } - SmartRegistryHandle redis1; - if (ERROR_SUCCESS != RegOpenKeyA(eventLogKey, cRedis.c_str(), redis1)) { - if (ERROR_SUCCESS != RegCreateKeyA(eventLogKey, cRedis.c_str(), redis1)) { - throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); - } - } - SmartRegistryHandle redisserver; - if (ERROR_SUCCESS != RegOpenKeyA(redis1, cRedisServer.c_str(), redisserver)) { - if (ERROR_SUCCESS != RegCreateKeyA(redis1, cRedisServer.c_str(), redisserver)) { - throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); - } - } - DWORD value = 0; - DWORD type = REG_DWORD; - DWORD size = sizeof(DWORD); - if (ERROR_SUCCESS != RegQueryValueExA(redisserver, cTypesSupported.c_str(), 0, &type, NULL, &size)) { - if (ERROR_SUCCESS != RegSetValueExA(redisserver, cTypesSupported.c_str(), 0, REG_DWORD, (const BYTE*)&value, sizeof(DWORD))) { - throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); - } - } - type = REG_SZ; - size = 0; - if (ERROR_SUCCESS != RegQueryValueExA(redisserver, cEventMessageFile.c_str(), 0, &type, NULL, &size)) { - if (ERROR_SUCCESS != RegSetValueExA(redisserver, cEventMessageFile.c_str(), 0, REG_SZ, (BYTE*)appPath.c_str(), (DWORD)appPath.length())) { - throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); - } - } + SmartRegistryHandle eventLogKey; + if (ERROR_SUCCESS != RegOpenKeyA(HKEY_LOCAL_MACHINE, cEventLogPath.c_str(), eventLogKey)) { + throw std::system_error(GetLastError(), system_category(), "RegOpenKey failed"); + } + SmartRegistryHandle redis1; + if (ERROR_SUCCESS != RegOpenKeyA(eventLogKey, cRedis.c_str(), redis1)) { + if (ERROR_SUCCESS != RegCreateKeyA(eventLogKey, cRedis.c_str(), redis1)) { + throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); + } + } + SmartRegistryHandle redisserver; + if (ERROR_SUCCESS != RegOpenKeyA(redis1, cRedisServer.c_str(), redisserver)) { + if (ERROR_SUCCESS != RegCreateKeyA(redis1, cRedisServer.c_str(), redisserver)) { + throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); + } + } + DWORD value = 0; + DWORD type = REG_DWORD; + DWORD size = sizeof(DWORD); + if (ERROR_SUCCESS != RegQueryValueExA(redisserver, cTypesSupported.c_str(), 0, &type, NULL, &size)) { + if (ERROR_SUCCESS != RegSetValueExA(redisserver, cTypesSupported.c_str(), 0, REG_DWORD, (const BYTE*) &value, sizeof(DWORD))) { + throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); + } + } + type = REG_SZ; + size = 0; + if (ERROR_SUCCESS != RegQueryValueExA(redisserver, cEventMessageFile.c_str(), 0, &type, NULL, &size)) { + if (ERROR_SUCCESS != RegSetValueExA(redisserver, cEventMessageFile.c_str(), 0, REG_SZ, (BYTE*) appPath.c_str(), (DWORD) appPath.length())) { + throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); + } + } - SmartRegistryHandle application; - if (ERROR_SUCCESS != RegOpenKeyA(eventLogKey, cApplication.c_str() , application)) { - throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); - } - SmartRegistryHandle redis2; - if (ERROR_SUCCESS != RegOpenKeyA(application, cRedis.c_str(), redis2)) { - if (ERROR_SUCCESS != RegCreateKeyA(application, cRedis.c_str(), redis2)) { - throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); - } - } - type = REG_DWORD; - size = 0; - if (ERROR_SUCCESS != RegQueryValueExA(redis2, cTypesSupported.c_str(), 0, &type, NULL, &size)) { - if (ERROR_SUCCESS != RegSetValueExA(redis2, cTypesSupported.c_str(), 0, REG_DWORD, (const BYTE*)&value, sizeof(DWORD))) { - throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); - } - } - if (ERROR_SUCCESS != RegQueryValueExA(redis2, cEventMessageFile.c_str(), 0, &type, NULL, &size)) { - if (ERROR_SUCCESS != RegSetValueExA(redis2, cEventMessageFile.c_str(), 0, REG_SZ, (BYTE*)appPath.c_str(), (DWORD)appPath.length())) { - throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); - } - } + SmartRegistryHandle application; + if (ERROR_SUCCESS != RegOpenKeyA(eventLogKey, cApplication.c_str(), application)) { + throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); + } + SmartRegistryHandle redis2; + if (ERROR_SUCCESS != RegOpenKeyA(application, cRedis.c_str(), redis2)) { + if (ERROR_SUCCESS != RegCreateKeyA(application, cRedis.c_str(), redis2)) { + throw std::system_error(GetLastError(), system_category(), "RegCreateKeyA failed"); + } + } + type = REG_DWORD; + size = 0; + if (ERROR_SUCCESS != RegQueryValueExA(redis2, cTypesSupported.c_str(), 0, &type, NULL, &size)) { + if (ERROR_SUCCESS != RegSetValueExA(redis2, cTypesSupported.c_str(), 0, REG_DWORD, (const BYTE*) &value, sizeof(DWORD))) { + throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); + } + } + if (ERROR_SUCCESS != RegQueryValueExA(redis2, cEventMessageFile.c_str(), 0, &type, NULL, &size)) { + if (ERROR_SUCCESS != RegSetValueExA(redis2, cEventMessageFile.c_str(), 0, REG_SZ, (BYTE*) appPath.c_str(), (DWORD) appPath.length())) { + throw std::system_error(GetLastError(), system_category(), "RegSetValueExA failed"); + } + } } -void RedisEventLog::LogMessageToEventLog(LPCSTR msg, const WORD type) { - DWORD eventID; - switch (type) { - case EVENTLOG_ERROR_TYPE: - eventID = MSG_ERROR_1; - break; - case EVENTLOG_WARNING_TYPE: - eventID = MSG_WARNING_1; - break; - case EVENTLOG_INFORMATION_TYPE: - eventID = MSG_INFO_1; - break; - default: - std::cerr << "Unrecognized type: " << type << "\n"; - eventID = MSG_INFO_1; - break; - } +void RedisEventLog::LogMessage(LPCSTR msg, const WORD type) { + DWORD eventID; + switch (type) { + case EVENTLOG_ERROR_TYPE: + eventID = MSG_ERROR_1; + break; + case EVENTLOG_WARNING_TYPE: + eventID = MSG_WARNING_1; + break; + case EVENTLOG_INFORMATION_TYPE: + eventID = MSG_INFO_1; + break; + default: + std::cerr << "Unrecognized type: " << type << "\n"; + eventID = MSG_INFO_1; + break; + } - HANDLE hEventLog = RegisterEventSourceA(0, this->eventLogName.c_str()); + HANDLE hEventLog = RegisterEventSourceA(0, this->eventLogName.c_str()); - if (0 == hEventLog) { - std::cerr << "Failed open source '" << this->eventLogName << "': " << GetLastError() << endl; - } else { - if (FALSE == ReportEventA( hEventLog, type, 0, eventID, 0, 1, 0, &msg, 0)) { - std::cerr << "Failed to write message: " << GetLastError() << endl; - } + if (0 == hEventLog) { + std::cerr << "Failed open source '" << this->eventLogName << "': " << GetLastError() << endl; + } else { + if (FALSE == ReportEventA(hEventLog, type, 0, eventID, 0, 1, 0, &msg, 0)) { + std::cerr << "Failed to write message: " << GetLastError() << endl; + } - DeregisterEventSource(hEventLog); - } + DeregisterEventSource(hEventLog); + } } -extern "C" void WriteEventLog(const char* sysLogInstance, const char* msg) { - try { - stringstream ss; - ss << "syslog-ident = " << sysLogInstance << endl; +void RedisEventLog::LogError(string msg) { + try { + if (eventLogEnabled == true) { + stringstream ss; + ss << "syslog-ident = " << eventLogIdentity << endl; + ss << msg; + RedisEventLog().LogMessage(ss.str().c_str(), EVENTLOG_ERROR_TYPE); + } + } + catch (...) { + } +} + +string RedisEventLog::GetEventLogIdentity() { + return eventLogIdentity; +} + +void RedisEventLog::EnableEventLog(bool enabled) { + eventLogEnabled = enabled; +} + +bool RedisEventLog::IsEventLogEnabled() { + return eventLogEnabled; +} + +extern "C" void setSyslogEnabled(int enabled) { + try { + if (enabled == 1) { + RedisEventLog().EnableEventLog(true); + } else { + RedisEventLog().EnableEventLog(false); + } + } + catch (...) {} +} + +extern "C" void setSyslogIdent(char* identity) { + try { + RedisEventLog().SetEventLogIdentity(identity); + } + catch (...) {} +} + +extern "C" void WriteEventLog(const char* msg) { + try { + stringstream ss; + ss << "syslog-ident = " << RedisEventLog().GetEventLogIdentity() << endl; ss << msg; - RedisEventLog().LogMessageToEventLog(ss.str().c_str(),EVENTLOG_INFORMATION_TYPE); - } catch (...) { - } + RedisEventLog().LogMessage(ss.str().c_str(), EVENTLOG_INFORMATION_TYPE); + } + catch (...) {} +} + +extern "C" int IsEventLogEnabled() { + try { + if (RedisEventLog().IsEventLogEnabled() == true) { + return 1; + } else { + return 0; + } + } + catch (...) {} } diff --git a/src/Win32_Interop/Win32_EventLog.h b/src/Win32_Interop/Win32_EventLog.h index 61335e23..5cec2292 100644 --- a/src/Win32_Interop/Win32_EventLog.h +++ b/src/Win32_Interop/Win32_EventLog.h @@ -28,29 +28,38 @@ using namespace std; typedef class RedisEventLog { public: - ~RedisEventLog() {} + ~RedisEventLog() {} - void InstallEventLogSource(string appPath); - void UninstallEventLogSource(); + void InstallEventLogSource(string appPath); + void UninstallEventLogSource(); - void LogMessageToEventLog(LPCSTR msg, const WORD type); + void SetEventLogIdentity(const char* identity); + + void LogMessage(LPCSTR msg, const WORD type); + void LogError(string msg); + + string GetEventLogIdentity(); + void EnableEventLog(bool enabled); + bool IsEventLogEnabled(); private: - - const string eventLogName = "redis"; - const string cEventLogPath = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\"; - const string cEventLogApplicitonPath = cEventLogPath + "Application\\"; - const string cRedis = "redis"; - const string cEventMessageFile = "EventMessageFile"; - const string cRedisServer = "redis-server"; - const string cTypesSupported = "TypesSupported"; - const string cApplication = "Application"; + const string eventLogName = "redis"; + const string cEventLogPath = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\"; + const string cEventLogApplicitonPath = cEventLogPath + "Application\\"; + const string cRedis = "redis"; + const string cEventMessageFile = "EventMessageFile"; + const string cRedisServer = "redis-server"; + const string cTypesSupported = "TypesSupported"; + const string cApplication = "Application"; } RedisEventLog; extern "C" { #endif - void WriteEventLog(const char* sysLogInstance, const char* msg); + void setSyslogEnabled(int enabled); + void setSyslogIdent(char* identity); + int IsEventLogEnabled(); + void WriteEventLog(const char* msg); #ifdef __cplusplus } diff --git a/src/Win32_Interop/Win32_QFork.cpp b/src/Win32_Interop/Win32_QFork.cpp index f285e5ab..fa015d01 100644 --- a/src/Win32_Interop/Win32_QFork.cpp +++ b/src/Win32_Interop/Win32_QFork.cpp @@ -45,6 +45,7 @@ #include "Win32_RedisLog.h" #include "Win32_StackTrace.h" #include "Win32_ThreadControl.h" +#include "Win32_EventLog.h" #include #include @@ -216,6 +217,7 @@ bool ReportSpecialSystemErrors(int error) { "\n" "Redis can not continue. Exiting." ); + RedisEventLog().LogError("Failed to allocate the memory mapped file."); return true; } @@ -239,6 +241,7 @@ bool ReportSpecialSystemErrors(int error) { "\n" "Redis can not continue. Exiting." ); + RedisEventLog().LogError("Disk full error while allocating the memory mapped file."); return true; } @@ -333,11 +336,13 @@ BOOL QForkChildInit(HANDLE QForkConrolMemoryMapHandle, DWORD ParentProcessID) { } catch(std::system_error syserr) { if (ReportSpecialSystemErrors(syserr.code().value()) == false) { - ::redisLog(REDIS_WARNING, "QForkChildInit: system error caught. error code=0x%08x, message=%s\n", syserr.code().value(), syserr.what()); + RedisEventLog().LogError("QForkChildInit: system error. " + string(syserr.what())); + ::redisLog(REDIS_WARNING, "QForkChildInit: system error. ErrCode: 0x%08x, ErrMsg: %s\n", syserr.code().value(), syserr.what()); } } catch(std::runtime_error runerr) { - ::redisLog(REDIS_WARNING, "QForkChildInit: runtime error caught. message=%s\n", runerr.what()); + RedisEventLog().LogError("QForkChildInit: runtime error. " + string(runerr.what())); + ::redisLog(REDIS_WARNING, "QForkChildInit: runtime error. ErrMsg: %s\n", runerr.what()); } if (g_pQForkControl != NULL) { @@ -495,7 +500,7 @@ BOOL QForkParentInit(__int64 maxheapBytes) { throw std::system_error( GetLastError(), system_category(), - "CreateFileW failed."); + "CreateFile failed"); } SIZE_T mmSize = g_pQForkControl->availableBlocksInHeap * cAllocationGranularity; @@ -580,14 +585,17 @@ BOOL QForkParentInit(__int64 maxheapBytes) { } catch(std::system_error syserr) { if (ReportSpecialSystemErrors(syserr.code().value()) == false) { - ::redisLog(REDIS_WARNING, "QForkParentInit: system error caught. error code=0x%08x, message=%s\n", syserr.code().value(), syserr.what()); + RedisEventLog().LogError("QForkParentInit: system error. " + string(syserr.what())); + ::redisLog(REDIS_WARNING, "QForkParentInit: system error. ErrCode: 0x%08x, ErrMsg: %s\n", syserr.code().value(), syserr.what()); } } catch(std::runtime_error runerr) { - ::redisLog(REDIS_WARNING, "QForkParentInit: runtime error caught. message=%s\n", runerr.what()); + RedisEventLog().LogError("QForkParentInit: runtime error. " + string(runerr.what())); + ::redisLog(REDIS_WARNING, "QForkParentInit: runtime error. ErrMsg: %s\n", runerr.what()); } - catch(...) { - ::redisLog(REDIS_WARNING, "QForkParentInit: other exception caught.\n"); + catch(std::exception ex) { + RedisEventLog().LogError("QForkParentInit: an exception occurred. " + string(ex.what())); + ::redisLog(REDIS_WARNING, "QForkParentInit: an exception occurred. ErrMsg: %s\n", ex.what()); } return FALSE; } @@ -636,8 +644,11 @@ LONG CALLBACK VectoredHeapMapper(PEXCEPTION_POINTERS info) { ::redisLog(REDIS_WARNING, "The system paging file is too small for this operation to complete."); ::redisLog(REDIS_WARNING, "See https://github.com/MSOpenTech/redis/wiki/Memory-Configuration"); ::redisLog(REDIS_WARNING, "for more information on configuring the system paging file for Redis."); + + RedisEventLog().LogError("QForkParentInit: an exception occurred. The system paging file is too small for this operation to complete."); } ::redisLog(REDIS_WARNING, "\n=== REDIS BUG REPORT END. Make sure to include from START to END. ===\n\n"); + // Call exit to avoid executing the Unhandled Exceptiont Handler since we don't need a call stack exit(1); } @@ -1268,9 +1279,9 @@ void SetupLogging() { string syslogIdent = (g_argMap.find(cSyslogIdent) != g_argMap.end() ? g_argMap[cSyslogIdent].at(0).at(0) : cDefaultSyslogIdent); string logFileName = (g_argMap.find(cLogfile) != g_argMap.end() ? g_argMap[cLogfile].at(0).at(0) : cDefaultLogfile); - setSyslogEnabled(syslogEnabled); + RedisEventLog().EnableEventLog(syslogEnabled); if (syslogEnabled) { - setSyslogIdent(syslogIdent.c_str()); + RedisEventLog().SetEventLogIdentity(syslogIdent.c_str()); } else { setLogFile(logFileName.c_str()); } @@ -1298,15 +1309,24 @@ extern "C" StackTraceInit(); InitThreadControl(); } catch (system_error syserr) { + string errMsg = string("System error during startup: ") + syserr.what(); + RedisEventLog().LogError(errMsg); + cout << errMsg << endl; exit(-1); } catch (runtime_error runerr) { - cout << runerr.what() << endl; + string errMsg = string("System error during startup: ") + runerr.what(); + RedisEventLog().LogError(errMsg); + cout << errMsg << endl; exit(-1); } catch (invalid_argument &iaerr) { - cout << iaerr.what() << endl; + string errMsg = string("Invalid argument during startup: ") + iaerr.what(); + RedisEventLog().LogError(errMsg); + cout << errMsg << endl; exit(-1); } catch (exception othererr) { - cout << othererr.what() << endl; + string errMsg = string("An exception occurred during startup: ") + othererr.what(); + RedisEventLog().LogError(errMsg); + cout << errMsg << endl; exit(-1); } @@ -1364,11 +1384,14 @@ extern "C" return redis_main(argc, argv); } } catch (std::system_error syserr) { - ::redisLog(REDIS_WARNING, "main: system error caught. error code=0x%08x, message=%s\n", syserr.code().value(), syserr.what()); + RedisEventLog().LogError(string("Main: system error. ") + syserr.what()); + ::redisLog(REDIS_WARNING, "Main: system error. ErrCode: 0x%08x, ErrMsg: %s\n", syserr.code().value(), syserr.what()); } catch (std::runtime_error runerr) { - ::redisLog(REDIS_WARNING, "main: runtime error caught. message=%s\n", runerr.what()); - } catch (...) { - ::redisLog(REDIS_WARNING, "main: other exception caught.\n"); + RedisEventLog().LogError(string("Main: runtime error. ") + runerr.what()); + ::redisLog(REDIS_WARNING, "Main: runtime error. ErrMsg: %s\n", runerr.what()); + } catch (std::exception ex) { + RedisEventLog().LogError(string("Main: an exception occurred. ") + ex.what()); + ::redisLog(REDIS_WARNING, "Main: an exception occurred. ErrMsg: %s\n", ex.what()); } } } diff --git a/src/Win32_Interop/Win32_RedisLog.c b/src/Win32_Interop/Win32_RedisLog.c index 9778cf6a..9ad1cea9 100644 --- a/src/Win32_Interop/Win32_RedisLog.c +++ b/src/Win32_Interop/Win32_RedisLog.c @@ -36,19 +36,9 @@ static const char ellipsis[] = "[...]"; static const char ellipsisWithNewLine[] = "[...]\n"; static int verbosity = REDIS_WARNING; -static int syslogEnabled = 0; -static char syslogIdent[MAX_PATH]; static HANDLE hLogFile = INVALID_HANDLE_VALUE; static int isStdout = 0; -void setSyslogEnabled(int flag) { - syslogEnabled = flag; -} - -void setSyslogIdent(const char* ident) { - strcpy_s(syslogIdent, MAX_PATH, ident); -} - void setLogVerbosityLevel(int level) { verbosity = level; @@ -163,7 +153,9 @@ void redisLogRaw(int level, const char *msg) { FlushFileBuffers(hLogFile); #endif - if (syslogEnabled) WriteEventLog(syslogIdent, msg); + if (IsEventLogEnabled() == 1) { + WriteEventLog(msg); + } } /* Like redisLogRaw() but with printf-alike support. This is the function that diff --git a/src/Win32_Interop/Win32_RedisLog.h b/src/Win32_Interop/Win32_RedisLog.h index 38f59eb2..afedec8e 100644 --- a/src/Win32_Interop/Win32_RedisLog.h +++ b/src/Win32_Interop/Win32_RedisLog.h @@ -39,8 +39,6 @@ extern "C" { #endif -void setSyslogEnabled(int flag); -void setSyslogIdent(const char* ident); void setLogVerbosityLevel(int level); void setLogFile (const char* logFileName); void redisLogRaw(int level, const char *msg); diff --git a/src/config.c b/src/config.c index 7466e39e..52bc7f6f 100644 --- a/src/config.c +++ b/src/config.c @@ -29,7 +29,8 @@ */ #ifdef _WIN32 -#include "win32_Interop/win32_types.h" +#include "Win32_Interop/win32_types.h" +#include "Win32_Interop/Win32_EventLog.h" #endif #include "redis.h" @@ -237,9 +238,7 @@ void loadServerConfigFromString(char *config) { setSyslogIdent(server.syslog_ident); #endif } else if (!strcasecmp(argv[0], "syslog-facility") && argc == 2) { -#ifdef _WIN32 - // Skip error - just ignore syslog-facility -#else +#ifndef _WIN32 // On Windows ignore syslog-facility int i; for (i = 0; validSyslogFacilities[i].name; i++) {