New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support human-friendly Thread ID in logging messages (DM-4756) #9
Conversation
namespace log { | ||
namespace detail { | ||
|
||
int lwpID() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too fond of having his return an int. The lwp ID should be unsigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's a bit more complicated. LWP ID is actually a process ID which is of pid_t
type, and on Linux that type is int
. The only possible issue here is that on systems without LWP support we use incremental counter which could overflow and become negative. I'll think about adding protection against negative values. I could change int
here to pid_t
too if we don't care about systems that don't define that type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking again, I do not want to care about overflow, no reasonable application should create more than 2 billion threads during its lifetime.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, don't think, and use unsigned :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, switched to unsigned
for lwpID()
3c73b63
to
67f57a3
Compare
@@ -404,6 +407,66 @@ This has to be done after fork() and corresponding formatting code needs to be a | |||
|
|||
log4j.appender.FILE.layout.conversionPattern=%X{PID} - %m%n | |||
|
|||
\subsection TID Display thread ID | |||
|
|||
The conversion pattern in log4cxx has special conversion code (`%t`) to render "thread ID", the rendered value is a pointer to `thread_t` object (on POSIX systems) and is rendered as a long string of hexadecimal digits which makes it difficult to read for non-hardcore programmers. `lsst.log` provides more himan-friendly way to print thread-identifying information. Special function `lsst::log::lwpID()` returns light-weight process ID (LWP) on the plaftorms that support this feature and small incremental integer number on other platforms. Using this function one can add LWP to MDC and configure output format to include this special MDC key: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/himan/human
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To err is himan 👽
Also added lsst::log::lwpID() method which returns LWP ID or a simulated integer value (this is just a wrapper for detail::lwpID() added earlier).
ebbeda7
to
0aa50b8
Compare
Adding new macro LOG_MDC_INIT to support dynamic MDC initialization.
LOG_MDC_INIT macro takes a function which will be executed in every new thread to update MDC. Documentation updated to describe details.