info.rb
Heads up: This description was created by AI and might not be 100% accurate.
This Ruby code snippet demonstrates the use of the Logger
class for logging messages at different severity levels. It initializes a logger that outputs to STDOUT
, sets the logging level to INFO
, and then logs messages at WARN
, INFO
, and DEBUG
levels. Only WARN
and INFO
messages are displayed because the logger’s level is set to INFO
, filtering out DEBUG
messages. The output shows the severity level, timestamp, and the message itself.
Additional Note
Ref. https://docs.ruby-lang.org/ja/latest/library/logger.html
Ruby code snippet
require 'logger'
#=> true
logger = Logger.new(STDOUT)
#=>
#<Logger:0x00007f71ce3b1d60
puts "Level INFO"
Level INFO
#=> nil
logger.level = Logger::INFO # <= change level
#=> 1
logger.warn("Nothing to do!") # output
W, [2025-10-11T11:55:27.576402 #2927] WARN -- : Nothing to do!
#=> true
logger.info("Program started") # output
I, [2025-10-11T11:55:27.576891 #2927] INFO -- : Program started
#=> true
logger.debug("Created logger") # none
#=> true
Executed with Ruby 3.4.7
.