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.



14
15
16
17
18
19
20
# File 'lib/do_snapshot/log.rb', line 14

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
  Hashie.logger = self
end

Instance Attribute Details

#bufferObject



26
27
28
# File 'lib/do_snapshot/log.rb', line 26

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

#instanceObject



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

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

#quietObject

Returns the value of attribute quiet.



11
12
13
# File 'lib/do_snapshot/log.rb', line 11

def quiet
  @quiet
end

#shellObject

Returns the value of attribute shell.



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

def shell
  @shell
end

#verboseObject

Returns the value of attribute verbose.



11
12
13
# File 'lib/do_snapshot/log.rb', line 11

def verbose
  @verbose
end

Instance Method Details

#closeObject



34
35
36
# File 'lib/do_snapshot/log.rb', line 34

def close
  instance.close if instance
end

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



42
43
44
45
46
47
# File 'lib/do_snapshot/log.rb', line 42

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