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

Add Process ID to formatters #463

Merged
merged 3 commits into from
Oct 24, 2024
Merged

Conversation

HonakerM
Copy link
Contributor

Description

This PR adds the ability for formatters to optionally include the process_id in the log message. This is useful for multi-process applications.

Changes

Add new option to python alog.configure.

Testing

Tested locally

Related Issue(s)

List any issues related to this PR

Signed-off-by: Michael Honaker <[email protected]>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Two small nits. Nice addition!

@@ -25,7 +25,7 @@
logging package with a number of additional features, including log channels,
configurable formatting and scoped loggers.
"""

import os
Copy link
Collaborator

Choose a reason for hiding this comment

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

NIT: Please sort these alphabetically

Comment on lines 553 to 555
thread_id: bool =False,
handler_generator: Optional[Callable[[], logging.Handler]] = None,
process_id: bool =False,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
thread_id: bool =False,
handler_generator: Optional[Callable[[], logging.Handler]] = None,
process_id: bool =False,
thread_id: bool = False,
handler_generator: Optional[Callable[[], logging.Handler]] = None,
process_id: bool = False,

Signed-off-by: Michael Honaker <[email protected]>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Ok, nice! I think there are a few more things we should add to make this maximally useful:

  1. It should be handled in the pretty formatter. I'd suggest adding it right next to the thread_id (here) so that it formats as :<thread_id>:P<proc_id>
  2. We should add unit tests. This would look like adding it to the pretty print parsing, then replicating the tests for thread_id and making sure we handle having both/one/neither.

@HonakerM
Copy link
Contributor Author

@gabe-l-hart darn you trying to enforce good code etiquette. Let me push a commit

Signed-off-by: Michael Honaker <[email protected]>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

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

Thanks for putting up with me Casey!

@gabe-l-hart gabe-l-hart merged commit 8767173 into IBM:main Oct 24, 2024
14 checks passed
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.

2 participants