mirror of https://gitee.com/bigwinds/arangodb
cache pid for logging
This commit is contained in:
parent
f4b6d3ef70
commit
805a1c5d51
|
@ -242,6 +242,7 @@ int DaemonFeature::forkProcess() {
|
|||
|
||||
// child
|
||||
LogAppender::allowStdLogging(false);
|
||||
Logger::clearCachedPid();
|
||||
|
||||
// change the file mode mask
|
||||
umask(0);
|
||||
|
|
|
@ -67,6 +67,7 @@ bool Logger::_keepLogRotate(false);
|
|||
bool Logger::_useMicrotime(false);
|
||||
bool Logger::_showRole(false);
|
||||
char Logger::_role('\0');
|
||||
TRI_pid_t Logger::_cachedPid(0);
|
||||
std::string Logger::_outputPrefix("");
|
||||
|
||||
std::unique_ptr<LogThread> Logger::_loggingThread(nullptr);
|
||||
|
@ -329,7 +330,17 @@ void Logger::log(char const* function, char const* file, int line,
|
|||
}
|
||||
|
||||
// append the process / thread identifier
|
||||
out << '[' << Thread::currentProcessId();
|
||||
|
||||
// we only determine our pid once, as currentProcessId() will
|
||||
// likely do a syscall.
|
||||
// this read-check-update sequence is not thread-safe, but this
|
||||
// should not matter, as the pid value is only changed from 0 to the
|
||||
// actual pid and never changes afterwards
|
||||
if (_cachedPid == 0) {
|
||||
_cachedPid = Thread::currentProcessId();
|
||||
}
|
||||
TRI_ASSERT(_cachedPid != 0);
|
||||
out << '[' << _cachedPid;
|
||||
|
||||
if (_showThreadIdentifier) {
|
||||
out << '-' << Thread::currentThreadNumber();
|
||||
|
@ -444,6 +455,8 @@ void Logger::shutdown() {
|
|||
|
||||
// cleanup appenders
|
||||
LogAppender::shutdown();
|
||||
|
||||
_cachedPid = 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -235,6 +235,9 @@ class Logger {
|
|||
static bool getUseMicrotime() {return _useMicrotime;};
|
||||
static void setKeepLogrotate(bool);
|
||||
|
||||
// can be called after fork()
|
||||
static void clearCachedPid() { _cachedPid = 0; }
|
||||
|
||||
static std::string const& translateLogLevel(LogLevel);
|
||||
|
||||
static void log(char const* function, char const* file, int line,
|
||||
|
@ -275,6 +278,7 @@ class Logger {
|
|||
static bool _keepLogRotate;
|
||||
static bool _useMicrotime;
|
||||
static char _role; // current server role to log
|
||||
static TRI_pid_t _cachedPid;
|
||||
static std::string _outputPrefix;
|
||||
|
||||
static std::unique_ptr<LogThread> _loggingThread;
|
||||
|
|
Loading…
Reference in New Issue