Heads up: This description was created by AI and might not be 100% accurate.
info.rb
This Ruby code snippet demonstrates the usage of the Logger
class. It initializes a logger that writes to standard output, logs messages at different levels (INFO, WARN, INFO, DEBUG), and shows how to set the logging level. The code demonstrates logging messages with different levels and highlights the fact that debugging messages are not outputted.
Additional Note
Ref. https://docs.ruby-lang.org/ja/latest/library/logger.html
Ruby code snippet
require 'logger'
(irb):1: warning: logger was loaded from the standard library, but will no longer be part of the default gems starting from Ruby 3.5.0.
You can add logger to your Gemfile or gemspec to silence this warning.
#=> true
logger = Logger.new(STDOUT)
#=>
#<Logger:0x00007fa4c03e6810
puts "Level INFO"
Level INFO
#=> nil
logger.level = Logger::INFO # <= change level
#=> 1
logger.warn("Nothing to do!") # output
W, [2025-07-22T13:40:33.061679 #3033] WARN -- : Nothing to do!
#=> true
logger.info("Program started") # output
I, [2025-07-22T13:40:33.062137 #3033] INFO -- : Program started
#=> true
logger.debug("Created logger") # none
#=> true
Executed with Ruby 3.4.5
.