Method: Logmaster#initialize

Defined in:
lib/logmaster.rb

#initialize(log_level: Logger::INFO, file: nil, stdout: true, raise_exception: false, email_config: nil, logstash_config: nil, name: "Logmaster") ⇒ Logmaster

Returns a new instance of Logmaster.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/logmaster.rb', line 7

def initialize(
  log_level:       Logger::INFO,
  file:            nil,   # if nil, will not log into any file
  stdout:          true,  # if false, will not log into STDOUR
  raise_exception: false, # if true, will a raise an Exception after logging it
  email_config:    nil,   # see email config options for Pony gem
  logstash_config: nil,   # see https://github.com/dwbutler/logstash-logger#basic-usage
  name:            "Logmaster"
)

  @name            = name
  @raise_exception = raise_exception
  @log_level       = log_level
  @loggers         = []

  self.email_config = email_config if email_config
  @logstash_config = logstash_config

  @loggers << ::Logger.new(STDOUT)            if stdout
  @loggers << ::Logger.new(file, 10, 1024000) if file
  if logstash_config
    require 'logstash-logger'
    @loggers << LogStashLogger.new(**logstash_config)
  end
  @loggers.each { |l| l.level = @log_level }

end