Class: Entangler::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/entangler/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outputs, verbose: false) ⇒ Logger

Returns a new instance of Logger.



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/entangler/logger.rb', line 16

def initialize(outputs, verbose: false)
  @loggers = Array(outputs).map do |output|
    logger = ::Logger.new(output, 1, 10_485_760) # 10.megabytes.to_i

    logger.level = verbose ? ::Logger::DEBUG : ::Logger::INFO
    logger.formatter = proc do |severity, datetime, _, msg|
      date_format = datetime.strftime('%Y-%m-%d %H:%M:%S')
      "[#{date_format}] #{severity.rjust(5)}: #{msg}\n"
    end

    logger
  end
end

Class Method Details

.create_log_dir(base_dir) ⇒ Object



8
9
10
# File 'lib/entangler/logger.rb', line 8

def self.create_log_dir(base_dir)
  FileUtils.mkdir_p(File.dirname(log_file_path(base_dir)))
end

.log_file_path(base_dir, log_file_name = 'entangler.log') ⇒ Object



12
13
14
# File 'lib/entangler/logger.rb', line 12

def self.log_file_path(base_dir, log_file_name = 'entangler.log')
  File.join(base_dir, '.entangler', 'log', log_file_name)
end

Instance Method Details

#level=(level) ⇒ Object



30
31
32
# File 'lib/entangler/logger.rb', line 30

def level=(level)
  @loggers.each { |logger| logger.level = level }
end