leszek.hanusz
leszek.hanusz

Reputation: 5327

How to test that a message has been sent to syslog

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.

Upvotes: 2

Views: 3487

Answers (2)

Toby Speight
Toby Speight

Reputation: 30928

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).

Upvotes: 2

Roman Pustylnikov
Roman Pustylnikov

Reputation: 1932

I believe you can retrieve the location from eiter /etc/rsyslog.conf or /etc/syslog.conf

As for the second question - you can grep <msg> /var/log/syslog* to look for it in every log including rotated.

You may want to add some unique running id in your messages in order to distinct from the previous message of the same content. It should be much easier to deal with than deleting the system logs.

Upvotes: 0

Related Questions