class ManageIQ::Loggers::Journald
Attributes
syslog_identifier[RW]
An syslog identifier used when writing messages. The default is the progname.
Public Class Methods
new(logdev = nil, *args)
click to toggle source
Create and return a new ManageIQ::Loggers::Journald
instance. The arguments to the initializer can be ignored unless you're multicasting.
Internally we set our own formatter, and automatically set the progname option to 'manageiq' if not specified.
Calls superclass method
ManageIQ::Loggers::Base::new
# File lib/manageiq/loggers/journald.rb, line 13 def initialize(logdev = nil, *args) require "systemd-journal" super(logdev, *args) @formatter = Formatter.new @progname ||= 'manageiq' @syslog_identifier ||= @progname end
Public Instance Methods
add(severity, message = nil, progname = nil) { || ... }
click to toggle source
Redefine this method from the core Logger class. Internally this is the method used when .info, .warn, etc are called.
# File lib/manageiq/loggers/journald.rb, line 31 def add(severity, message = nil, progname = nil) severity ||= Logger::UNKNOWN return true if severity < @level progname ||= @progname if message.nil? if block_given? message = yield else message = progname progname = @progname end end message = formatter.call(format_severity(severity), progname, message) caller_object = caller_locations(3, 1).first Systemd::Journal.message( :message => message, :priority => log_level_map[severity], :syslog_identifier => syslog_identifier, :code_line => caller_object.lineno, :code_file => caller_object.absolute_path, :code_func => caller_object.label ) end
filename()
click to toggle source
Comply with the VMDB::Logger interface. For a filename we simply use the string 'journald' since we're not using a backing file directly.
# File lib/manageiq/loggers/journald.rb, line 24 def filename "journald" end
Private Instance Methods
log_level_map()
click to toggle source
Map the Systemd::Journal error levels to the Logger error levels. For unknown, we go with alert level.
# File lib/manageiq/loggers/journald.rb, line 64 def log_level_map @log_level_map ||= { Logger::UNKNOWN => Systemd::Journal::LOG_ALERT, Logger::FATAL => Systemd::Journal::LOG_CRIT, Logger::ERROR => Systemd::Journal::LOG_ERR, Logger::WARN => Systemd::Journal::LOG_WARNING, Logger::INFO => Systemd::Journal::LOG_INFO, Logger::DEBUG => Systemd::Journal::LOG_DEBUG, } end