Improve compatibility between Logger
and ActiveSupport::BroadcastLogger
The usage of `dispatch` in all logging methods causes common usages such as `logger.info` to return an array of loggers, making it unsafe for an application to upgrade to Rails 7.1. Returning `nil` is more efficient, and is the default behavior when using `Logger`.
This commit is contained in:
parent
b9f814ad86
commit
a054307bbc
@ -229,6 +229,7 @@ def initialize_copy(other)
|
|||||||
private
|
private
|
||||||
def dispatch(&block)
|
def dispatch(&block)
|
||||||
@broadcasts.each { |logger| block.call(logger) }
|
@broadcasts.each { |logger| block.call(logger) }
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(name, ...)
|
def method_missing(name, ...)
|
||||||
|
@ -302,6 +302,11 @@ def info(msg, &block)
|
|||||||
assert_same logger, broadcast_logger.broadcasts.sole
|
assert_same logger, broadcast_logger.broadcasts.sole
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "logging has no return value" do
|
||||||
|
assert_equal true, @logger.info("Hello")
|
||||||
|
assert_equal true, @logger.error("Hello")
|
||||||
|
end
|
||||||
|
|
||||||
class CustomLogger
|
class CustomLogger
|
||||||
attr_reader :adds, :closed, :chevrons
|
attr_reader :adds, :closed, :chevrons
|
||||||
attr_accessor :level, :progname, :formatter, :local_level
|
attr_accessor :level, :progname, :formatter, :local_level
|
||||||
|
Loading…
Reference in New Issue
Block a user