Class: SemanticLogger::Formatters::Syslog

Inherits:
Default
  • Object
show all
Defined in:
lib/semantic_logger/formatters/syslog.rb

Defined Under Namespace

Classes: LevelMap

Constant Summary

Constants inherited from Base

Base::PRECISION, Base::TIME_FORMAT

Instance Attribute Summary collapse

Attributes inherited from Default

#log, #logger

Attributes inherited from Base

#log_application, #log_host, #time_format

Instance Method Summary collapse

Methods inherited from Default

#duration, #exception, #level, #message, #name, #named_tags, #payload, #process_info, #tags

Constructor Details

#initialize(facility: ::Syslog::LOG_USER, level_map: LevelMap.new) ⇒ Syslog

Create a Syslog Log Formatter

Parameters:

facility: [Integer]
  Default: ::Syslog::LOG_USER

level_map: [Hash | SemanticLogger::Formatters::Syslog::LevelMap]
  Supply a custom map of SemanticLogger levels to syslog levels.

Example:
  # Change the warn level to LOG_NOTICE level instead of a the default of LOG_WARNING.
  SemanticLogger.add_appender(appender: :syslog, level_map: {warn: ::Syslog::LOG_NOTICE})


53
54
55
56
57
# File 'lib/semantic_logger/formatters/syslog.rb', line 53

def initialize(facility: ::Syslog::LOG_USER, level_map: LevelMap.new)
  @facility  = facility
  @level_map = level_map.is_a?(LevelMap) ? level_map : LevelMap.new(level_map)
  super()
end

Instance Attribute Details

#facilityObject

Returns the value of attribute facility.



10
11
12
# File 'lib/semantic_logger/formatters/syslog.rb', line 10

def facility
  @facility
end

#level_mapObject

Returns the value of attribute level_map.



10
11
12
# File 'lib/semantic_logger/formatters/syslog.rb', line 10

def level_map
  @level_map
end

Instance Method Details

#call(log, logger) ⇒ Object



64
65
66
67
# File 'lib/semantic_logger/formatters/syslog.rb', line 64

def call(log, logger)
  message = super(log, logger)
  create_syslog_packet(message)
end

#timeObject

Time is part of the syslog packet and is not included in the formatted message.



60
61
62
# File 'lib/semantic_logger/formatters/syslog.rb', line 60

def time
  nil
end