diff options
author | Thom May <thom@chef.io> | 2018-01-19 13:15:41 +0000 |
---|---|---|
committer | Thom May <thom@chef.io> | 2018-02-15 14:13:09 +0000 |
commit | 5c41d803a179dc0e8ac0a2548e794c3b6ef3bcf2 (patch) | |
tree | e6c2b51f50d241f0f3c9eb75681d7d1bd523b8f0 /lib/mixlib/log/child.rb | |
parent | 62249f18082129fb956804ecfa2f90529a6adc6d (diff) | |
download | mixlib-log-5c41d803a179dc0e8ac0a2548e794c3b6ef3bcf2.tar.gz |
add metadata to log messages
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib/mixlib/log/child.rb')
-rw-r--r-- | lib/mixlib/log/child.rb | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/lib/mixlib/log/child.rb b/lib/mixlib/log/child.rb index 2676b69..7234043 100644 --- a/lib/mixlib/log/child.rb +++ b/lib/mixlib/log/child.rb @@ -14,24 +14,23 @@ # See the License for the specific language governing permissions and # limitations under the License. +require "mixlib/log/logging" + module Mixlib module Log class Child - # include Mixlib::Log + include Mixlib::Log::Logging attr_reader :parent - def initialize(parent) + def initialize(parent, metadata = {}) @parent = parent + @metadata = metadata end def level parent.level end - def pass(severity, args, progname = nil, &block) - parent.pass(severity, args, progname, &block) - end - # Define the methods to interrogate the logger for the current log level. # Note that we *only* query the default logger (@logger) and not any other # loggers that may have been added, even though it is possible to configure @@ -39,23 +38,14 @@ module Mixlib [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name| class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) def #{method_name} - parent.#{method_name} + parent.send(:#{method_name}) end METHOD_DEFN end - # Define the standard logger methods on this class programmatically. - # No need to incur method_missing overhead on every log call. - [:debug, :info, :warn, :error, :fatal].each do |method_name| - class_eval(<<-METHOD_DEFN, __FILE__, __LINE__) - def #{method_name}(msg=nil, &block) - pass(:#{method_name}, msg, &block) - end - METHOD_DEFN - end - - def add(severity, message = nil, progname = nil, &block) - parent.pass(severity, message, progname, &block) + def add(severity, message = nil, progname = nil, data: {}, &block) + data = metadata.merge(data) if data.kind_of?(Hash) + parent.send(:pass, severity, message, progname, data: data, &block) end end |