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::CONTROL_CHARS, Base::CONTROL_CHAR_ESCAPES, Base::PRECISION

Instance Attribute Summary collapse

Attributes inherited from Base

#escape_control_chars, #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, escape_control_chars: true, **args) ⇒ 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.

escape_control_chars: [Boolean]
Replace control characters (newlines, the ANSI escape, etc.) in
untrusted log data with a printable escaped form so that they cannot
forge or split syslog records.
Default: true (unlike other formatters, since syslog frames records
with a separator)

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})


62
63
64
65
66
67
68
69
70
71
# File 'lib/semantic_logger/formatters/syslog.rb', line 62

def initialize(facility: ::Syslog::LOG_USER, level_map: LevelMap.new, max_size: Integer,
               escape_control_chars: true, **args)
  @facility  = facility
  @level_map = level_map.is_a?(LevelMap) ? level_map : LevelMap.new(**level_map)
  @max_size = max_size
  # Syslog frames records with a separator, so embedded newlines or other
  # control characters in untrusted log data can forge or split records.
  # Default to escaping them, overridable for backwards compatibility.
  super(escape_control_chars: escape_control_chars, **args)
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



78
79
80
81
# File 'lib/semantic_logger/formatters/syslog.rb', line 78

def call(log, logger)
  message = super
  create_syslog_packet(message)
end

#timeObject

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



74
75
76
# File 'lib/semantic_logger/formatters/syslog.rb', line 74

def time
  nil
end