-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Labels
Description
To start, after speaking with @clalancette, here's a bullet list of the current state of affairs:
- console messages (tuple of logger name, log level, log message, etc...) are sent to rcutils via logging macros
- rcutils determines if the logger is enabled for the console message's level
- it checks this here: https://github.com/ros2/rcutils/blob/c49b41c9b19ae9e76e746db662285fc6c7d3b1af/src/logging.c#L911-L913
- severity is considered here: https://github.com/ros2/rcutils/blob/c49b41c9b19ae9e76e746db662285fc6c7d3b1af/src/logging.c#L875-L889
- rcutils calls the output handler (it only supports one at a time)
- it calls the global output handler here: https://github.com/ros2/rcutils/blob/c49b41c9b19ae9e76e746db662285fc6c7d3b1af/src/logging.c#L901-L904
- by default rcl registers a handler (so the default rcutils one is not used directly)
- actually by default the client libraries (e.g. rclcpp and rclpy) register a single handler, but in those cases they just make it thread-safe and then forward it to the rcl handler
- the rcl handler iterates over its internal list of output handlers and calls each one in turn with the console message
- by default it has one for the console, which just send the console message back to rcutils and it is printed there
- it also has one for rosout:
- and finally it has one for the "external logging library" which is the spdlog backend:
- each logging handler does what it wants with the console message
- the spdlog backend will write it to file only
There a few problems with this:
- rcutils printing to the console means that:
- we have to configure it separately from the logging backend (including disabling it or changing its default log level)
- we don't take advantage of implicit features of the logging backend (like the console printing performance of spdlog)
- filter console messages in rcutils instead of in each output handler means:
- you cannot have different log levels set for each output handler (or sink), e.g. you cannot have debug go to file and info to console
- also, you limit what goes over
/rosoutbased on what you output to the console, limiting the remote debugger's ability to see more details than what is printed to the screen (I haven't confirmed this, but it seems to be the case based on the code)
Additionally, the default logging backend that uses spdlog does not have any way to configure it using a file or the command line. There is a command line option to disable it entirely (see: #88 (comment))
The current state makes it impossible to configure the system in a few ways, the most important of which is a use case that came up from one of our clients where they would like to:
- have a single config file they pass to all nodes (via launch or env var or command line)
- control the default log level of the file and console separately, e.g. debug to file and info to console
- control the log level of specific named loggers based on the sink, e.g. logger 'my_node' puts debug to file and info to console
There are other use cases which might be considered, but this one I think is going to be pretty common and is not possible in the current situation.
For these reasons, I propose we make these changes:
- use spdlog (and generally the logging back ends) for console printing (rather than the implementation in rcutils)
- delegate the filtering of console messages by log level to each output handler so they can have different levels
- define a ROS specific console logging config file format that can be parsed and used to configure
rcl_logging_spdlog(since spdlog does not have its own config file format) - (optional) elevate the concept of "sinks" to the ROS level, so users can configure different log levels per sink for each named logger (at least in the config file if not also from the command line)
- e.g. something like
--log-level my_node:=file:debug,console:infoinstead of--log-level my_node:=debug
- e.g. something like
rshanor, haronaut, Achllle and Jakub-husarz