syslogObjective: Explain syslog function fundamentals and configure and manage the /etc/syslog.conf file and syslog messaging. A critical part of the system administrator's job is monitoring the system. Solaris uses the syslog message facility to do this. syslogd is the daemon responsible for capturing system messages. The messages can be warnings, alerts, or simply informational messages. As the system administrator, you customize syslog to specify where and how system messages are to be saved. The syslogd daemon receives messages from applications on the local host or from remote hosts and then directs messages to a specified log file. To each message that syslog captures, it adds a timestamp, the message type keyword at the beginning of the message, and a newline at the end of the message. For example, the following messages were logged in the /var/adm/messages file: July 15 23:06:39 ultra10 ufs: [ID 845546 kern.notice] NOTICE: alloc: /var: \ file system full Sep 1 04:57:06 docbert nfs: [ID 563706 kern.notice] NFS server saturn.east ok syslog enables you to capture messages by facility (the part of the system that generated the message) and by level of importance. Facility is considered to be the service area generating the message or error (such as printing, email, or network), whereas the level can be considered the level of severity (such as notice, warning, error, or emergency). syslog also enables you to forward messages to another machine so that all your messages can be logged in one location. The syslogd daemon reads and logs messages into a set of files described by the configuration file /etc/syslog.conf. When the syslogd daemon starts up, it preprocesses the /etc/syslog.conf file through the m4 macro processor to get the correct information for specific log files. syslogd does not read the /etc/syslog.conf file directly. syslogd starts m4, which parses the /etc/syslog.conf file for ifdef statements that can be interpreted by m4. The function ifdef is an integral part of m4 and identifies the system designated as LOGHOST. The macro is then able to evaluate whether log files are to be held locally or on a remote system, or a combination of both. If m4 doesn't recognize any m4 commands in the syslog.conf file, output is passed back to syslogd. syslogd then uses this output to route messages to appropriate destinations. When m4 encounters ifdef statements that it can process, the statement is evaluated for a true or false condition and the message is routed relative to the output of the test. Exam Alert /etc/syslog.conf and ifdef statements Make sure you become familiar with the facilities and values listed in the tables in this section. An exam question might provide a sample file and ask where a specific type of message, such as a failed login, will be logged. Also watch out for the ifdef statements to see if the logging is being carried out on a remote system. An entry in the /etc/syslog.conf file is composed of two fields: selector action The selector field contains a semicolon-separated list of priority specifications of this form: facility.level [ ; facility.level ] The action field indicates where to forward the message. Many defined facilities exist. Exam Alert Separate with Tabs The separator between the two fields must be a tab character. Spaces will not work and will give unexpected results. This is a very common mistake to make. The facilities are described in Table 11.7. Table 11.8 lists recognized values for the syslog level field. They are listed in descending order of severity. Note Levels Include All Higher Levels Too When you specify a syslog level, it means that the specified level and all higher levels. For example, if you specify the err level, then this will include crit, alert and emerg levels as well. Values for the action field can have one of four forms:
Blank lines are ignored. Lines in which the first nonwhitespace character is a # are treated as comments. All of this becomes much clearer when you look at sample entries from an /etc/syslog.conf file: *.err /dev/console *.err;daemon,auth.notice;mail.crit /var/adm/messages mail.debug /var/log/syslog *.alert root *.emerg * kern.err @server *.alert;auth.warning /var/log/auth In this example, the first line prints all errors on the console. The second line sends all errors, daemon and authentication system notices, and critical errors from the mail system to the file /var/adm/messages. The third line sends mail system debug messages to /var/log/syslog. The fourth line sends all alert messages to user root. The fifth line sends all emergency messages to all users. The sixth line forwards kernel messages of err (error) severity or higher to the machine named server. The last line logs all alert messages and messages of warning level or higher from the authorization system to the file /var/log/auth. The level none may be used to disable a facility. This is usually done in the context of eliminating messages. For example: *.debug;mail.none /var/adm/messages This selects debug messages and above from all facilities except those from mail. In other words, mail messages are disabled. The mail system, sendmail, logs a number of messages. The mail system can produce a large amount of information, so some system administrators disable mail messages or send them to another file that they clean out frequently. Before disabling mail messages, however, remember that sendmail messages come in very handy when you're diagnosing mail problems or tracking mail forgeries. As of Solaris 10, the mechanism for stopping, starting, and refreshing syslogd has changed. The syslog function is now under the control of the Service Management Facility (SMF), which is described in detail in Chapter 3. To stop or start syslogd, use the svcadm command with the appropriate parameter, enable or disable as follows: # svcadm enable t system-log # svcadm disable t system-log The syslog facility reads its configuration information from /etc/syslog.conf whenever it receives a refresh command from the service administration command, svcadm, and when the system is booted. You can make your changes to /etc/syslog.conf, then run the following command to cause the file to be re-read by the syslogd daemon: # svcadm refresh system-log Exam Alert No More kill -HUP Make sure you remember that the kill -HUP facility should no longer be used to try to cause a daemon process to re-read its configuration file, even though it still works. The svcadm refresh command is now the recommended way of achieving this. The first message in the logfile is logged by the syslog daemon itself to show when the process was started. syslog logs are automatically rotated on a regular basis. In previous Solaris releases, this was achieved by the program newsyslog. A new method of log rotation was introduced with Solaris 9logadm, a program normally run as a root-owned cron job. A configuration file /etc/logadm.conf is now used to manage log rotation and allows a number of criteria to be specified. See the logadm and logadm.conf manual pages for further details. Using the logger CommandThe logger command provides the means of manually adding one-line entries to the system logs from the command line. This is especially useful in shell scripts. The syntax for the logger command is as follows: logger [-i] [-f file] [-p priority] [-t tag] [message] ... Options to the logger command are described in Table 11.9.
As an example, to log a message to the default system log file stating that the backups have completed successfully, enter the following: logger "Backups Completed Successfully" |