Heads up: This description was created by AI and might not be 100% accurate.
warn.rb
This Ruby code snippet demonstrates the use of the Logger
class for logging messages. It initializes a logger to STDOUT, sets the logging level to WARN, and then logs messages at different levels (WARN, INFO, DEBUG) demonstrating how the level setting affects what is actually logged to the console.
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:0x00007f0d50e26a30
puts "Level WARN"
Level WARN
#=> nil
logger.level = Logger::WARN # <= change level
#=> 2
logger.warn("Nothing to do!") # output
W, [2025-07-22T13:40:33.302916 #3036] WARN -- : Nothing to do!
#=> true
logger.info("Program started") # none
#=> true
logger.debug("Created logger") # none
#=> true
Executed with Ruby 3.4.5
.