Comments (3)
Below is the rough idea I had for a fix -- it has the added benefit of also introducing support for #log(...)
to Ougai loggers.
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
from ougai.
released v1.9.0 for this.
from ougai.
Thanks @tilfin! 👍
from ougai.
Related Issues (20)
- Switch from awesome_print to amazing_print to avoid deprecation warnings HOT 4
- Adding fields to logging within a block without using a child logger HOT 4
- Cannot load such file -- awesome_print when using logger.formatter = Ougai::Formatters::Readable.new HOT 4
- Getting issue for loading `Readable` object in production environment HOT 3
- Sidekiq instructions wiki is out of date HOT 1
- Ougai::Logger#add not compatible with Rails HOT 3
- Logging ANSI colors HOT 4
- How to make Oj optional HOT 7
- Option to add prefix to all logs HOT 3
- Log redaction HOT 1
- `after_initialize` is deprecated HOT 1
- json log formatter ignores with_newline flag when jsonize is false HOT 3
- How to log level as literal, not number HOT 1
- cannot load such file -- amazing_print (LoadError) HOT 2
- broadcast doesn't work with child
- Invalid JSON on not local env only
- ChildLogger does not define <<
- Sidekiq 7 compatibility and `.child` not returning an instance of the logger class HOT 1
- Customizing message keys HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ougai.