-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ChildLogger does not define #add #112
Comments
Below is the rough idea I had for a fix -- it has the added benefit of also introducing support for Please let me know if this makes sense for this gem. If so, I'm happy to work on a branch which also includes some new specs. diff --git a/lib/ougai/logger.rb b/lib/ougai/logger.rb
index 91632fa..c6f88cb 100644
--- a/lib/ougai/logger.rb
+++ b/lib/ougai/logger.rb
@@ -38,9 +38,9 @@ module Ougai
# @param logger [Logger] The logger receiving broadcast logs.
def self.broadcast(logger)
Module.new do |mdl|
- define_method(:log) do |*args|
- logger.log(*args)
- super(*args)
+ define_method(:log) do |*args, &block|
+ logger.log(*args, &block)
+ super(*args, &block)
end
define_method(:level=) do |level|
@@ -111,7 +111,7 @@ module Ougai
hooks.each do |hook|
return false if hook.call(data) == false
end
- add(severity, data)
+ method(:add).super_method.call(severity, data)
end
def to_item(args)
diff --git a/lib/ougai/logging.rb b/lib/ougai/logging.rb
index 0e65636..a93ccb8 100644
--- a/lib/ougai/logging.rb
+++ b/lib/ougai/logging.rb
@@ -28,7 +28,7 @@ module Ougai
# @return [Boolean] true
# @see Logging#debug
def trace(message = nil, ex = nil, data = nil, &block)
- log(TRACE, message, ex, data, block)
+ log(TRACE, message, ex, data, &block)
end
# Log any one or more of a message, an exception and structured data as DEBUG.
@@ -39,43 +39,42 @@ module Ougai
# @yieldreturn [String|Exception|Object|Array] Any one or more of former parameters
# @return [Boolean] true
def debug(message = nil, ex = nil, data = nil, &block)
- log(DEBUG, message, ex, data, block)
+ log(DEBUG, message, ex, data, &block)
end
# Log any one or more of a message, an exception and structured data as INFO.
# @return [Boolean] true
# @see Logging#debug
def info(message = nil, ex = nil, data = nil, &block)
- log(INFO, message, ex, data, block)
+ log(INFO, message, ex, data, &block)
end
# Log any one or more of a message, an exception and structured data as WARN.
# @return [Boolean] true
# @see Logging#debug
def warn(message = nil, ex = nil, data = nil, &block)
- log(WARN, message, ex, data, block)
+ log(WARN, message, ex, data, &block)
end
# Log any one or more of a message, an exception and structured data as ERROR.
# @return [Boolean] true
# @see Logging#debug
def error(message = nil, ex = nil, data = nil, &block)
- log(ERROR, message, ex, data, block)
+ log(ERROR, message, ex, data, &block)
end
# Log any one or more of a message, an exception and structured data as FATAL.
# @return [Boolean] true
# @see Logging#debug
def fatal(message = nil, ex = nil, data = nil, &block)
- log(FATAL, message, ex, data, block)
+ log(FATAL, message, ex, data, &block)
end
# Log any one or more of a message, an exception and structured data as UNKNOWN.
# @return [Boolean] true
# @see Logging#debug
def unknown(message = nil, ex = nil, data = nil, &block)
- args = block ? yield : [message, ex, data]
- append(UNKNOWN, args)
+ log(UNKNOWN, message, ex, data, &block)
end
# Whether the current severity level allows for logging TRACE.
@@ -107,11 +106,11 @@ module Ougai
end
end
- # @private
- def log(severity, message, ex, data, block)
+ public
+ def add(severity, *args)
return true if level > severity
- args = block ? block.call : [message, ex, data]
- append(severity, args)
+ append(severity, block_given? ? yield : args)
end
+ alias log add
end
end |
released v1.9.0 for this. |
Thanks @tilfin! 👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because
Ougai::ChildLogger
does not subclass Ruby's stdlibLogger
, I have run into issues when passing a "child" Ougai logger into a library which calls#add(...)
on the passed logger.A good example is in Bunny: https://github.com/ruby-amqp/bunny/blob/master/lib/bunny/transport.rb#L374
Here is a quick spec I prepared which illustrates the issue:
I think I have an idea for a clean fix if that would be helpful, but I wanted to see if this was intentional or not first.
Thanks very much! This is a great gem. 😃
The text was updated successfully, but these errors were encountered: