open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: Local message processing with syslog

ITworld 1/8/2008

Sandra Henry-Stocker, ITworld.com

The syslog deamon (syslogd) on Unix systems provides message logging for other services so that each service doesn't have to duplicate the same basic functionality to manage logging for itself. The messages issued and their severity level depends on the applications, but where these messages are logged and how they are filtered when using the services of syslogd depends on how syslog is configured. The basic format of a line in syslog's configuration file specifies a message type and how messages matching the type will be handled.

For example, a line such as the one below tells syslogd to send informational messages from the line printer to the lpr.log file:

  lpr.info                                /var/log/lpr.log
This line doesn't just influence informational (low severity) messages, however. It also determines how lpr messages with higher severity levels will be logged.

One important thing to understand about syslog message before we get any further is that there is a clearly defined "level" for each message, the lower the numerical severity value, the more critical the message. An emergency message, for example, is level 0. This is the most critical message category. Debugging messages, on the other hand, are level 7, the lowest message level. The table below shows all 8 severity levels.

Message Type 	Description 			Syslog Message 	Severity Level
emergencies 	System unusable 			LOG_EMERG 	0
alerts 		Immediate action needed 	         LOG_ALERT 	1
critical 		Critical conditions 		LOG_CRIT 	         2
errors 		Error conditions 			LOG_ERR 	         3
warnings 		Warning conditions 		LOG_WARNING       4
notifications 	Normal but significant 		LOG_NOTICE 	5
informational 	Informational messagesonly 	         LOG_INFO 	         6
debugging 	Debugging messages 	         LOG_DEBUG 	7
If you elect to have all information messages for lpr logged, therefore, you will also log notifications, warnings, errors, critical messages, alerts and emergencies. If you elect to log only emergencies, on the other hand, none of the lower level messages will be logged.

Message types in the /etc/syslog.conf file are composed of two parts. The first part specifies the service or "facility" that is generating the messages and the second part is the level or severity of the message.

Facilities correspond to values specified in the openlog and syslog library routines, so you can't just make them up on the fly. However, besides the message types that correspond to familiar facilities -- such as mail, news, user, uucp, cron and so on, the local0 through local7 facilities are defined so that you can add custom message types for your own processing and configure syslogd to send them to whatever log file works best for you.

If a message facility is specified in the syslog.conf file with an asterisk (e.g., *.emerg), this means that all emergency messages will be selected for the specified treatment.

Any time you make a change to the syslog.conf file, you have to restart syslogd or send it a hangup. On some systems, you can do this with the "pkill -HUP syslogd" command.

Systems may log messages to a remote system's log files if the "loghost" variable is used in the syslog.conf file is used and refers to a remote system. Some sysadmins like to use this option because it keeps them from having to log into each system they manage to view log messages. Others prefer to have messages stay on the systems on which they were generated.

If you want to add local messages, you can to select the message facility you want to use (e.g., local0) and then make sure that your application sends it messages using with syslog calls to that facility.

Add a line such as this to /etc/syslog.conf

local0.err 					/var/log/testing
Once you've restart syslogd, you can test whether your new messaging facility is working using the logger command. If you're using local0, for example, the bash loop included in the script below will attempt to log local0.debug through local0.emerg messages. If your syslog.conf line looks like the one shown above, you should notice four new messages in your /var/log/testing file.

#!/usr/bin/bash
  # logmsgs: test syslog local0 processing

for i in debug info notice warn err crit alert emerg
do
    logger -t $i -p local0.$i $i
done
The output below shows the messages that would be generated by this script:

# ./logmsgs
  # tail -4 /var/log/testing
  Jan 10 12:01:54 boson err: [ID 702911 local0.error] err
  Jan 10 12:01:54 boson crit: [ID 702911 local0.crit] crit
  Jan 10 12:01:54 boson alert: [ID 702911 local0.alert] alert
  Jan 10 12:01:54 boson emerg: [ID 702911 local0.emerg] emerg
  
Don't be surprised that some of the messages will also be displayed on your screen. This is the normal system response for the higher severity messages.

Jan 10 12:01:54 boson alert: [ID 702911 local0.alert] alert
Jan 10 12:01:54 boson emerg: [ID 702911 local0.emerg] emerg
Message from syslogd@boson at Thu Jan 10 12:01:54 2008 ...
boson emerg: [ID1002911 local0.emerg] emerg

On this topic

 

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Multi-Core Test Results In Virtualized Servers
Check Out The Latest Xeon® Performance Results. Virtualized Servers vs. Non-Virtualized Servers.
Understanding VPN Technology Choices
Knowing the VPN options can help a manager work more effectively with available technologies.
Experience The Benefits Of Intel® vPro™ Technology
Get Built-In Security And Remote Management Capabilities. Meet Critical Business Challenges.
TRY MICROSOFT DYNAMICS® CRM Online FREE
Get Microsoft Dynamics CRM capabilities without the investment in IT infrastructure and staffing.
» Buy a link now

Advertisements
Sponsored links
KODAK i1400 Series Scanners stand up to the challenge
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Locate Hidden Software on business PCs with this free tool
Top 5 Reasons to Combine App Performance and Security
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.