Previous Page
Next Page



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.7. Recognized Values for Facilities




Messages generated by user processes. This is the default priority for messages from programs or facilities not listed in this file.


Messages generated by the kernel.


The mail system.


System daemons, such as in.ftpd.


The authorization system, such as login, su, getty, and others.


lpr is the syslogd facility responsible for generating messages from the line printer spooling systemlpr and lpc.


Reserved for the Usenet network news system.


Reserved for the UUCP system. It does not currently use the syslog mechanism.


The cron/at facility, such as crontab, at, cron, and others.


The audit facility, such as auditd.


Reserved for local use.


For timestamp messages produced internally by syslogd.


Indicates all facilities except the mark facility.

Table 11.8 lists recognized values for the syslog level field. They are listed in descending order of severity.

Table 11.8. Recognized Values for level




Panic conditions that would normally be broadcast to all users.


Conditions that should be corrected immediately, such as a corrupted system database.


Warnings about critical conditions, such as hard device errors.


Other errors.


Warning messages.


Conditions that are not error conditions but that might require special handling, such as a failed login attempt. A failed login attempt is considered a notice and not an error.


Informational messages.


Messages that are normally used only when debugging a program.


Does not send messages from the indicated facility to the selected file. For example, the entry *.debug;mail.none in /etc/syslog.conf sends all messages except mail messages to the selected file.


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:

  • A filename, beginning with a leading slash. This indicates that messages specified by the selector are to be written to the specified file. The file is opened in append mode and must already exist. syslog will not create the file if it doesn't already exist.

  • The name of a remote host, prefixed with a @. An example is @server, which indicates that messages specified by the selector are to be forwarded to syslogd on the named host. The hostname loghost is the hostname given to the machine that will log syslogd messages. Every machine is its own loghost by default. This is specified in the local /etc/hosts file. It is also possible to specify one machine on a network to be loghost by making the appropriate host table entries. If the local machine is designated as loghost, syslogd messages are written to the appropriate files. Otherwise, they are sent to the machine loghost on the network.

  • A comma-separated list of usernames, which indicates that messages specified by the selector are to be written to the named users if they are logged in.

  • An asterisk, which indicates that messages specified by the selector are to be written to all logged-in users.

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 Command

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

Table 11.9. logger Options




Logs the Process ID (PID) of the logger process with each line written to a log file.

-f <file>

Use the contents of file as the message to be logged.

-P <priority>

The message priority. This can be defined as a numeric value or as a facility.level pair as described in Tables 11.7 and 11.8 of this chapter. The default priority is user.notice.

-t <tag>

Marks each line with the specified tag.


One or more string arguments, separated by a single space character comprising the text of the message to be logged.

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"

Previous Page
Next Page