10.3 Testing System Logging with loggerBefore 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 loggermylinuxbox:~# 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 promptmylinuxbox:~# for i in {debug,info,notice,warning,err,crit,alert,emerg} > do > logger -p daemon.$i "Test daemon message, level $I" > done This sends tests messages to the daemon facility for each of all eight priorities. Example 10-24, presented in the form of an actual script, generates messages for all facilities at each priority level. Example 10-24. Generating even more test messages with a bash script#!/bin/bash for i in {auth,auth-priv,cron,daemon,kern,lpr,mail,mark,news,syslog,user,uucp,local0, local1,local2,local3,local4,local5,local6,local7} # (this is all one line!) do for k in {debug,info,notice,warning,err,crit,alert,emerg} do logger -p $i.$k "Test daemon message, facility $i priority $k" done done Logger works with both syslog and Syslog-ng. |