Class: TxCatcher::Logger

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

Constant Summary collapse

LOG_LEVELS =
{
  info: 1,
  warn: 2,
  error: 3,
  fatal: 4,
  unknown: 5
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_file: "txcatcher.log", error_file: "error.log", error_log_delimiter: "\n\n", reporters: [:logfile, :stdout, :sentry]) ⇒ Logger

Returns a new instance of Logger.



15
16
17
18
19
20
# File 'lib/txcatcher/logger.rb', line 15

def initialize(log_file: "txcatcher.log", error_file: "error.log", error_log_delimiter: "\n\n", reporters: [:logfile, :stdout, :sentry])
  @log_file_name       = log_file
  @error_log_file_name = error_file
  @error_log_delimiter = error_log_delimiter
  @reporters           = reporters
end

Instance Attribute Details

#reportersObject

Returns the value of attribute reporters.



13
14
15
# File 'lib/txcatcher/logger.rb', line 13

def reporters
  @reporters
end

Instance Method Details

#report(message, log_level = :info, data: nil, timestamp: false, newline: "\n") ⇒ Object



23
24
25
26
27
28
29
# File 'lib/txcatcher/logger.rb', line 23

def report(message, log_level=:info, data: nil, timestamp: false, newline: "\n")
  @reporters.each do |out|
    if LOG_LEVELS[log_level] >= LOG_LEVELS[Config["logger"]["#{out}_level"].to_sym]
      send("report_to_#{out}", message, log_level, data: data, timestamp: timestamp, newline: newline)
    end
  end
end