Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

now allowing python_logging.yaml#1033

Closed
asmodehn wants to merge 2 commits intoros:indigo-develfrom
asmodehn:yaml_logging_conf
Closed

now allowing python_logging.yaml#1033
asmodehn wants to merge 2 commits intoros:indigo-develfrom
asmodehn:yaml_logging_conf

Conversation

@asmodehn
Copy link
Copy Markdown
Contributor

Small PR to enable support for yaml configuration for python logging.
Do not merge yet, this is still in testing...

@mikepurvis
Copy link
Copy Markdown
Member

mikepurvis commented Apr 19, 2017

I'm not a major user of rospy, but the log4cxx logger in roscpp is configured via the ROSCONSOLE_CONFIG_FILE environment variable. Should there be something similar to allow setting the config location for Python? Wait a minute, nevermind— there totally is ROS_PYTHON_LOG_CONFIG_FILE. Is this change just allowing yaml in addition to conf as the format?

FYI @paulbovbel

@asmodehn
Copy link
Copy Markdown
Contributor Author

@mikepurvis yes just that. I figured it was simple enough to add and would allow more detailed configuration using recent python 2.7 logging API. Plus we are already using yaml everywhere for configuration in our ROS software so why not for logging as well.

But AFAIK there is no test for this behaviour it and I haven't used it yet, so this patch might need a few days/weeks to mature...

@asmodehn
Copy link
Copy Markdown
Contributor Author

I tested part of that new code (by setting ROS_PYTHON_LOG_CONFIG_FILE to python_logging.yaml in my environment) with this file :

---
version: 1
disable_existing_loggers: False
formatters:
    default:
        format: "[%(name)s][%(levelname)s] %(asctime)s: %(message)s"

handlers:

    rosconsole:
        class: rosgraph.roslogging.RosStreamHandler
        level: DEBUG
        formatter: default
        colorize: True

    roslog:
        class: logging.handlers.RotatingFileHandler
        level: DEBUG
        formatter: default
        filename: os.environ['ROS_LOG_FILENAME']
        maxBytes: 50000000
        backupCount: 4

loggers:

    root:
        level: INFO
        handlers: [roslog]

    rosout:
        level: INFO
        handlers: [rosconsole]
        propagate: yes
        qualname: rosout

I get one error that I didn't have with python_logging.conf :

No handlers could be found for logger "roslaunch"

As well as for my other custom loggers in my code that didn't add NullHandler as explained here : https://docs.python.org/2/howto/logging.html#library-config

So I understand it means that no logger is configured for roslaunch in python_logging.conf, but I don't know what is the behavior in that case, where and how it will send log messages...

We should add a NullHandler into roslaunch.
But do we want to add a specific config for roslaunch logger ?

@asmodehn
Copy link
Copy Markdown
Contributor Author

Or maybe we do not want a NullHandler for roslaunch, since it is not a library after all, and that error is expected.

And we should define (for example) :

  • a default console handler for roslaunch in code
  • an extra file handler in configuration file (if needed, or even just as an example).

Any idea/advice for this ?

@asmodehn
Copy link
Copy Markdown
Contributor Author

I solved roslaunch warning on my side by adding this to the config :

    roslaunch:
        level: WARNING
        handlers: [rosconsole]
        propagate: no
        qualname: roslaunch

dict_conf = yaml.load(f)
dict_conf.setdefault('version', 1)
logging.config.dictConfig(dict_conf)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this block doesn't have an else part. Also if the user was using a different filename before it might not work with the modified code anymore. Therefore I would suggest the logic to be updated to:

if yaml:
    # do yaml stuff
else:
    # do stuff as before

Copy link
Copy Markdown
Member

@dirk-thomas dirk-thomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please retarget the latest development branch (lunar-devel).

import logging
import logging.config

import yaml
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package currently doesn't depend on yaml. Please add the additional dependency to the package manifest.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I get it now rosgraph, not roslaunch. my bad...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants