class SemanticLogger::Formatters::Syslog

Attributes

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

Public Class Methods

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

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

Public Instance Methods

call(log, logger) click to toggle source
# File lib/semantic_logger/formatters/syslog.rb, line 66
def call(log, logger)
  message = super(log, logger)
  create_syslog_packet(message)
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.rb, line 62
def time
  nil
end

Private Instance Methods

create_syslog_packet(message) click to toggle source

Create Syslog Packet

# File lib/semantic_logger/formatters/syslog.rb, line 74
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