Skip to content

Commit

Permalink
Remove obsolete Logger severity predicates
Browse files Browse the repository at this point in the history
The Logger severity predicates have existed since the [introduction of
Logger][1]. However, these methods only looked at the `level` instance
variable, so they did not work with the [thread safe implementation][2]
of temporary log levels in Rails.

Since then, the Logger severity predicates were [updated][3] to use the
`level` method instead of the instance variable, making Rails' severity
predicate overrides obsolete.

This commit removes Rails' custom severity predicates in favor of
Logger's implementation, since the new implementation was released in
Logger 1.4.2 and came bundled with Ruby 2.7.0.

[1]: ruby/logger@525b58d
[2]: rails/rails@629efb6
[3]: ruby/logger@7365c99
  • Loading branch information
skipkayhil committed Jun 15, 2024
1 parent 23729ce commit 6faf1ca
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ PATH
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger
logger (>= 1.4.2)
minitest (>= 5.1)
tzinfo (~> 2.0, >= 2.0.5)
rails (8.0.0.alpha)
Expand Down
2 changes: 1 addition & 1 deletion activesupport/activesupport.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ Gem::Specification.new do |s|
s.add_dependency "base64"
s.add_dependency "drb"
s.add_dependency "bigdecimal"
s.add_dependency "logger"
s.add_dependency "logger", ">= 1.4.2"
end
8 changes: 0 additions & 8 deletions activesupport/lib/active_support/logger_thread_safe_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@ module ActiveSupport
module LoggerThreadSafeLevel # :nodoc:
extend ActiveSupport::Concern

Logger::Severity.constants.each do |severity|
class_eval(<<-EOT, __FILE__, __LINE__ + 1)
def #{severity.downcase}? # def debug?
Logger::#{severity} >= level # DEBUG >= level
end # end
EOT
end

def local_level
IsolatedExecutionState[local_level_key]
end
Expand Down
20 changes: 20 additions & 0 deletions activesupport/test/broadcast_logger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,26 @@ def add(message_level, message = nil, progname = nil, &block)
@adds << [message_level, message, progname] if message_level >= local_level
end

def debug?
level <= ::Logger::DEBUG
end

def info?
level <= ::Logger::INFO
end

def warn?
level <= ::Logger::WARN
end

def error?
level <= ::Logger::ERROR
end

def fatal?
level <= ::Logger::FATAL
end

def close
@closed = true
end
Expand Down

0 comments on commit 6faf1ca

Please sign in to comment.