Skip to content

Commit

Permalink
[rosgraph] now allowing python_logging.yaml for logging configuration (
Browse files Browse the repository at this point in the history
…ros#1061)

* [rosgraph] now allowing python_logging.yaml for logging configuration

* get package path only once, minor style
  • Loading branch information
asmodehn authored and sputnick1124 committed Jul 30, 2017
1 parent f409c09 commit 057f94a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
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 @@ -41,6 +41,8 @@
import logging.config
import inspect

import yaml

import rospkg
from rospkg.environment import ROS_LOG_DIR

Expand Down Expand Up @@ -140,16 +142,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 @@ -159,10 +162,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

0 comments on commit 057f94a

Please sign in to comment.