class SemanticLogger::Formatters::SyslogCee

Attributes

facility[RW]
level_map[RW]
max_size[RW]

Public Class Methods

new(facility: ::Syslog::LOG_USER, level_map: SemanticLogger::Formatters::Syslog::LevelMap.new, max_size: Integer) click to toggle source

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')
Calls superclass method SemanticLogger::Formatters::Raw::new
# 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

Public Instance Methods

call(log, logger) click to toggle source
Calls superclass method SemanticLogger::Formatters::Raw#call
# 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
time() click to toggle source

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

# File lib/semantic_logger/formatters/syslog_cee.rb, line 35
def time
end

Private Instance Methods

create_syslog_packet(message) click to toggle source

Create Syslog Packet

# File lib/semantic_logger/formatters/syslog_cee.rb, line 46
def create_syslog_packet(message)
  packet          = SyslogProtocol::Packet.new
  packet.hostname = logger.host
  packet.facility = facility
  packet.tag      = logger.application.delete(" ")
  packet.content  = message
  packet.time     = log.time
  packet.severity = level_map[log.level]
  packet.assemble(@max_size)
end