From a7c59c60f30f7cb6a918935ef915a83629cfa178 Mon Sep 17 00:00:00 2001 From: jsteemann Date: Wed, 6 Jul 2016 12:30:02 +0200 Subject: [PATCH] don't log client tool errors to Windows event log --- lib/Basics/ArangoGlobalContext.cpp | 12 +++++++++++- lib/Basics/ArangoGlobalContext.h | 2 ++ lib/Logger/Logger.cpp | 5 ++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Basics/ArangoGlobalContext.cpp b/lib/Basics/ArangoGlobalContext.cpp index ce6bb6f8d5..6d1fee8035 100644 --- a/lib/Basics/ArangoGlobalContext.cpp +++ b/lib/Basics/ArangoGlobalContext.cpp @@ -108,7 +108,17 @@ LONG CALLBACK unhandledExceptionHandler(EXCEPTION_POINTERS* e) { ArangoGlobalContext* ArangoGlobalContext::CONTEXT = nullptr; ArangoGlobalContext::ArangoGlobalContext(int argc, char* argv[]) - : _binaryName(TRI_BinaryName(argv[0])), _ret(EXIT_FAILURE) { + : _binaryName(TRI_BinaryName(argv[0])), _ret(EXIT_FAILURE), _useEventLog(true) { + + static char const* serverName = "arangod"; + if (_binaryName.size() < strlen(serverName) || + _binaryName.substr(_binaryName.size() - strlen(serverName)) != serverName) { + // turn off event-logging for all binaries except arangod + // the reason is that all other tools are client tools that will directly + // print all errors so the user can handle them + _useEventLog = false; + } + ADB_WindowsEntryFunction(); #ifdef _WIN32 diff --git a/lib/Basics/ArangoGlobalContext.h b/lib/Basics/ArangoGlobalContext.h index 64eccce93e..1f4da5113d 100644 --- a/lib/Basics/ArangoGlobalContext.h +++ b/lib/Basics/ArangoGlobalContext.h @@ -43,10 +43,12 @@ class ArangoGlobalContext { void unmaskStandardSignals(); void runStartupChecks(); void tempPathAvailable(); + bool useEventLog() { return _useEventLog; } private: std::string _binaryName; int _ret; + bool _useEventLog; }; } diff --git a/lib/Logger/Logger.cpp b/lib/Logger/Logger.cpp index 7769723285..0d0eae5621 100644 --- a/lib/Logger/Logger.cpp +++ b/lib/Logger/Logger.cpp @@ -24,6 +24,7 @@ #include "Logger.h" +#include "Basics/ArangoGlobalContext.h" #include "Basics/ConditionLocker.h" #include "Basics/Exceptions.h" #include "Basics/MutexLocker.h" @@ -204,7 +205,9 @@ void Logger::log(char const* function, char const* file, long int line, std::string const& message) { #ifdef _WIN32 if (level == LogLevel::FATAL || level == LogLevel::ERR) { - TRI_LogWindowsEventlog(function, file, line, message); + if (ArangoGlobalContext::CONTEXT->useEventLog()) { + TRI_LogWindowsEventlog(function, file, line, message); + } } #endif