Skip to content
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

Merged
merged 5 commits into from Feb 26, 2016

Conversation

andy-slac
Copy link
Contributor

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.

namespace log {
namespace detail {

int lwpID() {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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 :-)

Copy link
Contributor Author

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()

@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/himan/human

Copy link
Contributor Author

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).
@andy-slac andy-slac merged commit 0aa50b8 into master Feb 26, 2016
@ktlim ktlim deleted the tickets/DM-4756 branch August 25, 2018 05:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants