A linux program is sending logs to syslog.
To test this program automatically, I need to check that after some action has been done a message has been sent to syslog.
Unfortunately, the location of the syslog file is different depending on syslog configuration (/var/log/messages
on one computer, /var/log/syslog
on another computer and possibly other paths).
How can I know the current path of the syslog file programmatically ?
If I know the log path, how to detect the log message ? I could grep the log file and check the return value of the grep command but:
This test should also work with the busybox version of syslog.
Probably the best method is to interpose a shared library (using LD_PRELOAD
) in which you provide your own verifiable implementations of the syslog
functions for the purpose of your unit tests. You don't have to let the messages go to the installed syslog daemon at all (unless you want to).