setting up syslog for distributed application logging
syslog configurations vary in complexity from simple logging to local files to network based logging to a single centralized logging server (or set of logging servers).
terminology
here are some syslog terms you should be familiar with:- facility: a syslog facility is an application space for log segmentation. examples are
daemon, ftp, kern, lpr, mail. for application logging, you'll probably stick to the user defined facility spacelocal0throughlocal7. unfortunately, you can't add your own facilities. - priority: the priority tells you how important a message is, and can have the following values:
debug, info, notice, warning, crit, alert, emerg
preparing your syslog server
to prepare your server for remote logging, you need to givesyslogd the -r argument to tell it to accept distributed logging requests. you can do this by creating the following line in /etc/default/syslogd
SYSLOGD="-r -m0"-- MARK -- lines in the log.
next, choose a file where you'll want your application logs written to, and a facility that you'd like to use. add this configuration to /etc/syslog.conf, for example
# - application logging -
# log all local0's messages to /var/log/application
local0.* /var/log/applicationthe choice of user definied facility is somewhat arbitrary. local0 is a decent choice if you don't want to think about it.
now, restart your syslog daemon.
# /etc/init.d/sysklogd restartpreparing your application server
you are now ready to configure your application server's logging. syslog allows you to easily configure which priority messages get logged locally, which get logged remotely (and much more). see:# man 5 syslog.conf/etc/syslog.conf file:
# - application logging -
# log all application messages to the local /var/log/application and critical
# messages to the log server and the console
local0.* /var/log/application
local0.crit /dev/console
local0.crit @logservernote that my logging server's hostname is "logserver". don't forget to restart your syslog daemon after changing this file.
making some log statements
you can test your setup easily using syslog's shell interface,logger, see:
# man 1 loggerhere's a simple script that writes a couple of log statements:
#!/bin/bash
logger -p local0.crit "application1: your pants are on fire! `date "+%s"`"
logger -p local0.warn "application1: your pants are slightly warm `date "+%s"`"now take a look at the file /var/log/application on both your application server and your logging server. you'll see critical logs (pants on fire) in the log server, and all logs on the application server.
integration into other systems
most applications and programming have a syslog integration, and i won't bore you with the details. here are some links to illustrate the point:further reading
sometimes you want critical logging requests to be more "active" than a simple log statement written to a logfile. i've just written a short article describing how to get real time notification of critical syslog events by sms or email. you can find the article here.tech blog
- john's blog
- 3640 reads




delicious
digg
reddit
google
yahoo