summaryrefslogtreecommitdiff
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
parent17b91dd99492e6eb528bfa5049753287ac7fa2a5 (diff)
downloadmixlib-log-b28a6106ea8b6b7625077341964c3257679fcf59.tar.gz
add trace level
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--lib/mixlib/log.rb5
-rw-r--r--lib/mixlib/log/child.rb2
-rw-r--r--lib/mixlib/log/logging.rb16
-rw-r--r--spec/mixlib/log_spec.rb28
4 files changed, 33 insertions, 18 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)
diff --git a/spec/mixlib/log_spec.rb b/spec/mixlib/log_spec.rb
index ac4932d..137b557 100644
--- a/spec/mixlib/log_spec.rb
+++ b/spec/mixlib/log_spec.rb
@@ -38,7 +38,7 @@ class LoggerLike
@messages << message
end
- [:debug, :info, :warn, :error, :fatal].each do |method_name|
+ [:trace, :debug, :info, :warn, :error, :fatal].each do |method_name|
class_eval(<<-E)
def #{method_name}(message)
@messages << message
@@ -95,13 +95,14 @@ RSpec.describe Mixlib::Log do
expect(Logit.configured?).to be true
end
- it "should set the log level using the binding form, with :debug, :info, :warn, :error, or :fatal" do
+ it "should set the log level using the binding form, with :trace, :debug, :info, :warn, :error, or :fatal" do
levels = {
- :debug => Logger::DEBUG,
- :info => Logger::INFO,
- :warn => Logger::WARN,
- :error => Logger::ERROR,
- :fatal => Logger::FATAL,
+ :trace => Mixlib::Log::TRACE,
+ :debug => Mixlib::Log::DEBUG,
+ :info => Mixlib::Log::INFO,
+ :warn => Mixlib::Log::WARN,
+ :error => Mixlib::Log::ERROR,
+ :fatal => Mixlib::Log::FATAL,
}
levels.each do |symbol, constant|
Logit.level = symbol
@@ -117,13 +118,14 @@ RSpec.describe Mixlib::Log do
expect(logdev.string).to match(/the_message/)
end
- it "should set the log level using the method form, with :debug, :info, :warn, :error, or :fatal" do
+ it "should set the log level using the method form, with :trace, :debug, :info, :warn, :error, or :fatal" do
levels = {
- :debug => Logger::DEBUG,
- :info => Logger::INFO,
- :warn => Logger::WARN,
- :error => Logger::ERROR,
- :fatal => Logger::FATAL,
+ :trace => Mixlib::Log::TRACE,
+ :debug => Mixlib::Log::DEBUG,
+ :info => Mixlib::Log::INFO,
+ :warn => Mixlib::Log::WARN,
+ :error => Mixlib::Log::ERROR,
+ :fatal => Mixlib::Log::FATAL,
}
levels.each do |symbol, constant|
Logit.level(symbol)