class Logger < ::Logger
- Inherits from
::Logger
A compatible interface for ::Logger which can be used with module Console.
Nested Classes and Modules
class LogDeviceA compatible log device which can be used with
module Console. Suitable for use with code which (incorrectly) assumes that the log device a public interface and has certain methods/behaviours.
Definitions
def initialize(subject, output = Console)
Create a new (compatible) logger.
Signature
-
parameter
subjectString The subject of the log messages.
-
parameter
outputConsole::Interface The output interface.
Implementation
def initialize(subject, output = Console)
super(nil)
@progname = subject
@logdev = LogDevice.new(subject, output)
end
def add(severity, message = nil, progname = nil, **options)
Log a message with the given severity.
Signature
-
parameter
severityInteger The severity of the message.
-
parameter
messageString The message to log.
-
parameter
prognameString The program name.
-
returns
Boolean True if the message was logged.
Implementation
def add(severity, message = nil, progname = nil, **options)
severity ||= UNKNOWN
if @logdev.nil? or severity < level
return true
end
if progname.nil?
progname = @progname
end
if message.nil?
if block_given?
message = yield
else
message = progname
progname = @progname
end
end
@logdev.call(
progname, message,
**options,
severity: format_severity(severity)
)
return true
end
def format_severity(value)
Format the severity.
Signature
-
parameter
valueInteger The severity value.
-
returns
Symbol The formatted severity.
Implementation
def format_severity(value)
super.downcase.to_sym
end