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, #time_key

Attributes inherited from Base

#filter, #name

Instance Method Summary collapse

Methods inherited from Raw

#application, #duration, #environment, #exception, #file_name_and_line, #host, #level, #message, #metric, #name, #named_tags, #payload, #pid, #tags, #thread_name

Methods inherited from Base

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

Constructor Details

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


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

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

def max_size
  @max_size
end

Instance Method Details

#call(log, logger) ⇒ Object



38
39
40
41
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 38

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.



35
36
# File 'lib/semantic_logger/formatters/syslog_cee.rb', line 35

def time
end