mirror of https://gitee.com/bigwinds/arangodb
issue #1042
This commit is contained in:
parent
5abfa7fdbd
commit
31ebe14ea6
|
@ -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
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@ statistics about executed requests and timings about computation steps.
|
|||
<!-- lib/ApplicationServer/ApplicationServer.h -->
|
||||
@startDocuBlock logLevel
|
||||
|
||||
!SUBSECTION Local Time
|
||||
<!-- lib/ApplicationServer/ApplicationServer.h -->
|
||||
@startDocuBlock logLocalTime
|
||||
|
||||
!SUBSECTION Line number
|
||||
<!-- lib/ApplicationServer/ApplicationServer.h -->
|
||||
@startDocuBlock logLineNumber
|
||||
|
@ -61,4 +65,4 @@ statistics about executed requests and timings about computation steps.
|
|||
|
||||
!SUBSECTION Histname
|
||||
<!-- lib/ApplicationServer/ApplicationServer.h -->
|
||||
@startDocuBlock logHostname
|
||||
@startDocuBlock logHostname
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -424,6 +424,12 @@ namespace triagens {
|
|||
|
||||
string _logLevel;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief use local dates & times in log messages
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool _logLocalTime;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief quiet start
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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<string, ProgramOptionsDescription>& 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]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -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
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue