End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
Logger#log
# File tmp/rubies/ruby-3.0.5/lib/logger.rb, line 459
def add(severity, message = nil, progname = nil)
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.write(
format_message(format_severity(severity), Time.now, progname, message))
true
end
Alias of #add
Args
severity-
Severity. Constants are defined in
Loggernamespace:DEBUG,INFO,WARN,ERROR,FATAL, orUNKNOWN. messageprogname-
Program name string. Can be omitted. Treated as a message if no
messageandblockare given. block-
Can be omitted. Called to get a message string if
messageis nil.
Return
When the given severity is not high enough (for this particular logger), log no message, and return true.
Description
Log a message if the given severity is high enough. This is the generic logging method. Users will be more inclined to use debug, info, warn, error, and fatal.
Message format: message can be any object, but it has to be converted to a String in order to log it. Generally, inspect is used if the given object is not a String. A special case is an Exception object, which will be printed in detail, including message, class, and backtrace. See msg2str for the implementation if required.
Bugs
-
Logfile is not locked.
-
Append open does not need to lock file.
-
If the OS supports multi I/O, records possibly may be mixed.