Class: Scoutui::Logger::LogMgr

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/scoutui/logger/log_mgr.rb

Constant Summary collapse

LOGLEVELS =
[ DEBUG = 0,  INFO = 1, WARN = 2, ERROR = 3, FATAL = 4]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogMgr

Returns a new instance of LogMgr.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/scoutui/logger/log_mgr.rb', line 16

def initialize

  @root = Logging.logger(STDOUT)
  @root.level = :debug
  @level = LOGLEVELS[DEBUG]

  Logging.appenders.stderr('Standard Error', :level => :error)

  # Logging.appenders.file('Command File', :filename => 'command.log')
  # Logging.logger['Commands'].appenders = 'Command File'

  @asserts = Logging.logger['Assertions']
  @asserts.add_appenders(
              Logging.appenders.stdout
  )
  @asserts.add_appenders(
              Logging.appenders.file("assertions.log")
  )

  @asserts.level = :debug

  @commands = Logging.logger['Commands']
  @commands.add_appenders(
               Logging.appenders.stdout,
               Logging.appenders.file('commands.log')
  )
  @commands.level = :debug


  @benchmarks = Logging.logger['Benchmarks']
  @benchmarks.add_appenders(
      Logging.appenders.stdout,
      Logging.appenders.file('benchmarks.log')
  )
  @benchmarks.level = :info

  #Logging.logger.root.level = :warn
end

Instance Attribute Details

#benchmarksObject

Returns the value of attribute benchmarks.



13
14
15
# File 'lib/scoutui/logger/log_mgr.rb', line 13

def benchmarks
  @benchmarks
end

#commandsObject

Returns the value of attribute commands.



12
13
14
# File 'lib/scoutui/logger/log_mgr.rb', line 12

def commands
  @commands
end

#levelObject

Returns the value of attribute level.



14
15
16
# File 'lib/scoutui/logger/log_mgr.rb', line 14

def level
  @level
end

#rootObject

Returns the value of attribute root.



11
12
13
# File 'lib/scoutui/logger/log_mgr.rb', line 11

def root
  @root
end

Instance Method Details

#assertsObject



55
56
57
# File 'lib/scoutui/logger/log_mgr.rb', line 55

def asserts
  @asserts
end

#benchmarkObject



112
113
114
# File 'lib/scoutui/logger/log_mgr.rb', line 112

def benchmark
  @benchmarks
end

#commandObject



59
60
61
# File 'lib/scoutui/logger/log_mgr.rb', line 59

def command
  @commands
end

#debug(txt) ⇒ Object



107
108
109
# File 'lib/scoutui/logger/log_mgr.rb', line 107

def debug(txt)
  log('debug', txt)
end

#err(txt) ⇒ Object



91
92
93
# File 'lib/scoutui/logger/log_mgr.rb', line 91

def err(txt)
  error(txt)
end

#error(txt) ⇒ Object



95
96
97
# File 'lib/scoutui/logger/log_mgr.rb', line 95

def error(txt)
  log('error', txt)
end

#fatal(txt) ⇒ Object



99
100
101
# File 'lib/scoutui/logger/log_mgr.rb', line 99

def fatal(txt)
  log('fatal', txt)
end

#info(txt) ⇒ Object



103
104
105
# File 'lib/scoutui/logger/log_mgr.rb', line 103

def info(txt)
  log('info', txt)
end

#log(level, txt) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/scoutui/logger/log_mgr.rb', line 120

def log(level, txt)

  if level.match(/debug/i)
    @root.debug txt if DEBUG >= @level
  elsif level.match(/info/i)
    @root.info txt  if INFO >= @level
  elsif level.match(/warn/i)
    @root.warn txt  if WARN >= @level
  elsif level.match(/error/i)
    @root.error txt if ERROR >= @level
  elsif level.match(/fatal/i)
    @root.fatal txt  if FATAL >= @level
  end

end

#setLevel(_level) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/scoutui/logger/log_mgr.rb', line 66

def setLevel(_level)

  @asserts.level = @benchmarks.level = @commands.level = @root.level = _level.to_sym

  _l = _level.to_s
  if _l.match(/debug/i)
    @level = LOGLEVELS[DEBUG]
  elsif _l.match(/info/i)
    @level = LOGLEVELS[INFO]
  elsif _l.match(/warn/i)
    @level = LOGLEVELS[WARN]
  elsif _l.match(/error/i)
    @level = LOGLEVELS[ERROR]
  elsif _l.match(/fatal/i)
    @level = LOGLEVELS[FATAL]
  else
    raise "UNKNOWN_LEVEL"
  end

end

#warn(txt) ⇒ Object



87
88
89
# File 'lib/scoutui/logger/log_mgr.rb', line 87

def warn(txt)
  log('warn', txt)
end