launch icon indicating copy to clipboard operation
launch copied to clipboard

[Draft] Added syslog handler for launch log

Open firesurfer opened this issue 1 year ago • 8 comments

This PR adds initial support for writing to the syslog. It goes hand in hand with: https://github.com/ros2/rcl_logging/pull/105 In combination it allows to write the whole log a ros2 application creates to the syslog. Both PRs use 'local1' as facility which allows to redirect the whole log into a seperate log file or even a remote logging server without the need for additional configuration inside the ros2 logging system. (Everything can be configured in rsyslog.conf)

And also answers my question from #736

Why do we need it

In enterprise environments it can be desirable to store the whole application log on a remote logging server. Utilizing rsyslog for providing this functionality is an easy and established way.

Just grabbing /rosout won't suffice as we cannot grab all parts of the log.

What is missing so far:

  1. Allow configuring the SysLogHandler (address, facility)
  2. Allow to disable/enable the SysLogHandler
  3. Implement custom formatter / do not reuse the file_formatter

How to test it:

I redirected the 'local1' facility to /var/log/local1.log. This allows testing without spamming into your normal syslog.

sudo touch /var/log/local1.log
sudo chown syslog /var/log/local1.log

Edit /etc/rsyslog.d/50-default.conf And add the line:

local1.*                        -/var/log/local1.log

Restart rsyslog

sudo systemctl restart rsyslog.service 

Afterwards you should see the most basic output written into the file. Eg:

Oct 11 08:33:01 my_pc 1697005981.4697814 [INFO] [launch]: All log files can be found below /home/my_user/.ros/log/2023-10-11-08-33-01-469156-my_pc-2027270

Some additional notes

The current implementation grabs on purpose only the parts of the log which can't be grabbed via rcl_logging (https://github.com/ros2/rcl_logging/pull/105). Otherwise some log messages would occur twice in the syslog.

firesurfer avatar Oct 11 '23 06:10 firesurfer

Just a quick push, as I would really like to progress on these patches :)

firesurfer avatar Oct 25 '23 06:10 firesurfer

@clalancette assigned you to provide thoughts on Windows 🧇

sloretz avatar Nov 02 '23 21:11 sloretz

@clalancette As I already wrote in https://github.com/ros2/rcl_logging/pull/105 we could use the Event Log on Windows instead: https://docs.python.org/3/library/logging.handlers.html#nteventloghandler

Additionally if desired by the user we could support writing to a remote Syslog server (The python logging handler implementation supports this in contrast to spdlog)

logging.handlers.SysLogHandler(address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER, socktype=socket.SOCK_DGRAM)

firesurfer avatar Dec 19 '23 10:12 firesurfer