Class: MCollective::Logger::Syslog_logger
- Includes:
- Syslog::Constants
- Defined in:
- lib/mcollective/logger/syslog_logger.rb
Overview
Implements a syslog based logger using the standard ruby syslog class
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #log(level, from, msg) ⇒ Object
-
#set_logging_level(level) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #start ⇒ Object
- #syslog_facility(facility) ⇒ Object
- #valid_levels ⇒ Object
Methods inherited from Base
#cycle_level, #initialize, #reopen, #set_level
Constructor Details
This class inherits a constructor from MCollective::Logger::Base
Instance Method Details
#log(level, from, msg) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/mcollective/logger/syslog_logger.rb', line 40 def log(level, from, msg) Syslog.send(map_level(level), "#{from} #{msg}") if @known_levels.index(level) >= @known_levels.index(@active_level) rescue # if this fails we probably cant show the user output at all, # STDERR it as last resort warn("#{level}: #{msg}") end |
#set_logging_level(level) ⇒ Object
rubocop:disable Naming/AccessorMethodName
28 29 30 |
# File 'lib/mcollective/logger/syslog_logger.rb', line 28 def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName # noop end |
#start ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/mcollective/logger/syslog_logger.rb', line 9 def start config = Config.instance facility = syslog_facility(config.logfacility) level = config.loglevel.to_sym Syslog.close if Syslog.opened? Syslog.open(File.basename($0), 3, facility) set_level(level) end |
#syslog_facility(facility) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/mcollective/logger/syslog_logger.rb', line 21 def syslog_facility(facility) Syslog.const_get("LOG_#{facility.upcase}") rescue NameError warn "Invalid syslog facility #{facility} supplied, reverting to USER" Syslog::LOG_USER end |
#valid_levels ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/mcollective/logger/syslog_logger.rb', line 32 def valid_levels {:info => :info, :warn => :warning, :debug => :debug, :fatal => :crit, :error => :err} end |