lib/eco/api/common/session/logger.rb in eco-helpers-1.5.13 vs lib/eco/api/common/session/logger.rb in eco-helpers-1.5.14

- old
+ new

@@ -3,13 +3,16 @@ module Common module Session class Logger DEFAULT_TIMESTAMP_PATTERN = '%Y-%m-%dT%H:%M:%S' + attr_reader :cache + def initialize(console_level: nil, file_level: ::Logger::DEBUG, log_file: nil, timestamp_console: false, enviro: nil) raise "Required Environment object (enviro:). Given: #{enviro}" if enviro && !enviro.is_a?(Eco::API::Common::Session::Environment) @enviro = enviro + @cache = Logger::Cache.new timestamp_console = fetch_timestamp_console(timestamp_console) @console_logger = ::Logger.new(STDOUT).tap do |_logger| _logger.formatter = proc do |severity, datetime, progname, msg| str_timestamp = timestamp_console ? "#{datetime.strftime(DEFAULT_TIMESTAMP_PATTERN)} >" : "" @@ -19,11 +22,13 @@ end if log_file = fetch_log_file(log_file) @file_logger = ::Logger.new(log_file).tap do |_logger| _logger.formatter = proc do |severity, datetime, progname, msg| - "#{severity.to_s[0]}: #{datetime.strftime(DEFAULT_TIMESTAMP_PATTERN)} > #{msg}\n" + "#{severity.to_s[0]}: #{datetime.strftime(DEFAULT_TIMESTAMP_PATTERN)} > #{msg}\n".tap do |formatted| + cache.add(severity, datetime, msg, formatted) + end end _logger.level = fetch_file_level(file_level) end end end @@ -105,5 +110,8 @@ end end end end end + +require_relative "logger/cache" +require_relative "logger/log"