From 89769d13c6ccd88332675eb8a2188f02d0377a4c Mon Sep 17 00:00:00 2001 From: Toshimitsu Takahashi Date: Thu, 29 Aug 2019 22:33:38 +0900 Subject: [PATCH 1/2] Fix broadcast if method is given block --- lib/ougai/logger.rb | 10 +++------- lib/ougai/logging.rb | 3 +-- spec/logger_spec.rb | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/ougai/logger.rb b/lib/ougai/logger.rb index 95f5229..545738d 100644 --- a/lib/ougai/logger.rb +++ b/lib/ougai/logger.rb @@ -38,13 +38,9 @@ def inherited(subclass) # @param logger [Logger] The logger receiving broadcast logs. def self.broadcast(logger) Module.new do |mdl| - Logger::Severity.constants.each do |severity| - method_name = severity.downcase.to_sym - - mdl.send(:define_method, method_name) do |*args| - logger.send(method_name, *args) - super(*args) - end + define_method(:log) do |*args| + logger.log(*args) + super(*args) end define_method(:level=) do |level| diff --git a/lib/ougai/logging.rb b/lib/ougai/logging.rb index a8d15f8..0e65636 100644 --- a/lib/ougai/logging.rb +++ b/lib/ougai/logging.rb @@ -107,8 +107,7 @@ def weak_merge!(base_data, inferior_data) end end - private - + # @private def log(severity, message, ex, data, block) return true if level > severity args = block ? block.call : [message, ex, data] diff --git a/spec/logger_spec.rb b/spec/logger_spec.rb index 52bc8b1..bdced75 100644 --- a/spec/logger_spec.rb +++ b/spec/logger_spec.rb @@ -645,7 +645,7 @@ def to_hash end it 'outputs info log with block on both loggers' do - logger.info(log_msg, foo: 2) + logger.info { [log_msg, { foo: 2 }] } expect(item).to be_log_message(log_msg, 30) expect(item).to include_data(foo: 2) expect(another_item).to be_log_message(log_msg, 30) From a10e188f0b88a0a6c140dd064d4f87c443734c8f Mon Sep 17 00:00:00 2001 From: Toshimitsu Takahashi Date: Thu, 29 Aug 2019 22:34:08 +0900 Subject: [PATCH 2/2] Fix not to destory data hash --- lib/ougai/formatters/readable.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ougai/formatters/readable.rb b/lib/ougai/formatters/readable.rb index 369d469..0092253 100644 --- a/lib/ougai/formatters/readable.rb +++ b/lib/ougai/formatters/readable.rb @@ -28,7 +28,8 @@ def initialize(app_name = nil, hostname = nil, opts = {}) load_dependent end - def _call(severity, time, progname, data) + def _call(severity, time, progname, _data) + data = _data.dup msg = data.delete(:msg) level = @plain ? severity : colored_level(severity) dt = format_datetime(time)