Class MCollective::Log
In: lib/mcollective/log.rb
Parent: Object

A simple singleton class that allows logging at various levels.

Methods

cycle_level   debug   error   fatal   info   new   warn  

Included Modules

Singleton

Public Class methods

[Source]

    # 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

Public Instance methods

cycles the log level increasing it till it gets to the highest then down to the lowest again

[Source]

    # 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

[Source]

    # File lib/mcollective/log.rb, line 75
75:         def debug(msg)
76:             log(Logger::DEBUG, msg)
77:         end

logs at level ERROR

[Source]

    # File lib/mcollective/log.rb, line 85
85:         def error(msg)
86:             log(Logger::ERROR, msg)
87:         end

logs at level FATAL

[Source]

    # File lib/mcollective/log.rb, line 80
80:         def fatal(msg)
81:             log(Logger::FATAL, msg)
82:         end

logs at level INFO

[Source]

    # File lib/mcollective/log.rb, line 65
65:         def info(msg)
66:             log(Logger::INFO, msg)
67:         end

logs at level WARN

[Source]

    # File lib/mcollective/log.rb, line 70
70:         def warn(msg)
71:             log(Logger::WARN, msg)
72:         end

[Validate]