diff --git a/CHANGELOG b/CHANGELOG index 85c0cd3fb2..ee4de641e4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,11 @@ v2.3.0 (XXXX-XX-XX) ------------------- +* issue #1042: set time zone in log output + + the command-line option `--log.use-local-time` was added to print dates and times in + the server-local timezone instead of UTC + * command-line options that require a boolean value now validate the value given on the command-line diff --git a/Documentation/Books/Users/ConfigureArango/Logging.mdpp b/Documentation/Books/Users/ConfigureArango/Logging.mdpp index a024b98911..daeb37ab0c 100644 --- a/Documentation/Books/Users/ConfigureArango/Logging.mdpp +++ b/Documentation/Books/Users/ConfigureArango/Logging.mdpp @@ -29,6 +29,10 @@ statistics about executed requests and timings about computation steps. @startDocuBlock logLevel +!SUBSECTION Local Time + +@startDocuBlock logLocalTime + !SUBSECTION Line number @startDocuBlock logLineNumber @@ -61,4 +65,4 @@ statistics about executed requests and timings about computation steps. !SUBSECTION Histname -@startDocuBlock logHostname \ No newline at end of file +@startDocuBlock logHostname diff --git a/arangosh/ArangoShell/ArangoClient.cpp b/arangosh/ArangoShell/ArangoClient.cpp index 6808b3c830..56f5e30080 100644 --- a/arangosh/ArangoShell/ArangoClient.cpp +++ b/arangosh/ArangoShell/ArangoClient.cpp @@ -127,6 +127,7 @@ ArangoClient::ArangoClient () : _configFile(), _tempPath(), _logLevel("info"), + _logLocalTime(false), _quiet(false), _colorOptions(false), @@ -187,6 +188,7 @@ void ArangoClient::setupGeneral (ProgramOptionsDescription& description) { loggingOptions ("log.level,l", &_logLevel, "log level") + ("log.use-local-time", "log local dates and times in log messages") ; description @@ -318,9 +320,14 @@ void ArangoClient::parse (ProgramOptions& options, if (! options.parse(description, argc, argv)) { LOG_FATAL_AND_EXIT("%s", options.lastError().c_str()); } + + if (options.has("log.use-local-time")) { + _logLocalTime = true; + } // setup the logging TRI_SetLogLevelLogging(_logLevel.c_str()); + TRI_SetUseLocalTimeLogging(_logLocalTime); TRI_CreateLogAppenderFile("-", 0, TRI_LOG_SEVERITY_UNKNOWN, false); TRI_SetLineNumberLogging(false); TRI_SetThreadIdentifierLogging(false); @@ -400,7 +407,7 @@ void ArangoClient::parse (ProgramOptions& options, // if a username is specified explicitly, assume authentication is desired _disableAuthentication = false; } - + // check if have a password _hasPassword = options.has("server.password") || _disableAuthentication diff --git a/arangosh/ArangoShell/ArangoClient.h b/arangosh/ArangoShell/ArangoClient.h index b277970f6a..a8a8201333 100644 --- a/arangosh/ArangoShell/ArangoClient.h +++ b/arangosh/ArangoShell/ArangoClient.h @@ -424,6 +424,12 @@ namespace triagens { string _logLevel; +//////////////////////////////////////////////////////////////////////////////// +/// @brief use local dates & times in log messages +//////////////////////////////////////////////////////////////////////////////// + + bool _logLocalTime; + //////////////////////////////////////////////////////////////////////////////// /// @brief quiet start //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/ApplicationServer/ApplicationServer.cpp b/lib/ApplicationServer/ApplicationServer.cpp index fdf2c3e4b1..4e4472ea76 100644 --- a/lib/ApplicationServer/ApplicationServer.cpp +++ b/lib/ApplicationServer/ApplicationServer.cpp @@ -129,6 +129,7 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const _logSyslog(), _logThreadId(false), _logLineNumber(false), + _logLocalTime(false), _logSourceFilter(), _logContentFilter(), _randomGenerator(5), @@ -169,6 +170,7 @@ ApplicationServer::ApplicationServer (std::string const& name, std::string const _logSyslog(), _logThreadId(false), _logLineNumber(false), + _logLocalTime(false), _logSourceFilter(), _logContentFilter(), _randomGenerator(3), @@ -238,12 +240,17 @@ void ApplicationServer::setupLogging (bool threaded, bool daemon) { if (_options.has("log.line-number")) { _logLineNumber = true; } + + if (_options.has("log.use-local-time")) { + _logLocalTime = true; + } if (! _logRequestsFile.empty()) { // add this so the user does not need to think about it _logSeverity += ",usage"; } + TRI_SetUseLocalTimeLogging(_logLocalTime); TRI_SetLineNumberLogging(_logLineNumber); TRI_SetLogLevelLogging(_logLevel.c_str()); @@ -820,6 +827,7 @@ void ApplicationServer::setupOptions (map& op ("log.severity", &_logSeverity, "log severities") ("log.syslog", &_logSyslog, "use syslog facility") ("log.thread", "log the thread identifier for severity 'human'") + ("log.use-local-time", "use local dates and times in log messages") ; options[OPTIONS_HIDDEN] diff --git a/lib/ApplicationServer/ApplicationServer.h b/lib/ApplicationServer/ApplicationServer.h index ce2aaaefc5..02046806e8 100644 --- a/lib/ApplicationServer/ApplicationServer.h +++ b/lib/ApplicationServer/ApplicationServer.h @@ -759,7 +759,7 @@ namespace triagens { //////////////////////////////////////////////////////////////////////////////// /// @brief log line number /// @startDocuBlock logLineNumber -/// `--log.line-number}` +/// `--log.line-number` /// /// Normally, if an human readable fatal, error, warning or info message is /// logged, no information about the file and line number is provided. The file @@ -770,6 +770,19 @@ namespace triagens { bool _logLineNumber; +//////////////////////////////////////////////////////////////////////////////// +/// @brief log dates and times in local time zone +/// @startDocuBlock logLocalTime +/// `--log.use-local-time` +/// +/// If specified, all dates and times in log messages will use the server's +/// local time-zone. If not specified, all dates and times in log messages +/// will be printed in UTC / Zulu time. +/// @endDocuBlock +//////////////////////////////////////////////////////////////////////////////// + + bool _logLocalTime; + //////////////////////////////////////////////////////////////////////////////// /// @brief log source filter /// @startDocuBlock logSourceFilter diff --git a/lib/Basics/logging.cpp b/lib/Basics/logging.cpp index d1faf1ad13..52841752c6 100644 --- a/lib/Basics/logging.cpp +++ b/lib/Basics/logging.cpp @@ -261,6 +261,12 @@ static sig_atomic_t IsDebug = 0; static sig_atomic_t IsTrace = 0; +//////////////////////////////////////////////////////////////////////////////// +/// @brief use local time for dates & times in log output +//////////////////////////////////////////////////////////////////////////////// + +static sig_atomic_t UseLocalTime = 0; + //////////////////////////////////////////////////////////////////////////////// /// @brief show line numbers, debug and trace always show the line numbers //////////////////////////////////////////////////////////////////////////////// @@ -832,9 +838,17 @@ static void LogThread (char const* func, // ............................................................................. tt = time(0); - TRI_gmtime(tt, &tb); - // write time in buffer - len = strftime(buffer, 32, "%Y-%m-%dT%H:%M:%SZ ", &tb); + if (UseLocalTime == 0) { + // use GMtime + TRI_gmtime(tt, &tb); + // write time in buffer + len = strftime(buffer, 32, "%Y-%m-%dT%H:%M:%SZ ", &tb); + } + else { + // use localtime + TRI_localtime(tt, &tb); + len = strftime(buffer, 32, "%Y-%m-%dT%H:%M:%S ", &tb); + } va_copy(ap2, ap); @@ -1085,6 +1099,14 @@ void TRI_SetThreadIdentifierLogging (bool show) { ShowThreadIdentifier = show ? 1 : 0; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief use local time? +//////////////////////////////////////////////////////////////////////////////// + +void TRI_SetUseLocalTimeLogging (bool value) { + UseLocalTime = value ? 1 : 0; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief sets the line number visibility //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Basics/logging.h b/lib/Basics/logging.h index bf2a23683b..c161910951 100644 --- a/lib/Basics/logging.h +++ b/lib/Basics/logging.h @@ -138,13 +138,19 @@ void TRI_SetLogSeverityLogging (char const* severities); /// @brief sets the output prefix //////////////////////////////////////////////////////////////////////////////// -void TRI_SetPrefixLogging (char const* prefix); +void TRI_SetPrefixLogging (char const*); //////////////////////////////////////////////////////////////////////////////// /// @brief sets the thread identifier visibility //////////////////////////////////////////////////////////////////////////////// -void TRI_SetThreadIdentifierLogging (bool show); +void TRI_SetThreadIdentifierLogging (bool); + +//////////////////////////////////////////////////////////////////////////////// +/// @brief use local time? +//////////////////////////////////////////////////////////////////////////////// + +void TRI_SetUseLocalTimeLogging (bool); //////////////////////////////////////////////////////////////////////////////// /// @brief sets the line number visibility diff --git a/lib/Basics/operating-system.h b/lib/Basics/operating-system.h index 2f8faa7b5f..302e381919 100644 --- a/lib/Basics/operating-system.h +++ b/lib/Basics/operating-system.h @@ -101,6 +101,7 @@ #define TRI_HAVE_GETRUSAGE 1 #define TRI_HAVE_GETTIMEOFDAY 1 #define TRI_HAVE_GMTIME_R 1 +#define TRI_HAVE_LOCALTIME_R 1 #define TRI_HAVE_INITGROUPS 1 #define TRI_HAVE_SETGID 1 #define TRI_HAVE_SETUID 1 @@ -271,6 +272,7 @@ #define TRI_GETRUSAGE_MAXRSS_UNIT 1024 #define TRI_HAVE_GETTIMEOFDAY 1 #define TRI_HAVE_GMTIME_R 1 +#define TRI_HAVE_LOCALTIME_R 1 #define TRI_HAVE_SETGID 1 #define TRI_HAVE_SETUID 1 #define TRI_HAVE_STRTOLL 1 @@ -429,6 +431,7 @@ #define TRI_HAVE_GETRUSAGE 1 #define TRI_HAVE_GETTIMEOFDAY 1 #define TRI_HAVE_GMTIME_R 1 +#define TRI_HAVE_LOCALTIME_R 1 #define TRI_HAVE_INITGROUPS 1 #define TRI_HAVE_PRCTL 1 #define TRI_HAVE_SETGID 1 @@ -580,6 +583,7 @@ #define TRI_HAVE_GETTID 1 #define TRI_HAVE_GMTIME_S 1 +#define TRI_HAVE_LOCALTIME_S 1 #define TRI_HAVE_STRTOI64 1 #define TRI_HAVE_STRTOUI64 1 diff --git a/lib/Basics/system-functions.cpp b/lib/Basics/system-functions.cpp index b05dbee3e4..6c079ddbd5 100644 --- a/lib/Basics/system-functions.cpp +++ b/lib/Basics/system-functions.cpp @@ -135,6 +135,35 @@ ssize_t getline (char** lineptr, size_t* n, FILE* stream) { #endif +//////////////////////////////////////////////////////////////////////////////// +/// @brief safe localtime +//////////////////////////////////////////////////////////////////////////////// + +void TRI_localtime (time_t tt, struct tm* tb) { +#ifdef TRI_HAVE_LOCALTIME_R + + localtime_r(&tt, tb); + +#else + +#ifdef TRI_HAVE_LOCALTIME_S + + localtime_s(tb, &tt); + +#else + + struct tm* tp; + + tp = localtime(&tt); + + if (tp != NULL) { + memcpy(tb, tp, sizeof(struct tm)); + } + +#endif +#endif +} + //////////////////////////////////////////////////////////////////////////////// /// @brief safe gmtime //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/Basics/system-functions.h b/lib/Basics/system-functions.h index 632283fd08..16279600ed 100644 --- a/lib/Basics/system-functions.h +++ b/lib/Basics/system-functions.h @@ -62,6 +62,12 @@ int gettimeofday (struct timeval* tv, void* tz); ssize_t getline (char**, size_t*, FILE*); #endif +//////////////////////////////////////////////////////////////////////////////// +/// @brief safe localtime +//////////////////////////////////////////////////////////////////////////////// + +void TRI_localtime (time_t, struct tm*); + //////////////////////////////////////////////////////////////////////////////// /// @brief safe gmtime ////////////////////////////////////////////////////////////////////////////////