1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/logger] Add support for changing severity using bang methods.

https://github.com/ruby/logger/commit/ae4c6dfcbb
This commit is contained in:
Samuel Williams 2019-03-15 12:12:11 +13:00 committed by Hiroshi SHIBATA
parent 310198d6be
commit 47500f2055
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
2 changed files with 26 additions and 0 deletions

View file

@ -322,22 +322,37 @@ class Logger
# +DEBUG+ messages.
def debug?; @level <= DEBUG; end
# Sets the severity to DEBUG.
def debug!; self.level = DEBUG; end
# Returns +true+ iff the current severity level allows for the printing of
# +INFO+ messages.
def info?; @level <= INFO; end
# Sets the severity to INFO.
def info!; self.level = INFO; end
# Returns +true+ iff the current severity level allows for the printing of
# +WARN+ messages.
def warn?; @level <= WARN; end
# Sets the severity to WARN.
def warn!; self.level = WARN; end
# Returns +true+ iff the current severity level allows for the printing of
# +ERROR+ messages.
def error?; @level <= ERROR; end
# Sets the severity to ERROR.
def error!; self.level = ERROR; end
# Returns +true+ iff the current severity level allows for the printing of
# +FATAL+ messages.
def fatal?; @level <= FATAL; end
# Sets the severity to FATAL.
def fatal!; self.level = FATAL; end
#
# :call-seq:
# Logger.new(logdev, shift_age = 0, shift_size = 1048576)

View file

@ -13,4 +13,15 @@ class TestLoggerSeverity < Test::Unit::TestCase
end
assert_equal(levels.size, Logger::Severity.constants.size)
end
def test_level_assignment
logger = Logger.new(nil)
Logger::Severity.constants.each do |level|
next if level == :UNKNOWN
logger.send("#{level.downcase}!")
assert(logger.level) == Logger::Severity.const_get(level)
end
end
end