3 # Implements a syslog based logger using the standard ruby syslog class
4 class Syslog_logger<Base
7 include Syslog::Constants
10 config = Config.instance
12 facility = syslog_facility(config.logfacility)
13 level = config.loglevel.to_sym
15 Syslog.close if Syslog.opened?
16 Syslog.open(File.basename($0), 3, facility)
21 def syslog_facility(facility)
23 Syslog.const_get("LOG_#{facility.upcase}")
25 STDERR.puts "Invalid syslog facility #{facility} supplied, reverting to USER"
30 def set_logging_level(level)
42 def log(level, from, msg)
43 Syslog.send(map_level(level), "#{from} #{msg}")
45 # if this fails we probably cant show the user output at all,
46 # STDERR it as last resort
47 STDERR.puts("#{level}: #{msg}")