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

A simple class that allows logging at various levels.

Methods

configure   cycle_level   debug   error   fatal   from   info   instance   log   logger   set_logger   warn  

Public Class methods

configures the logger class, if the config has not yet been loaded we default to the console logging class and do not set @configured so that future calls to the log method will keep attempting to configure the logger till we eventually get a logging preference from the config module

[Source]

    # File lib/mcollective/log.rb, line 72
72:             def configure(logger=nil)
73:                 unless logger
74:                     logger_type = "console"
75: 
76:                     config = Config.instance
77: 
78:                     if config.configured
79:                         logger_type = config.logger_type
80:                         @configured = true
81:                     end
82: 
83:                     require "mcollective/logger/#{logger_type.downcase}_logger"
84:                     set_logger(eval("MCollective::Logger::#{logger_type.capitalize}_logger.new"))
85:                 else
86:                     set_logger(logger)
87:                     @configured = true
88:                 end
89: 
90: 
91:                 @logger.start
92:             rescue Exception => e
93:                 @configured = false
94:                 STDERR.puts "Could not start logger: #{e.class} #{e}"
95:             end

increments the active log level

[Source]

    # File lib/mcollective/log.rb, line 43
43:             def cycle_level
44:                 @logger.cycle_level if @configured
45:             end

Logs at debug level

[Source]

    # File lib/mcollective/log.rb, line 23
23:             def debug(msg)
24:                 log(:debug, msg)
25:             end

Logs at error level

[Source]

    # File lib/mcollective/log.rb, line 33
33:             def error(msg)
34:                 log(:error, msg)
35:             end

Logs at fatal level

[Source]

    # File lib/mcollective/log.rb, line 28
28:             def fatal(msg)
29:                 log(:fatal, msg)
30:             end

figures out the filename that called us

[Source]

     # File lib/mcollective/log.rb, line 98
 98:             def from
 99:                 from = File.basename(caller[2])
100:             end

Logs at info level

[Source]

    # File lib/mcollective/log.rb, line 13
13:             def info(msg)
14:                 log(:info, msg)
15:             end

handle old code that relied on this class being a singleton

[Source]

    # File lib/mcollective/log.rb, line 38
38:             def instance
39:                 self
40:             end

logs a message at a certain level

[Source]

    # File lib/mcollective/log.rb, line 48
48:             def log(level, msg)
49:                 configure unless @configured
50: 
51:                 raise "Unknown log level" unless [:error, :fatal, :debug, :warn, :info].include?(level)
52: 
53:                 if @logger
54:                     @logger.log(level, from, msg)
55:                 else
56:                     t = Time.new.strftime("%H:%M:%S")
57: 
58:                     STDERR.puts "#{t}: #{level}: #{from}: #{msg}"
59:                 end
60:             end

Obtain the class name of the currently configured logger

[Source]

    # File lib/mcollective/log.rb, line 8
 8:             def logger
 9:                 @logger.class
10:             end

sets the logger class to use

[Source]

    # File lib/mcollective/log.rb, line 63
63:             def set_logger(logger)
64:                 @logger = logger
65:             end

Logs at warn level

[Source]

    # File lib/mcollective/log.rb, line 18
18:             def warn(msg)
19:                 log(:warn, msg)
20:             end

[Validate]