Class: DoSnapshot::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/do_snapshot/log.rb

Overview

Shared logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Log

Returns a new instance of Log.



12
13
14
15
16
17
# File 'lib/do_snapshot/log.rb', line 12

def initialize(options = {})
  @verbose = DoSnapshot.config.verbose
  @quiet   = DoSnapshot.config.quiet
  options.each { |key, option| instance_variable_set(:"@#{key}", option) }
  instance.level = DoSnapshot.config.logger_level if instance
end

Instance Attribute Details

#bufferObject



23
24
25
# File 'lib/do_snapshot/log.rb', line 23

def buffer
  @buffer ||= %w()
end

#instanceObject



19
20
21
# File 'lib/do_snapshot/log.rb', line 19

def instance
  @instance ||= DoSnapshot.config.logger
end

#quietObject

Returns the value of attribute quiet.



9
10
11
# File 'lib/do_snapshot/log.rb', line 9

def quiet
  @quiet
end

#shellObject

Returns the value of attribute shell.



8
9
10
# File 'lib/do_snapshot/log.rb', line 8

def shell
  @shell
end

#verboseObject

Returns the value of attribute verbose.



9
10
11
# File 'lib/do_snapshot/log.rb', line 9

def verbose
  @verbose
end

Instance Method Details

#closeObject



31
32
33
# File 'lib/do_snapshot/log.rb', line 31

def close
  instance.close if instance
end

#log(severity, message = nil, progname = nil, &block) ⇒ Object



39
40
41
42
43
44
# File 'lib/do_snapshot/log.rb', line 39

def log(severity, message = nil, progname = nil, &block)
  buffer << message
  instance.add(severity, message, progname, &block) if instance

  say message, color(severity) unless print?(severity)
end