lib/legion/logging/builder.rb in legion-logging-1.1.2 vs lib/legion/logging/builder.rb in legion-logging-1.1.3
- old
+ new
@@ -1,9 +1,9 @@
module Legion
module Logging
module Builder
- def log_format(options = {}, log = @log) # rubocop:disable Metrics/AbcSize
+ def log_format(options = {}) # rubocop:disable Metrics/AbcSize
log.formatter = proc do |severity, datetime, _progname, msg|
options[:lex_name] = options.key?(:lex) ? "[lex-#{options[:lex]}]" : nil
unless options[:lex_name].nil?
data = caller_locations[4].to_s.split('/').last(2)
runner_trace = {
@@ -26,24 +26,44 @@
def output(options)
@log = ::Logger.new($stdout) if options[:log_file].nil?
@log = ::Logger.new(options[:log_file]) unless options[:log_file].nil?
end
- def log_level(level = 'info', log = @log)
- case level
- when 'trace'
- log.level = ::Logger::INFO
- when 'debug'
- log.level = ::Logger::DEBUG
- when 'info'
- log.level = ::Logger::INFO
- when 'warn'
- log.level = ::Logger::WARN
- when 'error'
- log.level = ::Logger::ERROR
- when 'fatal'
- log.level = ::Logger::FATAL
- end
+ def log
+ @log ||= set_log
+ end
+
+ def set_log(logfile: nil, **)
+ @log = logfile.nil? ? ::Logger.new($stdout) : ::Logger.new(logfile)
+ end
+
+ def level
+ log.level
+ end
+
+ def log_level(level = 'info')
+ log.level = case level
+ when 'trace'
+ ::Logger::DEBUG
+ when 'debug'
+ ::Logger::DEBUG
+ when 'info'
+ ::Logger::INFO
+ when 'warn'
+ ::Logger::WARN
+ when 'error'
+ ::Logger::ERROR
+ when 'fatal'
+ ::Logger::FATAL
+ when nil
+ 42
+ else
+ if level.is_a? Integer
+ level
+ else
+ 0
+ end
+ end
@log = log
end
end
end
end