Skip to content

Commit

Permalink
Ensure we only do a metadata write if required
Browse files Browse the repository at this point in the history
Signed-off-by: Thom May <thom@chef.io>
  • Loading branch information
Thom May committed Feb 15, 2018
1 parent 5c41d80 commit 17b91dd
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/mixlib/log.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ def <<(msg)

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)
Expand Down

0 comments on commit 17b91dd

Please sign in to comment.