Syslog is a standard for logging program messages. It allows separation of the software that generates messages from the system that stores them.
The traditional use of a syslog daemon is to store events in log files, in a format like this:
All the log files are in the
/var/log/ directory. You can explore the files
on your own machine an see the log messages for yourself.
Writing your own messages
Now, how can you log something with syslog? There is a command-line utility
suited just for the job –
logger . For instance:
will add something like
Logger is most useful for bash scripts, but while in C, you’d probably like to use something else. So let’s have look at some syscalls. Here is a very simple program, that will do the same as the logger command shown a couple lines back.
openlog() will establish a connection to the logging system. As
soon as it’s ready, you can start using
syslog() to save messages and in
the end you’ll need to close the connection by
closelog(). Fairly simple :-).
There are some parameters to the functions which are described in
or somewhere on the net.