summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2018-02-15 14:07:35 +0000
committerThom May <thom@chef.io>2018-02-15 14:13:13 +0000
commit17b91dd99492e6eb528bfa5049753287ac7fa2a5 (patch)
treea391a51c1721a64a8a2feb21f12c4da7243f1470 /lib
parent5c41d803a179dc0e8ac0a2548e794c3b6ef3bcf2 (diff)
downloadmixlib-log-17b91dd99492e6eb528bfa5049753287ac7fa2a5.tar.gz
Ensure we only do a metadata write if required
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/mixlib/log.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/mixlib/log.rb b/lib/mixlib/log.rb
index 2161568..0934f29 100644
--- a/lib/mixlib/log.rb
+++ b/lib/mixlib/log.rb
@@ -133,9 +133,11 @@ module Mixlib
def add(severity, message = nil, progname = nil, data: {}, &block)
message, progname, data = yield if block_given?
- data = metadata.merge(data) if data.kind_of?(Hash)
+ data = metadata.merge(data) if metadata.kind_of?(Hash) && data.kind_of?(Hash)
loggers.each do |l|
- if l.respond_to?(:add_data)
+ # if we don't have any metadata, let's not do the potentially expensive
+ # merging and managing that this call requires
+ if l.respond_to?(:add_data) && !data.nil? && !data.empty?
l.add_data(severity, message, progname, data: data)
else
l.add(severity, message, progname)