Home > Articles

  • Print
  • + Share This
This chapter is from the book



  • 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 sunfire 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 then can 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.

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.

The facilities are described in Table 4.7.

Table 4.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 system—lpr 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 4.8 lists recognized values for the syslog level field. They are listed in descending order of severity.

Table 4.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.

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 does 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 the book Solaris 10 System Administration Exam Prep: CX-310-200, Part I.

To stop or start syslogd, use the svcadm command with the appropriate parameter, enable or disable:

# svcadm enable -t system-log<cr>
# svcadm disable -t system-log<cr>

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 and then run the following command to cause the file to be reread by the syslogd daemon:

# svcadm refresh system-log<cr>

The first message in the log file 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 9—logadm, 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 4.9.

Table 4.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 4.7 and 4.8. 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.

For example, perhaps you have a simple shell script that backs up files:

tar cvf /tmp/backup  .
logger -p user.alert "Backups Completed"

The last line of the script uses the logger command to send a "Backups Completed" message to the default system log (/var/adm/messages). After running the script, I see the following message appended to the log file:

Jan 23 14:02:52 sunfire root: [ID 702911 user.alert] Backups Completed
  • + Share This
  • 🔖 Save To Your Account