| Class | MCollective::Log |
| In: |
lib/mcollective/log.rb
|
| Parent: | Object |
A simple singleton class that allows logging at various levels.
# File lib/mcollective/log.rb, line 8
8: def initialize
9: config = Config.instance
10: raise ("Configuration has not been loaded, can't start logger") unless config.configured
11:
12: @logger = Logger.new(config.logfile, config.keeplogs, config.max_log_size)
13: @logger.formatter = Logger::Formatter.new
14:
15: case config.loglevel
16: when "info"
17: @logger.level = Logger::INFO
18: when "warn"
19: @logger.level = Logger::WARN
20: when "debug"
21: @logger.level = Logger::DEBUG
22: when "fatal"
23: @logger.level = Logger::FATAL
24: when "error"
25: @logger.level = Logger::ERROR
26: else
27: @logger.level = Logger::INFO
28: log(Logger::ERROR, "Invalid log level #{config.loglevel}, defaulting to info")
29: end
30: end
cycles the log level increasing it till it gets to the highest then down to the lowest again
# File lib/mcollective/log.rb, line 34
34: def cycle_level
35: config = Config.instance
36:
37: case @logger.level
38: when Logger::FATAL
39: @logger.level = Logger::ERROR
40: error("Logging level is now ERROR configured level is #{config.loglevel}")
41:
42: when Logger::ERROR
43: @logger.level = Logger::WARN
44: warn("Logging level is now WARN configured level is #{config.loglevel}")
45:
46: when Logger::WARN
47: @logger.level = Logger::INFO
48: info("Logging level is now INFO configured level is #{config.loglevel}")
49:
50: when Logger::INFO
51: @logger.level = Logger::DEBUG
52: info("Logging level is now DEBUG configured level is #{config.loglevel}")
53:
54: when Logger::DEBUG
55: @logger.level = Logger::FATAL
56: fatal("Logging level is now FATAL configured level is #{config.loglevel}")
57:
58: else
59: @logger.level = Logger::DEBUG
60: info("Logging level now DEBUG configured level is #{config.loglevel}")
61: end
62: end
logs at level DEBUG
# File lib/mcollective/log.rb, line 75
75: def debug(msg)
76: log(Logger::DEBUG, msg)
77: end
logs at level ERROR
# File lib/mcollective/log.rb, line 85
85: def error(msg)
86: log(Logger::ERROR, msg)
87: end
logs at level FATAL
# File lib/mcollective/log.rb, line 80
80: def fatal(msg)
81: log(Logger::FATAL, msg)
82: end