Class: Consul::Async::Debug

Inherits:
Object
  • Object
show all
Defined in:
lib/consul/async/debug.rb

Overview

Toolbox for logs

Class Method Summary collapse

Class Method Details

.levelObject



5
6
7
# File 'lib/consul/async/debug.rb', line 5

def self.level
  @level || 2
end

.level=(log_level) ⇒ Object



13
14
15
16
17
18
# File 'lib/consul/async/debug.rb', line 13

def self.level=(log_level)
  lvl = levels.index(log_level)
  raise "Log level #{log_level} unsupported, must be one of #{levels.inspect}" if lvl.nil?

  @level = lvl
end

.levelsObject



9
10
11
# File 'lib/consul/async/debug.rb', line 9

def self.levels
  %w[none error info debug]
end


39
40
41
42
43
44
# File 'lib/consul/async/debug.rb', line 39

def self.print_debug(msg)
  return unless level > 2

  STDERR.print "[DEBG] #{msg}"
  warn '' if ENV['LOG_STREAM']
end


28
29
30
31
32
33
# File 'lib/consul/async/debug.rb', line 28

def self.print_info(msg)
  return unless level > 1

  STDERR.print "[INFO] #{msg}" if level > 1
  warn '' if ENV['LOG_STREAM']
end

.puts_debug(msg) ⇒ Object



35
36
37
# File 'lib/consul/async/debug.rb', line 35

def self.puts_debug(msg)
  warn "[DEBG] #{msg}" if level > 2
end

.puts_error(msg) ⇒ Object



20
21
22
# File 'lib/consul/async/debug.rb', line 20

def self.puts_error(msg)
  warn "[ERROR] #{msg}" if level.positive?
end

.puts_info(msg) ⇒ Object



24
25
26
# File 'lib/consul/async/debug.rb', line 24

def self.puts_info(msg)
  warn "[INFO] #{msg}" if level > 1
end