Class: ActiveLogger::Formatters::Syslog
- Inherits:
-
Base
- Object
- ActiveSupport::Logger::Formatter
- Base
- ActiveLogger::Formatters::Syslog
- Defined in:
- lib/active_logger/formatters/syslog.rb
Overview
:nodoc:
Defined Under Namespace
Classes: LevelMap
Instance Attribute Summary collapse
-
#facility ⇒ Object
Returns the value of attribute facility.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#maxsize ⇒ Object
Returns the value of attribute maxsize.
Instance Method Summary collapse
- #call(severity, timestamp, progname, msg) ⇒ Object
-
#initialize(hostname: nil, facility: nil, maxsize: nil) ⇒ Syslog
constructor
A new instance of Syslog.
- #syslog_packet(tag:, content:, facility: nil, time: nil, severity: nil, host: nil, maxsize: nil) ⇒ Object
Methods inherited from Base
#clear_tags!, #current_tags, #default_progname, #pid, #pop_tags, #push_tags, #tagged, #tags_text
Constructor Details
#initialize(hostname: nil, facility: nil, maxsize: nil) ⇒ Syslog
Returns a new instance of Syslog.
27 28 29 30 31 |
# File 'lib/active_logger/formatters/syslog.rb', line 27 def initialize(hostname: nil, facility: nil, maxsize: nil) @hostname = hostname @facility = facility @maxsize = maxsize end |
Instance Attribute Details
#facility ⇒ Object
Returns the value of attribute facility.
9 10 11 |
# File 'lib/active_logger/formatters/syslog.rb', line 9 def facility @facility end |
#hostname ⇒ Object
Returns the value of attribute hostname.
9 10 11 |
# File 'lib/active_logger/formatters/syslog.rb', line 9 def hostname @hostname end |
#maxsize ⇒ Object
Returns the value of attribute maxsize.
9 10 11 |
# File 'lib/active_logger/formatters/syslog.rb', line 9 def maxsize @maxsize end |
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_logger/formatters/syslog.rb', line 33 def call(severity, , progname, msg) = "#{}#{msg}" program = progname || default_progname syslog_packet( tag: program.delete(' '), content: , time: , severity: LevelMap.new[severity], facility: @facility, maxsize: @maxsize || 1024, host: @hostname ) end |
#syslog_packet(tag:, content:, facility: nil, time: nil, severity: nil, host: nil, maxsize: nil) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/active_logger/formatters/syslog.rb', line 48 def syslog_packet(tag:, content:, facility: nil, time: nil, severity: nil, host: nil, maxsize: nil) packet = SyslogProtocol::Packet.new packet.hostname = host || `hostname`.chomp packet.facility = facility || 'user' packet.tag = tag packet.content = content packet.time = time packet.severity = severity || 'notice' maxsize ? packet.assemble(maxsize) : packet.assemble end |