Home > Articles > Certification > Other IT

This chapter is from the book

syslog

Objective

  • 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

Value

Description

user

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

kern

Messages generated by the kernel.

mail

The mail system.

daemon

System daemons, such as in.ftpd.

auth

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

lpr

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

news

Reserved for the Usenet network news system.

uucp

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

cron

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

audit

The audit facility, such as auditd.

local0-7

Reserved for local use.

mark

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

Value

Description

emerg

Panic conditions that would normally be broadcast to all users.

alert

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

crit

Warnings about critical conditions, such as hard device errors.

err

Other errors.

warning

Warning messages.

Notice

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.

info

Informational messages.

debug

Messages that are normally used only when debugging a program.

none

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

Option

Description

-i

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.

message

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:

#/bin/ksh
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

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020