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

Instance Attribute Summary collapse

Attributes inherited from Base

#log, #log_application, #log_environment, #log_host, #logger, #precision, #time_format

Instance Method Summary collapse

Methods inherited from Default

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

Methods inherited from Base

build_time_format, #pid

Constructor Details

#initialize(facility: ::Syslog::LOG_USER, level_map: LevelMap.new, max_size: Integer) ⇒ 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})


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

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

Instance Attribute Details

#facilityObject

Returns the value of attribute facility.



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

def facility
  @facility
end

#level_mapObject

Returns the value of attribute level_map.



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

def level_map
  @level_map
end

#max_sizeObject

Returns the value of attribute max_size.



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

def max_size
  @max_size
end

Instance Method Details

#call(log, logger) ⇒ Object



66
67
68
69
# File 'lib/semantic_logger/formatters/syslog.rb', line 66

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.



62
63
64
# File 'lib/semantic_logger/formatters/syslog.rb', line 62

def time
  nil
end