1
0
Fork 0

Forward ERROR & FATAL logmessages into the windows eventlog. Else debugging services in the early starting phase is next to impossible.

This commit is contained in:
Willi Goesgens 2015-03-18 19:13:35 +01:00
parent 023d880b5f
commit 6b22b1e31c
3 changed files with 78 additions and 1 deletions

View File

@ -1317,14 +1317,24 @@ void TRI_Log (char const* func,
TRI_tid_t threadId;
va_list ap;
va_start(ap, fmt);
#ifdef _WIN32
#include "win-utils.h"
if ((level == TRI_LOG_LEVEL_FATAL) || (level == TRI_LOG_LEVEL_ERROR)) {
va_list wva;
va_copy(wva, ap);
TRI_LogWindowsEventlog(func, file, line, fmt, ap);
va_end(wva);
}
#endif
if (! LoggingActive) {
return;
va_end(ap);
}
processId = TRI_CurrentProcessId();
threadId = TRI_CurrentThreadId();
va_start(ap, fmt);
LogThread(func, file, line, level, severity, processId, threadId, fmt, ap);
va_end(ap);
}

View File

@ -461,6 +461,60 @@ int TRI_MapSystemError (DWORD error) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief logs a message to the windows event log.
/// we rather are keen on logging something at all then on being able to work
/// with fancy dynamic buffers; thus we work with a static buffer.
/// the arango internal logging will handle that usually.
////////////////////////////////////////////////////////////////////////////////
// No clue why there is no header for these...
#define MSG_INVALID_COMMAND ((DWORD)0xC0020100L)
#define UI_CATEGORY ((WORD)0x00000003L)
void TRI_LogWindowsEventlog (char const* func,
char const* file,
int line,
char const* fmt,
va_list ap) {
char buf[1024];
char linebuf[32];
LPCSTR logBuffers [] = {
buf,
file,
func,
linebuf,
NULL
};
HANDLE hEventLog = NULL;
hEventLog = RegisterEventSource(NULL, "ArangoDB");
if (NULL == hEventLog) {
// well, fail then.
return;
}
snprintf(linebuf, sizeof(linebuf), "%d", line);
DWORD len = _vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
buf[sizeof(buf) - 1] = '\0';
// Try to get messages through to windows syslog...
if (!ReportEvent(hEventLog,
EVENTLOG_ERROR_TYPE,
UI_CATEGORY,
MSG_INVALID_COMMAND,
NULL, 4, 0, (LPCSTR*) logBuffers,
NULL)) {
// well, fail then...
}
DeregisterEventSource(hEventLog);
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -106,6 +106,19 @@ void TRI_FixIcuDataEnv ();
int TRI_MapSystemError (DWORD);
////////////////////////////////////////////////////////////////////////////////
/// @brief logs a message to the windows event log.
/// we rather are keen on logging something at all then on being able to work
/// with fancy dynamic buffers; thus we work with a static buffer.
/// the arango internal logging will handle that usually.
////////////////////////////////////////////////////////////////////////////////
void TRI_LogWindowsEventlog (char const* func,
char const* file,
int line,
char const* fmt,
va_list ap);
#endif
// -----------------------------------------------------------------------------