Class: Maze::Loggers::STDOUTLogger

Inherits:
Logger
  • Object
show all
Includes:
Singleton
Defined in:
lib/maze/loggers/stdout_logger.rb

Overview

A logger to STDOUT, with level configured according to the environment

Instance Attribute Summary collapse

Attributes inherited from Logger

#file_logger, #stdout_logger

Instance Method Summary collapse

Methods inherited from Logger

#method_missing

Constructor Details

#initializeSTDOUTLogger

Returns a new instance of STDOUTLogger.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/maze/loggers/stdout_logger.rb', line 13

def initialize
  if ENV['TRACE']
    super(STDOUT, level: ::Logger::TRACE)
  elsif ENV['DEBUG']
    super(STDOUT, level: ::Logger::DEBUG)
  elsif ENV['QUIET']
    super(STDOUT, level: ::Logger::ERROR)
  else
    super(STDOUT, level: ::Logger::INFO)
  end

  @datetime_format = '%H:%M:%S'

  @formatter = proc do |severity, time, _name, message|
    formatted_time = time.strftime(@datetime_format)

    "\e[2m[#{formatted_time}]\e[0m #{severity.rjust(5)}: #{message}\n"
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Maze::Loggers::Logger

Instance Attribute Details

#datetime_formatObject

Returns the value of attribute datetime_format.



11
12
13
# File 'lib/maze/loggers/stdout_logger.rb', line 11

def datetime_format
  @datetime_format
end