Poco::Thread::current() is not reliable for logging
It can return null for no obvious reason, leading to misleading logging where the same thread is identified as numer zero at one place and non-zero at another. So use the actual Linux thread id in logging. Sure, thread ids are somewhat less convenient, as they are larger numbers, from the same number space as process ids.
This commit is contained in:
parent
f84cad1e8d
commit
8207412c02
1 changed files with 5 additions and 2 deletions
|
@ -15,6 +15,9 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Poco/ConsoleChannel.h>
|
||||
#include <Poco/FileChannel.h>
|
||||
#include <Poco/FormattingChannel.h>
|
||||
|
@ -88,8 +91,8 @@ namespace Log
|
|||
const char *appName = (Source.inited ? Source.id.c_str() : "<shutdown>");
|
||||
assert(strlen(appName) + 32 + 28 < 1024 - 1);
|
||||
|
||||
snprintf(buffer, 4095, "%s-%.2d %d:%.2d:%.2d.%.6d [ %s ] %s ", appName,
|
||||
(Poco::Thread::current() ? Poco::Thread::current()->id() : 0),
|
||||
snprintf(buffer, 4095, "%s-%.04lu %d:%.2d:%.2d.%.6d [ %s ] %s ", appName,
|
||||
syscall(SYS_gettid),
|
||||
(int)hours, (int)minutes, (int)seconds, (int)usec,
|
||||
procName, level);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue