Giter VIP home page Giter VIP logo

Comments (3)

kalmenius avatar kalmenius commented on June 15, 2024 1

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.

tilfin avatar tilfin commented on June 15, 2024

released v1.9.0 for this.

from ougai.

kalmenius avatar kalmenius commented on June 15, 2024

Thanks @tilfin! 👍

from ougai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.