summaryrefslogtreecommitdiff
path: root/lib/mixlib
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2019-08-06 20:51:22 -0700
committerTim Smith <tsmith84@gmail.com>2019-08-06 20:51:22 -0700
commit1d60af72a9e1cfa7155bf42bcba6b0f25e863324 (patch)
tree1c4eb7d73f14fe0622e4fc48ec5eccab14107fe2 /lib/mixlib
parentb7a37d62fca4252b0c80774adaa7f07a36d745fb (diff)
downloadmixlib-log-1d60af72a9e1cfa7155bf42bcba6b0f25e863324.tar.gz
Chefstyle fixes
Signed-off-by: Tim Smith <tsmith@chef.io>
Diffstat (limited to 'lib/mixlib')
-rw-r--r--lib/mixlib/log.rb10
-rw-r--r--lib/mixlib/log/child.rb4
-rw-r--r--lib/mixlib/log/formatter.rb2
-rw-r--r--lib/mixlib/log/logger.rb6
-rw-r--r--lib/mixlib/log/logging.rb2
5 files changed, 14 insertions, 10 deletions
diff --git a/lib/mixlib/log.rb b/lib/mixlib/log.rb
index e57ffcd..d15663c 100644
--- a/lib/mixlib/log.rb
+++ b/lib/mixlib/log.rb
@@ -61,7 +61,7 @@ module Mixlib
if other.respond_to?(:loggers) && other.respond_to?(:logger)
@loggers = other.loggers
@logger = other.logger
- elsif other.kind_of?(Array)
+ elsif other.is_a?(Array)
@loggers = other
@logger = other.first
else
@@ -82,7 +82,7 @@ module Mixlib
def init(*opts)
reset!
@logger = logger_for(*opts)
- @logger.formatter = Mixlib::Log::Formatter.new() if @logger.respond_to?(:formatter=)
+ @logger.formatter = Mixlib::Log::Formatter.new if @logger.respond_to?(:formatter=)
@logger.level = Logger::WARN
@configured = true
@parent = nil
@@ -110,6 +110,7 @@ module Mixlib
def level=(new_level)
level_int = LEVEL_NAMES.key?(new_level) ? new_level : LEVELS[new_level]
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
@@ -125,7 +126,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.
- [:trace?, :debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
+ %i{trace? debug? info? warn? error? fatal?}.each do |method_name|
define_method(method_name) do
logger.send(method_name)
end
@@ -137,7 +138,7 @@ module Mixlib
def add(severity, message = nil, progname = nil, data: {}, &block)
message, progname, data = yield if block_given?
- data = metadata.merge(data) if metadata.kind_of?(Hash) && data.kind_of?(Hash)
+ data = metadata.merge(data) if metadata.is_a?(Hash) && data.is_a?(Hash)
loggers.each do |l|
# if we don't have any metadata, let's not do the potentially expensive
# merging and managing that this call requires
@@ -193,6 +194,7 @@ module Mixlib
# to get access to it.
next unless logger.instance_variable_defined?(:"@logdev")
next unless (logdev = logger.instance_variable_get(:"@logdev"))
+
loggers_to_close << logger if logdev.filename
end
loggers_to_close
diff --git a/lib/mixlib/log/child.rb b/lib/mixlib/log/child.rb
index 56376c5..2d7de00 100644
--- a/lib/mixlib/log/child.rb
+++ b/lib/mixlib/log/child.rb
@@ -36,14 +36,14 @@ 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.
- [:trace?, :debug?, :info?, :warn?, :error?, :fatal?].each do |method_name|
+ %i{trace? debug? info? warn? error? fatal?}.each do |method_name|
define_method(method_name) do
parent.send(method_name)
end
end
def add(severity, message = nil, progname = nil, data: {}, &block)
- data = metadata.merge(data) if data.kind_of?(Hash)
+ data = metadata.merge(data) if data.is_a?(Hash)
parent.send(:pass, severity, message, progname, data: data, &block)
end
diff --git a/lib/mixlib/log/formatter.rb b/lib/mixlib/log/formatter.rb
index 1727452..680836f 100644
--- a/lib/mixlib/log/formatter.rb
+++ b/lib/mixlib/log/formatter.rb
@@ -31,7 +31,7 @@ module Mixlib
# Otherwise, doesn't print the time.
def call(severity, time, progname, msg)
if @@show_time
- sprintf("[%s] %s: %s\n", time.iso8601(), severity, msg2str(msg))
+ sprintf("[%s] %s: %s\n", time.iso8601, severity, msg2str(msg))
else
sprintf("%s: %s\n", severity, msg2str(msg))
end
diff --git a/lib/mixlib/log/logger.rb b/lib/mixlib/log/logger.rb
index f227f23..e1f8929 100644
--- a/lib/mixlib/log/logger.rb
+++ b/lib/mixlib/log/logger.rb
@@ -45,14 +45,16 @@ module Mixlib
def add_data(severity, message, progname, data: {})
return true if @logdev.nil? || severity < @level
+
data ||= {}
- if message.kind_of?(::Exception)
+ if message.is_a?(::Exception)
data[:err] = message
else
data[:msg] = message
end
@logdev.write(
- format_message(to_label(severity), Time.now, progname, data))
+ format_message(to_label(severity), Time.now, progname, data)
+ )
true
end
alias_method :add, :add_data
diff --git a/lib/mixlib/log/logging.rb b/lib/mixlib/log/logging.rb
index 524900b..5a7a076 100644
--- a/lib/mixlib/log/logging.rb
+++ b/lib/mixlib/log/logging.rb
@@ -41,7 +41,7 @@ module Mixlib
# Define the standard logger methods on this class programmatically.
# No need to incur method_missing overhead on every log call.
- [:trace, :debug, :info, :warn, :error, :fatal].each do |method_name|
+ %i{trace debug info warn error fatal}.each do |method_name|
level = LEVELS[method_name]
define_method(method_name) do |msg = nil, data: {}, &block|
pass(level, msg, data: data, &block)