Module: Helpers::Log

Included in:
AnsibleSpecPlus
Defined in:
lib/helpers/log.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.debug?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/helpers/log.rb', line 21

def debug?
  !@no_debug
end

.included(base) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/helpers/log.rb', line 36

def self.included(base)
  class << base
    def log
      Log.log
    end

    def log=(logger)
      Log.log=(logger)
    end

    def debug?
      Log.debug?
    end

    def set_debug(debug, level = Logger::INFO)
      Log.set_debug(debug, level)
    end

    def last_messages
      Log.last_messages
    end
  end
end

.last_messagesObject



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

def last_messages
  return [] unless @logger
  @logger.last_messages
end

.logObject



8
9
10
11
12
13
14
# File 'lib/helpers/log.rb', line 8

def log
  unless @logger
    @logger = BufferedLogger.new($stdout)
    @logger.formatter = ColorFormatter.new if $stdout.tty?
  end
  @logger
end

.log=(logger) ⇒ Object



16
17
18
19
# File 'lib/helpers/log.rb', line 16

def log=(logger)
  @logger = logger
  log.info('changed logger')
end

.set_debug(debug, level = ::Logger::INFO) ⇒ Object



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

def set_debug(debug, level = ::Logger::INFO)
  @no_debug = !debug
  log.level = level
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/helpers/log.rb', line 68

def debug?
  Log.debug?
end

#last_messagesObject



76
77
78
# File 'lib/helpers/log.rb', line 76

def last_messages
  Log.last_messages
end

#logObject



60
61
62
# File 'lib/helpers/log.rb', line 60

def log
  Log.log
end

#log=(logger) ⇒ Object



64
65
66
# File 'lib/helpers/log.rb', line 64

def log=(logger)
  Log.log=(logger)
end

#set_debug(debug, level = ::Logger::INFO) ⇒ Object



72
73
74
# File 'lib/helpers/log.rb', line 72

def set_debug(debug, level = ::Logger::INFO)
  Log.set_debug(debug, level)
end