Class: Log4r::SyslogOutputter
- Includes:
- Syslog::Constants
- Defined in:
- lib/log4r/outputter/syslogoutputter.rb
Direct Known Subclasses
Constant Summary collapse
- SYSLOG_LEVELS_MAP =
maps default log4r levels to syslog priorities (logevents never see ALL and OFF) SYSLOG Levels are:
"DEBUG" => Syslog::LOG_DEBUG "INFO" => Syslog::LOG_INFO "NOTICE" => Syslog::LOG_NOTICE "WARN" => Syslog::LOG_WARN "ERROR" => Syslog::LOG_ERROR "FATAL" => Syslog::LOG_FATAL "ALERT" => Syslog::LOG_ALERT "EMERG" => Syslog::LOG_EMERG
{ "DEBUG" => LOG_DEBUG, "INFO" => LOG_INFO, "NOTICE" => LOG_NOTICE, # by default NOTICE is not in log4r "WARN" => LOG_WARNING, "ERROR" => LOG_ERR, "FATAL" => LOG_CRIT, "ALERT" => LOG_ALERT, # by default ALERT is not in log4r "EMERG" => LOG_EMERG, # by default EMERG is not in log4r }
- SYSLOG_LOG4R_MAP =
mapping from Log4r default levels to syslog, by string name “DEBUG” => “DEBUG”
"INFO" => "INFO" "WARN" => "WARN" "ERROR" => "ERROR" "FATAL" => "FATAL"
{ "DEBUG" => "DEBUG", "INFO" => "INFO", "WARN" => "WARN", "ERROR" => "ERROR", "FATAL" => "FATAL" # "NOTICE" => "INFO", # by default NOTICE is not in log4r # "ALERT" => "FATAL", # by default ALERT is not in log4r # "EMERG" => "FATAL" # by default EMERG is not in log4r }
Instance Attribute Summary
Attributes inherited from Outputter
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #get_levels_map ⇒ Object
-
#initialize(_name, hash = {}) ⇒ SyslogOutputter
constructor
There are 3 hash arguments.
-
#map_levels_by_name_to_syslog(lmap = SYSLOG_LOG4R_MAP) ⇒ Object
A single hash argument that maps custom names to syslog names.
Methods inherited from Outputter
[], []=, each, each_outputter, #flush, #only_at, stderr, stdout
Constructor Details
#initialize(_name, hash = {}) ⇒ SyslogOutputter
There are 3 hash arguments
:ident
-
syslog ident, defaults to _name
:logopt
-
syslog logopt, defaults to LOG_PID | LOG_CONS
:facility
-
syslog facility, defaults to LOG_USER
64 65 66 67 68 69 70 |
# File 'lib/log4r/outputter/syslogoutputter.rb', line 64 def initialize(_name, hash={}) super(_name, hash) @ident = (hash[:ident] or hash['ident'] or _name) @logopt = (hash[:logopt] or hash['logopt'] or LOG_PID | LOG_CONS).to_i @facility = (hash[:facility] or hash['facility'] or LOG_USER).to_i map_levels_by_name_to_syslog() end |
Instance Method Details
#close ⇒ Object
76 77 78 79 80 |
# File 'lib/log4r/outputter/syslogoutputter.rb', line 76 def close @level = OFF OutputterFactory.create_methods(self) Logger.log_internal {"Outputter '#{@name}' closed Syslog and set to OFF"} end |
#closed? ⇒ Boolean
72 73 74 |
# File 'lib/log4r/outputter/syslogoutputter.rb', line 72 def closed? @level == OFF end |
#get_levels_map ⇒ Object
104 105 106 |
# File 'lib/log4r/outputter/syslogoutputter.rb', line 104 def get_levels_map() return @levels_map end |
#map_levels_by_name_to_syslog(lmap = SYSLOG_LOG4R_MAP) ⇒ Object
A single hash argument that maps custom names to syslog names
[levels_map
] A map that will create a linkage between levels in a hash and underlying syslog levels. By default, these are direct mapping of the log4r levels (e.g. “DEBUG” => “DEBUG”) If you have defined your own custom levels, you should provide this underlying mapping, otherwise all messages will be mapped to the underlying syslog level of INFO by default. e.g. You have created custom levels called: Configurator.custom_levels "HIGH", "MEDIUM", "LOW"
To map these to ‘equivilent’ syslog levels, after instantiatin a syslogoutputter: SyslogOutputter.map_levels_by_name_to_syslog( { "HIGH" => "ALERT", "MEDIUM" => "WARN", "LOW" => "INFO" } )
100 101 102 |
# File 'lib/log4r/outputter/syslogoutputter.rb', line 100 def map_levels_by_name_to_syslog( lmap = SYSLOG_LOG4R_MAP ) @levels_map = lmap end |