Logger: added %O to message format to display numeric thread id in logs.

This commit is contained in:
Matej Kenda 2015-06-01 10:00:56 +02:00
parent f1e6cba313
commit e26bb65a5b
4 changed files with 18 additions and 0 deletions

View File

@ -128,6 +128,9 @@ public:
long getTid() const;
/// Returns the numeric thread identifier for the message.
long getOsTid() const;
/// Returns the numeric OS thread identifier for the message.
void setPid(long pid);
/// Sets the process identifier for the message.
@ -196,6 +199,7 @@ private:
Priority _prio;
Timestamp _time;
int _tid;
int _ostid;
std::string _thread;
long _pid;
const char* _file;
@ -243,6 +247,12 @@ inline long Message::getTid() const
}
inline long Message::getOsTid() const
{
return _ostid;
}
inline long Message::getPid() const
{
return _pid;

View File

@ -45,6 +45,7 @@ class Foundation_API PatternFormatter: public Formatter
/// * %P - message process identifier
/// * %T - message thread name
/// * %I - message thread identifier (numeric)
/// * %O - message thread OS identifier (numeric)
/// * %N - node or host name
/// * %U - message source file path (empty string if not set)
/// * %u - message source line number (0 if not set)

View File

@ -29,6 +29,7 @@ namespace Poco {
Message::Message():
_prio(PRIO_FATAL),
_tid(0),
_ostid(0),
_pid(0),
_file(0),
_line(0),
@ -43,6 +44,7 @@ Message::Message(const std::string& source, const std::string& text, Priority pr
_text(text),
_prio(prio),
_tid(0),
_ostid(0),
_pid(0),
_file(0),
_line(0),
@ -57,6 +59,7 @@ Message::Message(const std::string& source, const std::string& text, Priority pr
_text(text),
_prio(prio),
_tid(0),
_ostid(0),
_pid(0),
_file(file),
_line(line),
@ -72,6 +75,7 @@ Message::Message(const Message& msg):
_prio(msg._prio),
_time(msg._time),
_tid(msg._tid),
_ostid(msg._ostid),
_thread(msg._thread),
_pid(msg._pid),
_file(msg._file),
@ -90,6 +94,7 @@ Message::Message(const Message& msg, const std::string& text):
_prio(msg._prio),
_time(msg._time),
_tid(msg._tid),
_ostid(msg._ostid),
_thread(msg._thread),
_pid(msg._pid),
_file(msg._file),
@ -113,6 +118,7 @@ void Message::init()
#if !defined(POCO_VXWORKS)
_pid = Process::id();
#endif
_ostid = Thread::currentTid();
Thread* pThread = Thread::current();
if (pThread)
{

View File

@ -75,6 +75,7 @@ void PatternFormatter::format(const Message& msg, std::string& text)
case 'P': NumberFormatter::append(text, msg.getPid()); break;
case 'T': text.append(msg.getThread()); break;
case 'I': NumberFormatter::append(text, msg.getTid()); break;
case 'O': NumberFormatter::append(text, msg.getOsTid()); break;
case 'N': text.append(Environment::nodeName()); break;
case 'U': text.append(msg.getSourceFile() ? msg.getSourceFile() : ""); break;
case 'u': NumberFormatter::append(text, msg.getSourceLine()); break;