lib/ecoportal/api/logger.rb in ecoportal-api-0.9.7 vs lib/ecoportal/api/logger.rb in ecoportal-api-0.10.0

- old
+ new

@@ -1,26 +1,28 @@ module Ecoportal module API class Logger - TIMESTAMP_PATTERN = "%Y-%m-%dT%H:%M:%S" - STDOUT_FORMAT_PROC = proc do |severity, datetime, progname, msg| - prefix = "%5s > " % severity + TIMESTAMP_PATTERN = "%Y-%m-%dT%H:%M:%S".freeze + + STDOUT_FORMAT_PROC = proc do |severity, _datetime, _progname, msg| + prefix = "%5s > " % severity # rubocop:disable Style/FormatString msg.lines.map.with_index do |line, idx| if idx.zero? prefix + line.chomp else - " "*prefix.length + line.chomp + (" " * prefix.length) + line.chomp end end.join("\n")+"\n" end - FILE_FORMAT_PROC = proc do |severity, datetime, progname, msg| - prefix = "%5s(%s) > " % [severity, datetime.strftime(TIMESTAMP_PATTERN)] + + FILE_FORMAT_PROC = proc do |severity, datetime, _progname, msg| + prefix = "%5s(%s) > " % [severity, datetime.strftime(TIMESTAMP_PATTERN)] # rubocop:disable Style/FormatString, Style/FormatStringToken msg.lines.map.with_index do |line, idx| if idx.zero? prefix + line.chomp else - " "*prefix.length + line.chomp + (" " * prefix.length) + line.chomp end end.join("\n")+"\n" end attr_reader :console, :file @@ -32,20 +34,20 @@ ) @console = make_stdout_logger(console_level) @file = make_file_logger(file_level, output_file) end - %w(unknown fatal error warn info debug).each do |type| + %w[unknown fatal error warn info debug].each do |type| define_method(type) do |&block| @console.send(type, &block) @file&.send(type, &block) end end private def make_stdout_logger(level) - ::Logger.new(STDOUT).tap do |logger| + ::Logger.new($stdout).tap do |logger| logger.formatter = STDOUT_FORMAT_PROC logger.level = level end end