Class: Eco::API::Common::Session::Logger

Inherits:
Language::BasicLogger show all
Defined in:
lib/eco/api/common/session/logger.rb,
lib/eco/api/common/session/logger/log.rb,
lib/eco/api/common/session/logger/cache.rb

Defined Under Namespace

Classes: Cache, Log

Constant Summary collapse

TIMESTAMP_PATTERN =
'%Y-%m-%dT%H:%M:%S'.freeze

Constants inherited from Language::BasicLogger

Language::BasicLogger::LOG_LEVELS, Language::BasicLogger::METHODS

Instance Attribute Summary collapse

Attributes inherited from Language::BasicLogger

#level

Instance Method Summary collapse

Methods inherited from Language::BasicLogger

forward, #timestamp?

Constructor Details

#initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs) ⇒ Logger

Returns a new instance of Logger.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/eco/api/common/session/logger.rb', line 10

def initialize(file_level: ::Logger::DEBUG, log_file: nil, enviro: nil, **kargs)
  super(**kargs)

  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))
    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
    end
  end

  if_config(:timestamp_console) { |value| self.timestamp  = value }
  if_config(:console_level)     { |value| self.level      = value }
  if_config(:file_level)        { |value| self.file_level = value }
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



8
9
10
# File 'lib/eco/api/common/session/logger.rb', line 8

def cache
  @cache
end

Instance Method Details

#file_level=(value) ⇒ Object



34
35
36
# File 'lib/eco/api/common/session/logger.rb', line 34

def file_level=(value)
  loggers[:file]&.level = value
end