summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2018-01-04 11:44:32 +0000
committerThom May <thom@chef.io>2018-02-22 09:59:23 +0000
commitb28a6106ea8b6b7625077341964c3257679fcf59 (patch)
treeaf1352af435dd1c7325531af580190cb0da5a39f /lib
parent17b91dd99492e6eb528bfa5049753287ac7fa2a5 (diff)
downloadmixlib-log-b28a6106ea8b6b7625077341964c3257679fcf59.tar.gz
add trace level
Signed-off-by: Thom May <thom@chef.io>
Diffstat (limited to 'lib')
-rw-r--r--lib/mixlib/log.rb5
-rw-r--r--lib/mixlib/log/child.rb2
-rw-r--r--lib/mixlib/log/logging.rb16
3 files changed, 18 insertions, 5 deletions
diff --git a/lib/mixlib/log.rb b/lib/mixlib/log.rb
index 0934f29..5bcb71d 100644
--- a/lib/mixlib/log.rb
+++ b/lib/mixlib/log.rb
@@ -94,6 +94,7 @@ module Mixlib
# Sets the level for the Logger object by symbol. Valid arguments are:
#
+ # :trace
# :debug
# :info
# :warn
@@ -103,7 +104,7 @@ module Mixlib
# Throws an ArgumentError if you feed it a bogus log level.
def level=(new_level)
level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level]
- raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if level_int.nil?
+ raise ArgumentError, "Log level must be one of :trace, :debug, :info, :warn, :error, or :fatal" if level_int.nil?
loggers.each { |l| l.level = level_int }
end
@@ -119,7 +120,7 @@ module Mixlib
# 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
# two (or more) loggers at different log levels.
- [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
+ [:trace?, :debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
def #{method_name}
logger.#{method_name}
diff --git a/lib/mixlib/log/child.rb b/lib/mixlib/log/child.rb
index 7234043..8f33daf 100644
--- a/lib/mixlib/log/child.rb
+++ b/lib/mixlib/log/child.rb
@@ -35,7 +35,7 @@ module Mixlib
# 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
# two (or more) loggers at different log levels.
- [:debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
+ [:trace?, :debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
def #{method_name}
parent.send(:#{method_name})
diff --git a/lib/mixlib/log/logging.rb b/lib/mixlib/log/logging.rb
index 0e8aed9..be84527 100644
--- a/lib/mixlib/log/logging.rb
+++ b/lib/mixlib/log/logging.rb
@@ -21,7 +21,19 @@ module Mixlib
module Log
module Logging
- LEVELS = { :debug => Logger::DEBUG, :info => Logger::INFO, :warn => Logger::WARN, :error => Logger::ERROR, :fatal => Logger::FATAL }.freeze
+ module Severity
+ include ::Logger::Severity
+ TRACE = -1
+
+ SEV_LABEL = %w{TRACE DEBUG INFO WARN ERROR FATAL ANY}.each(&:freeze).freeze
+
+ def to_label(sev)
+ SEV_LABEL[sev + 1] || -"ANY"
+ end
+ end
+ include Severity
+
+ LEVELS = { :trace => TRACE, :debug => DEBUG, :info => INFO, :warn => WARN, :error => ERROR, :fatal => FATAL }.freeze
LEVEL_NAMES = LEVELS.invert.freeze
attr_accessor :metadata
@@ -33,7 +45,7 @@ module Mixlib
# 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|
+ [:trace, :debug, :info, :warn, :error, :fatal].each do |method_name|
level = LEVELS[method_name]
class_eval(<<-METHOD_DEFN, __FILE__, __LINE__)
def #{method_name}(msg=nil, data: {}, &block)