Class: Bosh::Director::EventLog::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/event_log.rb

Overview

Job update (mysql_node): update |——– | (2/4) 50%

Instance Method Summary collapse

Constructor Details

#initialize(io = nil) ⇒ Log

Returns a new instance of Log.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bosh/director/event_log.rb', line 26

def initialize(io = nil)
  @logger = Logging::Logger.new('EventLog')
  if io.is_a?(String)
    @logger.add_appenders(Logging.appenders.file(
      'EventFile',
      filename: io,
      layout: Logging.layouts.pattern(:pattern => '%m\n')
    ))
  else
    @logger.add_appenders(Logging.appenders.io(
      'EventIO',
      io || StringIO.new,
      layout: Logging.layouts.pattern(:pattern => '%m\n')
    ))
  end
end

Instance Method Details

#begin_stage(stage_name, total = nil, tags = []) ⇒ Object



43
44
45
# File 'lib/bosh/director/event_log.rb', line 43

def begin_stage(stage_name, total = nil, tags = [])
  Stage.new(self, stage_name, tags, total)
end

#log_entry(entry) ⇒ Object



76
77
78
# File 'lib/bosh/director/event_log.rb', line 76

def log_entry(entry)
  @logger.info(JSON.generate(entry))
end

#log_error(error) ⇒ void

This method returns an undefined value.

Adds an error entry to the event log.

Parameters:



66
67
68
69
70
71
72
73
74
# File 'lib/bosh/director/event_log.rb', line 66

def log_error(error)
  @logger.info(JSON.generate(
    :time => Time.now.to_i,
    :error => {
      :code => error.error_code,
      :message => error.message,
    },
  ))
end

#warn(message) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/bosh/director/event_log.rb', line 55

def warn(message)
  log_entry(
    'time' => Time.now.to_i,
    'type' => 'warning',
    'message' => message
  )
end

#warn_deprecated(message) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/bosh/director/event_log.rb', line 47

def warn_deprecated(message)
  log_entry(
    'time' => Time.now.to_i,
    'type' => 'deprecation',
    'message' => message,
  )
end