-
Notifications
You must be signed in to change notification settings - Fork 137
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 LaunchLogger class #145
Conversation
56b180d
to
e0647ea
Compare
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.
lgtm, other than some style comments.
launch/launch/launch_service.py
Outdated
@@ -81,23 +81,22 @@ def __init__( | |||
:param: argv stored in the context for access by the entities, None results in [] | |||
:param: debug if True (not default), asyncio the logger are seutp for debug | |||
""" | |||
# Setup logging and debugging. | |||
# TODO(hidmic): should be moved somewhere else maybe? |
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.
Like where? Generally, I'd like to avoid indeterminate TODO's, at best they have a "do X when Y is possible/occurs" type structure. So I'd like to resolve this TODO before merging.
This seems like a reasonable place to initialize the logging, was there a specific use case you have in mind where this might not work out?
launch/launch/logging.py
Outdated
return _decorator | ||
|
||
|
||
@singleton(screen_handler=None, file_handlers={}) |
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.
This isn't a great name for the decoration, imo. It's not making the function a singleton, it's adding attributes to the function. Maybe add_logging_attributed
or just logging_attributes
.
launch/launch/logging.py
Outdated
|
||
@singleton(screen_handler=None, file_handlers={}) | ||
def launchConfig(*, level=None, log_dir=None, screen_format=None, | ||
log_format=None, screen_style=None, log_style=None): |
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.
Please wrap all arguments or none, and do not vertically align like this. All indentation should be a multiple of 4 and should only indent one level at a time.
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.
def launchConfig(
*, level=None, log_dir=None, screen_format=None,
log_format=None, screen_style=None, log_style=None
):
or
def launchConfig(
*,
level=None,
log_dir=None,
screen_format=None,
log_format=None,
screen_style=None,
log_style=None
):
launch/launch/logging.py
Outdated
the 'default' format. | ||
:param: screen_style the screen format style. No style can be provided | ||
if a format alias is given. | ||
:param: log_format for logging to the main launch log file, as expected |
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.
This parameter comes before the previously documented on (screen_style
) in the function declaration, please document them in the order they appear in the function declaration.
@wjwwood ready for re-review and merge! :) |
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.
This lgtm, I went through and fixed some style issues, and some docs, and some style issues with the docs :D.
Also, I noticed the use of methodName
rather than method_name
, which is more common in launch itself. I guess you were trying to emulate the logging
module from Python in some cases, to have launch.logging
be a drop in replacement of sorts for it.
I'm not sure how I feel about that. I kind of prefer people to use Python's logging
directly and the launch.logging
module only be used for configuration and special cases. This is pretty much what's happening right now anyways, for instance the only place that launch.logging.getLogger()
is being used instead of logging.getLogger
appears to be in the launch service, even though there are numerous other cases throughout the code that get the logger directly from Python.
I opened a draft pr (#190) so we can discuss it, because I'd like to know what you think about.
Related to that, I can see the convenience of forwarding some of the logging
module's contents via launch.logging
, e.g. forwarding logging.DEBUG
as launch.logging.DEBUG
, but for most of the cases, it seems like having people just use logging
directly might be better. Especially if the above draft pr is the direction we want to go in.
That's correct. As a result of providing all necessary functionality (e.g. a An alternative, though it wouldn't allow for some of the functionality added now, would be to turn
I'm under the impression that you're not considering the changes added by #147 (which we should probably merge into this one). Using |
BTW thanks for the typing annotations :) Haven't had the time to setup |
Yup, that bit me again. I would support merging them. So, you are using the custom What do you want to do, leave it as is or make |
Ok, I think I see where you're going. To have |
66af818
to
e7f6802
Compare
@wjwwood Alright, done. I had to rebase to solve some merge conflicts. There're two things I'm not very fond of though:
I'd be inclined to push all |
I'm not sure why but there are still merge conflicts. |
Uh. That's odd. I'll rebase again. |
e7f6802
to
2ab223f
Compare
@wjwwood ping |
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.
lgtm
There're two things I'm not very fond of though:
- To have launch_config() affecting logging.root verbosity.
Yeah, I guess so, but couldn't you instead store the requested log level and apply it only to the loggers as they're created using launch.logging.*
functions? Effectively preventing them from inheriting from the root logger's settings or you could ensure the given log level is not less than the inherited log level, so that setting the root logger to debug would still affect all launch loggers even if the log level given was info, for example.
- To have reset() affecting all loggers known to logging.
I don't understand the problem with this one.
I'd be inclined to push all launch.logging loggers below a common namespace like
launch.<logger-name>
to scope the effect of the aforementioned functions. Thoughts?
I'd prefer to not do that since it just makes all the names longer, though I could be convinced otherwise if there were example outputs which didn't look too bad. Instead I'd prefer to keep track of which "top level" loggers need to be affected without having a namespace for them all.
In the end, I think it won't matter that much as the default use case is running launch in it's own process by itself. The will be cases where that's not true, but I don't feel like this is going to be a big issue, but I could be underestimating it.
Hmm, the problem with that approach is that
That it's counter-intuitive if you're using the raw
That's a fair argument. Though we'll have a testing framework using Anyways, I'll rebase, test and merge this to get things going. We can revisit it later (even open issues if you think it's worth it). Thanks for the review @wjwwood ! |
Supports logging messages from multiple processes and modules to the screen, a common log file, or both. LaunchLogger is a singleton and when it is first instantiated a log file is created of the form 'DATETIME-launch-HOSTNAME-PID.log'. Messages sent to the screen or the log file will have the format 'TIME [LEVEL] NAME: MESSAGE'.
The timestamp in the screen format is optional.
Also extends LaunchLogger interface. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
- Fix style and documentation issues. - Removes dangling TODO. Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: William Woodall <william@osrfoundation.org>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Replacing usage of the Python logging module with the new LaunchLogger.
Also, removed unecessary logging logic.
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
Signed-off-by: Michel Hidalgo <michel@ekumenlabs.com>
2ab223f
to
9872792
Compare
Alright, CI passed. I'll merge this one, we can discuss outstanding issues/caveats in future PRs. |
Supports logging messages from multiple processes and modules to the screen, a common log file, or both.
LaunchLogger is a singleton and when it is first instantiated a log file is created of the form 'DATETIME-launch-HOSTNAME-PID.log'.
Messages sent to the screen or the log file will have the format 'TIME [LEVEL] NAME: MESSAGE'.
Connects to #104
Tests were added that capture and check stdout, but I could only get them working by supplying pytest with the
-s
option. I'm not sure why this is required.E.g.
colcon test --pytest-args -s --packages-select launch