launch
launch copied to clipboard
[Draft] Added syslog handler for launch log
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:
- Allow configuring the SysLogHandler (address, facility)
- Allow to disable/enable the SysLogHandler
- 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.
Just a quick push, as I would really like to progress on these patches :)
@clalancette assigned you to provide thoughts on Windows 🧇
@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)