Class: INat::App::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/inat/app/logging.rb

Defined Under Namespace

Modules: DSL

Instance Method Summary collapse

Constructor Details

#initialize(application) ⇒ Logger

Returns a new instance of Logger.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/inat/app/logging.rb', line 11

def initialize application
  @application = application
  v_para = {
    level: config[:verbose].severity
  }
  @verb = ::Logger::new STDERR, **v_para
  if config[:log][:enable]
    f_para = {
      level: config[:log][:level].severity,
    }
    f_para[:shift_age] = config[:log][:shift][:age] if config[:log][:shift][:age]
    f_para[:shift_level] = config[:log][:shift][:level] if config[:log][:shift][:level]
    @file = ::Logger::new config[:log][:file], **f_para
  else
    @file = nil
  end
end

Instance Method Details

#configObject



7
8
9
# File 'lib/inat/app/logging.rb', line 7

def config
  @application.config
end

#log(task, level, message) ⇒ Object



29
30
31
32
33
# File 'lib/inat/app/logging.rb', line 29

def log task, level, message
  task = task.name if task.respond_to?(:name)
  @verb.log(level.severity, message, task)
  @file.log(level.severity, message, task) if @file
end