Testing System Logging with logger
Before we leave the topic of system-logger configuration and use, we
should cover a tool that can be used to test your new configurations,
regardless of whether you use syslog or Syslog-ng:
logger
. logger
is a
command-line application that sends messages to the system logger. In
addition to being a good diagnostic tool, logger
is especially useful for adding logging functionality to shell
scripts.
The usage we’re interested in here, of course, is
diagnostics. It’s easiest to explain how to use
logger
with an example.
Suppose you’ve just reconfigured syslog to send all
daemon messages with priority
“warn” to
/var/log/warnings
. To test the new
syslog.conf
file, you’d first
restart syslogd
and klogd
and then you’d enter a command like the one in Example 10-22.
Example 10-22. Sending a test message with logger
mylinuxbox:~# logger -p daemon.warn "This is only a test."
As you can see, logger’s syntax is simple. The
-p
parameter allows you to specify a
facility.priority
selector. Everything after
this selector (and any other parameters or flags) is taken to be the
message.
Because I’m a fast typist, I often use
while...do...done
statements in interactive
bash
sessions to run impromptu scripts
(actually, just complex command lines). Example 10-23’s sequence of commands works
interactively or as a script.
Example 10-23. Generating test messages from a bash prompt
mylinuxbox:~#for i in {debug,info,notice,warning,err,crit,alert,emerg}
>do
>logger -p daemon.$i ...
Get Building Secure Servers with Linux now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.