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

[rosgraph] now allowing python_logging.yaml for logging configuration #1061

Merged
merged 2 commits into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tools/rosgraph/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

<run_depend>python-netifaces</run_depend>
<run_depend>python-rospkg</run_depend>
<run_depend>python-yaml</run_depend>

<test_depend>python-mock</test_depend>

Expand Down
31 changes: 21 additions & 10 deletions tools/rosgraph/src/rosgraph/roslogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import logging
import logging.config

import yaml

import rospkg
from rospkg.environment import ROS_LOG_DIR

Expand Down Expand Up @@ -103,16 +105,17 @@ def configure_logging(logname, level=logging.INFO, filename=None, env=None):
else:
# search for logging config file in /etc/. If it's not there,
# look for it package-relative.
fname = 'python_logging.conf'
config_file = None
rosgraph_d = rospkg.RosPack().get_path('rosgraph')
for f in [os.path.join(rospkg.get_ros_home(), 'config', fname),
'/etc/ros/%s'%(fname),
os.path.join(rosgraph_d, 'conf', fname)]:
if os.path.isfile(f):
config_file = f
for fname in ['python_logging.conf', 'python_logging.yaml']:
for f in [os.path.join(rospkg.get_ros_home(), 'config', fname),
'/etc/ros/%s'%(fname),
os.path.join(rosgraph_d, 'conf', fname)]:
if os.path.isfile(f):
config_file = f
break
if config_file is not None:
break
else:
config_file = None

if config_file is None or not os.path.isfile(config_file):
# logging is considered soft-fail
Expand All @@ -122,10 +125,18 @@ def configure_logging(logname, level=logging.INFO, filename=None, env=None):

# pass in log_filename as argument to pylogging.conf
os.environ['ROS_LOG_FILENAME'] = log_filename
# #3625: disabling_existing_loggers=False
logging.config.fileConfig(config_file, disable_existing_loggers=False)
if config_file.endswith(('.yaml', '.yml')):
with open(config_file) as f:
dict_conf = yaml.load(f)
dict_conf.setdefault('version', 1)
logging.config.dictConfig(dict_conf)
else:
# #3625: disabling_existing_loggers=False
logging.config.fileConfig(config_file, disable_existing_loggers=False)

return log_filename


def makedirs_with_parent_perms(p):
"""
Create the directory using the permissions of the nearest
Expand Down