Add named loggers to rospy #948
Conversation
dirk-thomas
left a comment
There was a problem hiding this comment.
Currently the patch fails to run the tests. Please iterate on this and run the tests locally.
| """Internal rospy client library warn logging""" | ||
| _rospy_logger.warn(msg, *args) | ||
|
|
||
| logdebug = logging.getLogger('rosout').debug |
There was a problem hiding this comment.
These variables are public API and can't be changed without breaking compatibility.
There was a problem hiding this comment.
I think this is replaced in line 181 of the new file:
https://github.com/ros/ros_comm/pull/948/files#diff-84739190beb4f06aecd26a816f126e29R181
There was a problem hiding this comment.
I'll take a look at it, I included a bunch of different commit here by accident. I'm cleaning up now
clients/rospy/src/rospy/core.py
Outdated
| """ | ||
| if uri.startswith(ROSRPC): | ||
| dest_addr = uri[len(ROSRPC):] | ||
| dest_addr = uri[len(ROSRPC):] |
There was a problem hiding this comment.
Please avoid any unrelated white space changes in your PR (even if the current file might be "ugly"). It makes backporting changes across branches much more difficult.
There was a problem hiding this comment.
Please take a look at the diff on the GitHub PR and update the PR to avoid any unnecessary changes.
There was a problem hiding this comment.
sorry I thought I got them, I'll fix it up
There was a problem hiding this comment.
I'll fix this again, I think the file has mixed line endings and my editor is trying to be helpful
f251821 to
14f6c53
Compare
f7d787a to
ab08dff
Compare
|
My previous comment still applies to the updated change. Please avoid any unrelated white space changes in your PR. |
774d1b7 to
a83e09e
Compare
a83e09e to
e99024f
Compare
dirk-thomas
left a comment
There was a problem hiding this comment.
Can you please add some unit tests (https://github.com/ros/ros_comm/blob/kinetic-devel/test/test_rospy/test/unit/test_rospy_core.py) covering the new funtionality.
clients/rospy/src/rospy/core.py
Outdated
| def _get_digest(*args): | ||
| m = hashlib.md5() | ||
| for arg in args: | ||
| m.update(str(args)) |
There was a problem hiding this comment.
Should this call update with arg instead of args?
There was a problem hiding this comment.
yes, it should be arg instead of args. I'll fix that up.
There was a problem hiding this comment.
Using MD5 for this seems like overkill. What about something like hash(tuple(*args + [str(msg)]))?
(Python's hashdoesn't do the right thing, so you can't use it directly, see ros/genpy#73)
There was a problem hiding this comment.
That should work, we only want to know the content of the print has changed. I'll test it out tonight.
clients/rospy/src/rospy/core.py
Outdated
| logfunc = getattr(rospy_logger, level) | ||
|
|
||
| if throttle: | ||
| caller_id = _frame_record_to_caller_id(inspect.stack()[1]) |
There was a problem hiding this comment.
Is 1 still correct now that the function is one level more nested?
There was a problem hiding this comment.
I believe 2 is correct now because of the one more level down, I'll verify and fix that up
9253224 to
1389f4c
Compare
|
I resolved all the white space conflicts that my editor injected. Is there a standard line ending that each file should follow? I see this core.py has mixed line endings. I should have unit tests up tomorrow, I have a test program that I used for develpoment I'll port to the test framework. |
clients/rospy/src/rospy/core.py
Outdated
| try: | ||
| level = kwargs.pop('logger_level') | ||
| except KeyError: | ||
| level = None |
There was a problem hiding this comment.
For my curiosity, what does this achieve over, eg:
def _base_logger(msg, name=None, throttle=None, level=None, *args, **kwargs):
rospy_logger = logging.getLogger('rosout')
if name:
rospy_logger = rospy_logger.getChild(name)
logfunc = getattr(rospy_logger, level)
if throttle:
caller_id = _frame_record_to_caller_id(inspect.stack()[2])
_logging_throttle(caller_id, logfunc, throttle, msg, *args)
else:
logfunc(msg, *args)
There was a problem hiding this comment.
I had the function using default values in one iteration but I believe i started failing tests and decided to use the keyword arguments instead. I'll rerun the tests and see if I can remember why I switched to using keyword args instead.
There was a problem hiding this comment.
Looking back through my testing, I had a test case where using the named arguments for name, throttle and level (like above) would interfer with variable length arguments. This happened when testing out code that was using the existing public API, the named variables would end up taking some of the values from the multi length arguments.
There was a problem hiding this comment.
Oh of course, that makes sense. In that case, maybe pass the default to pop rather than catching the exception. Eg:
def _base_logger(msg, *args, **kwargs):
name = kwargs.pop('logger_name', None)
throttle = kwargs.pop('logger_throttle', None)
level = kwargs.pop('logger_level', None)
There was a problem hiding this comment.
much cleaner, will change that
e0cb90c to
71f587e
Compare
|
I believe all the the comments have been resolved, please let me know if there is anything else needed |
ce667df to
664666d
Compare
|
cleaned up the review, looks better now. Tests are passing on my local machine. |
|
Looks good now, white space should be fixed to only what I changed and tests are now passing. |
|
ping @ros/ros_comm-maintainers All comments I believe are resolved |
|
👍 |
|
Sorry for the late response. This looks almost ready. Recently some concerns regarding performance came up though which have been addressed in #1091 for the other logging function. Can you please update the PR to use a similar approach. Thank you. This will also need to be rebased. |
422e9ec to
60e16b3
Compare
…gers under rospy.rosout. This allows for each named logger to have seperate verbosity setting, this will allow for two different verboisty settings for logging in a single node. Two named loggers can log to rosout at two different verbosity setings, which can help noisy debug logs.
60e16b3 to
58fec5c
Compare
|
Thank you for this new feature. Please consider adding some information to the wiki page to mention this to be available as of Lunar and post the link here for future readers. |
|
This breaks the |
@ggallagher01 Can you please look into this. |
|
I think the issue here is that we jump up two stack frames in the throttle case, but in the other case we need to jump up one frame (currently nothing): I can verify this and throw up a PR for it. |
|
Okay, I did dig into this a little more, and it's not quite as simple— the code I pasted only has to do with identifying the caller for the purposes of enforcing throttling. The actual logic which identifies the caller was added only recently in #1043, see: https://github.com/ros/ros_comm/blob/lunar-devel/tools/rosgraph/src/rosgraph/roslogging.py#L52-L80 It looks like this is a case where the underlying logic built into Since the amount of wrapping is not always consistent:
See some discussion here as well: https://stackoverflow.com/questions/19615876/showing-the-right-funcname-when-wrapping-logger-functionality-in-a-custom-class |
|
Okay, I've opened #1141 with a potential fix, so we can discuss that and other options there. |
|
This is a great addition, but wiki/rospy/Overview/Logging does not mention it. Is that an oversight? @ggallagher01: would you be willing to add that? From rospy equivalent of ROS_*_NAMED on ROS Answes. |
|
I'll have some time this weekend to add this |
|
I found that http://wiki.ros.org/rospy/Overview/Logging doesn't contain the features this commit adds. It may need to be updated. Another confusing thing is that on the wiki page, I am actually looking at the support of This ticket probably broke the python logger's |
@ggallagher31 Can you please follow up on this and add documentation about this feature to the wiki page. |
|
Ping. This feature is still not documented in the ROS wiki. I would be willing to provide the documentation but the wiki site is immutable for me. |
|
@timonegk: the wiki is read-only, unless you have an account. You can register for an account here. After that, you'd have to request write-access (spam protection measure) in ros-infrastructure/roswiki#258. |
|
@gavanderhoorn Thank you. I was not aware of the whitelist. |
|
I believe it's mentioned after you register. |
|
This feature is now documented (http://wiki.ros.org/rospy/Overview/Logging#Named_Logging). |
This change will create (named) child loggers under rospy.rosout. This allows for each named logger to have seperate verbosity setting, this will allow for two different verboisty settings for logging in a single node. Two named loggers can log to rosout at two different verbosity setings, which can help noisy debug logs.