ros2 / launch

Tools for launching multiple processes and for writing tests involving multiple processes.
Apache License 2.0
126 stars 144 forks source link

How to add SysLogHandler #736

Open firesurfer opened 1 year ago

firesurfer commented 1 year ago

Hi, I would like to write all log messages which are written to launch.log per default additionally to the system log (and later on to a remote logging server).

What I tried so far is to add a SysLogHandler in my launch.py file to every registered logger:

import launch.logging
import logging.handlers
import logging

def generate_launch_description():

    for logger in launch.logging.LaunchLogger.all_loggers:
        handler = logging.handlers.SysLogHandler(address = '/dev/log')
        logger.addHandler(handler)
        logger.critical("test")

The "test" message is logged correctly but the actual output of all other loggers is not shown in the syslog. I guess the reason for this that the loggers are created when the LaunchDescription is executed.

So my question is: How can a add an additional handler to every logger created by ros2 launch in order to write all log messages which are written to launch.log also to the syslog.