- 1_8_6_287
- 1_8_7_72
- 1_8_7_330
- 1_9_1_378
- 1_9_2_180
- 1_9_3_125
- 1_9_3_392
- 2_1_10 (0)
- 2_2_9 (0)
- 2_4_6 (0)
- 2_5_5 (0)
- 2_6_3 (0)
- What's this?
Syslog::Logger is a Logger work-alike that logs via syslog instead of to a file. You can use Syslog::Logger to aggregate logs between multiple machines.
By default, Syslog::Logger uses the program name ‘ruby’, but this can be changed via the first argument to Syslog::Logger.new.
NOTE! You can only set the Syslog::Logger program name when you initialize Syslog::Logger for the first time. This is a limitation of the way Syslog::Logger uses syslog (and in some ways, a limitation of the way syslog(3) works). Attempts to change Syslog::Logger’s program name after the first initialization will be ignored.
Example
The following will log to syslogd on your local machine:
require 'syslog/logger' log = Syslog::Logger.new 'my_program' log.info 'this line will be logged via syslog(3)'
Also the facility may be set to specify the facility level which will be used:
log.info 'this line will be logged using Syslog default facility level' log_local1 = Syslog::Logger.new 'my_program', Syslog::LOG_LOCAL1 log_local1.info 'this line will be logged using local1 facility level'
You may need to perform some syslog.conf setup first. For a BSD machine add the following lines to /etc/syslog.conf:
!my_program *.* /var/log/my_program.log
Then touch /var/log/my_program.log and signal syslogd with a HUP (killall -HUP syslogd, on FreeBSD).
If you wish to have logs automatically roll over and archive, see the newsyslog.conf(5) and newsyslog(8) man pages.
Constants
LEVEL_MAP = { ::Logger::UNKNOWN => Syslog::LOG_ALERT, ::Logger::FATAL => Syslog::LOG_ERR, ::Logger::ERROR => Syslog::LOG_WARNING, ::Logger::WARN => Syslog::LOG_NOTICE, ::Logger::INFO => Syslog::LOG_INFO, ::Logger::DEBUG => Syslog::LOG_DEBUG, }
VERSION = '2.1.0'
Attributes
[RW] | facility |
The facility argument is used to specify what type of program is logging the message. |
||||||||
[RW] | formatter |
Logging formatter, as a Proc that will take four arguments and return the formatted message. The arguments are:
The block should return an Object that can be written to the logging device via write. The default formatter is used when no formatter is set. |
||||||||
[RW] | level |