lib/eco/api/common/session/logger.rb in eco-helpers-2.7.12 vs lib/eco/api/common/session/logger.rb in eco-helpers-2.7.13

- old
+ new

@@ -1,21 +1,24 @@ module Eco module API module Common module Session class Logger < Eco::Language::BasicLogger - TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S' + TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S'.freeze attr_reader :cache def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs) super(**kargs) - raise "Required Environment object (enviro:). Given: #{enviro}" if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment) + + msg = "Required Environment object (enviro:). Given: #{enviro.class}" + raise ArgumentError, msg if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment) + @enviro = enviro @cache = Logger::Cache.new - if log_file = fetch_log_file(log_file) + if (log_file = fetch_log_file(log_file)) loggers[:file] = ::Logger.new(log_file).tap do |logger| logger.formatter = format_proc(console: false) do |severity, datetime, msg, formatted_msg| cache.add(severity, datetime, msg, formatted_msg) end logger.level = file_level @@ -32,18 +35,19 @@ end private def config(attr) - return nil unless cnf = @enviro&.config&.logger + return unless (cnf = @enviro&.config&.logger) + cnf.send(attr) if cnf.respond_to?(attr) end def if_config(attr) - unless (value = config(attr)).nil? - yield(value) if block_given? - value - end + return if (value = config(attr)).nil? + + yield(value) if block_given? + value end def fetch_log_file(log_file) if log_file ||= config(:file) log_file = @enviro.file_manager.dir.file(log_file) if @enviro