Class: SemanticLogger::Formatters::SyslogCee

Inherits:
Raw
  • Object
show all
Defined in:
lib/semantic_logger/formatters/syslog_cee.rb

Instance Attribute Summary collapse

Attributes inherited from Raw

#hash, #log, #logger, #time_key

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Raw

#application, #duration, #exception, #host, #level, #message, #metric, #name, #named_tags, #payload, #process_info, #tags

Methods inherited from Base

#backtrace, #fast_tag, #level, #level=, #log, #measure, #payload, #pop_tags, #push_tags, #should_log?, #silence, #tagged, #tags, #with_payload

Constructor Details

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

CEE JSON Syslog format

Untested prototype code. Based on documentation only.
If this works for you, please let us know by opening an issue.

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:

# Log via udp to a remote syslog server on host: `server1` and port `8514`, using the CEE format.
SemanticLogger.add_appender(appender: :syslog, formatter: syslog_cee, url: 'udp://server1:8514')


26
27
28
29
30
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 26

def initialize(facility: ::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new)
  @facility  = facility
  @level_map = level_map.is_a?(SemanticLogger::Formatters::Syslog::LevelMap) ? level_map : SemanticLogger::Formatters::Syslog::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_cee.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_cee.rb', line 10

def level_map
  @level_map
end

Instance Method Details

#call(log, logger) ⇒ Object



36
37
38
39
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 36

def call(log, logger)
  hash = super(log, logger)
  create_syslog_packet("@cee: #{hash.to_json}")
end

#timeObject

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



33
34
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 33

def time
end