-
Notifications
You must be signed in to change notification settings - Fork 913
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
[rospy] Write log for class method with class name for rospy #877
Closed
wkentaro
wants to merge
11
commits into
ros:kinetic-devel
from
wkentaro:rosconsole-format-func-with-class
Closed
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
606a907
Write log for class method with class name for rospy
wkentaro 1642602
Fix func name {class_name}.{method_name}
wkentaro 00ab383
Get line number for rospy logger
wkentaro 9f86e24
Add test for roslogging ROSCONSOLE_FORMAT
wkentaro bb4e980
Add license header
wkentaro 4a1cdde
Don't overwrite logger defined by user
wkentaro 76835b0
Inherit user defined custom logger class in RospyLogger
wkentaro 0abb0db
Fix test name of test_roslogging_user_logger.py
wkentaro 6ac0137
Make logging test as isolated one
wkentaro 603cdea
Revert "Make logging test as isolated one"
wkentaro 5b7e3e8
Fix test for rosgraph with user custom logger
wkentaro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import logging | ||
import os | ||
from StringIO import StringIO | ||
import sys | ||
|
||
from nose.tools import assert_regexp_matches | ||
import rosgraph.roslogging | ||
|
||
|
||
os.environ['ROSCONSOLE_FORMAT'] = ' '.join([ | ||
'${severity}', | ||
'${message}', | ||
'${walltime}', | ||
'${thread}', | ||
'${logger}', | ||
'${file}', | ||
'${line}', | ||
'${function}', | ||
'${node}', | ||
'${time}', | ||
]) | ||
rosgraph.roslogging.configure_logging('test_rosgraph', logging.INFO) | ||
loginfo = logging.getLogger('rosout').info | ||
|
||
# Remap stdout for testing | ||
f = StringIO() | ||
sys.stdout = f | ||
|
||
|
||
loginfo('on module') | ||
|
||
|
||
def logging_on_function(): | ||
loginfo('on function') | ||
|
||
logging_on_function() | ||
|
||
|
||
class LoggingOnClass(object): | ||
|
||
def __init__(self): | ||
loginfo('on method') | ||
|
||
LoggingOnClass() | ||
|
||
|
||
def test_rosconsole__logging_format(): | ||
this_file = os.path.abspath(__file__) | ||
# this is necessary to avoid test fails because of .pyc cache file | ||
base, ext = os.path.splitext(this_file) | ||
if ext == '.pyc': | ||
this_file = base + '.py' | ||
|
||
for i, loc in enumerate(['module', 'function', 'method']): | ||
if loc == 'module': | ||
function = '<module>' | ||
elif loc == 'function': | ||
function = 'logging_on_function' | ||
elif loc == 'method': | ||
function = 'LoggingOnClass.__init__' | ||
else: | ||
raise ValueError | ||
|
||
log_out = ' '.join([ | ||
'INFO', | ||
'on ' + loc, | ||
'[0-9]*\.[0-9]*', | ||
'[0-9]*', | ||
'rosout', | ||
this_file, | ||
'[0-9]*', | ||
function, | ||
'/unnamed', | ||
'[0-9]*\.[0-9]*', | ||
]) | ||
assert_regexp_matches(f.getvalue().splitlines()[i], log_out) | ||
|
||
|
||
sys.stdout = sys.__stdout__ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 should ensure not to overwrite custom logger classes already being set by user code. See https://docs.python.org/2/library/logging.html#logging.getLoggerClass on how to achieve this.
Could you please also cover that case in the test.