Class: MCollective::Log

### Home Classes Methods

### In Files

- lib/mcollective/log.rb

### Parent

Object

### Methods

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

### Files

- COPYING
- README
- Rakefile
- PLACEHOLDER
- PLACEHOLDER

### Class/Module Index

Quicksearch

- MCollective
- MCollective::Agent
- MCollective::Agents
- MCollective::Aggregate
- MCollective::Aggregate::Base
- MCollective::Aggregate::Result
- MCollective::Aggregate::Result::Base
- MCollective::Aggregate::Result::CollectionResult
- MCollective::Aggregate::Result::NumericResult
- MCollective::Application
- MCollective::Applications
- MCollective::Client
- MCollective::Config
- MCollective::Connector
- MCollective::Connector::Base
- MCollective::DDL
- MCollective::DDLValidationError
- MCollective::Data
- MCollective::Data::Base
- MCollective::Data::Result
- MCollective::Discovery
- MCollective::Facts
- MCollective::Facts::Base
- MCollective::Generators
- MCollective::Generators::AgentGenerator
- MCollective::Generators::Base
- MCollective::Generators::DataGenerator
- MCollective::InvalidRPCData
- MCollective::Log
- MCollective::Logger
- MCollective::Logger::Base
- MCollective::Logger::Console_logger
- MCollective::Logger::File_logger
- MCollective::Logger::Syslog_logger
- MCollective::Matcher
- MCollective::Matcher::Parser
- MCollective::Matcher::Scanner
- MCollective::Message
- MCollective::MissingRPCData
- MCollective::MsgDoesNotMatchRequestID
- MCollective::MsgTTLExpired
- MCollective::NotTargettedAtUs
- MCollective::Optionparser
- MCollective::PluginManager
- MCollective::PluginPackager
- MCollective::PluginPackager::AgentDefinition
- MCollective::PluginPackager::StandardDefinition
- MCollective::RPC
- MCollective::RPC::ActionRunner
- MCollective::RPC::Agent
- MCollective::RPC::Audit
- MCollective::RPC::Client
- MCollective::RPC::Helpers
- MCollective::RPC::Progress
- MCollective::RPC::Reply
- MCollective::RPC::Request
- MCollective::RPC::Result
- MCollective::RPC::Stats
- MCollective::RPCAborted
- MCollective::RPCError
- MCollective::Registration
- MCollective::Registration::Base
- MCollective::Runner
- MCollective::RunnerStats
- MCollective::SSL
- MCollective::Security
- MCollective::Security::Base
- MCollective::SecurityValidationFailed
- MCollective::Shell
- MCollective::UnixDaemon
- MCollective::UnknownRPCAction
- MCollective::UnknownRPCError
- MCollective::Util
- MCollective::WindowsDaemon
- Array
- Dir
- Object
- String
- Symbol

No matching classes.

# MCollective::Log

A simple class that allows logging at various levels.

### Public Class Methods

configure(logger=nil) click to toggle source

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

    # File lib/mcollective/log.rb, line 72
    def configure(logger=nil)
      unless logger
        logger_type = "console"

        config = Config.instance

        if config.configured
          logger_type = config.logger_type
          @configured = true
        end

        require "mcollective/logger/#{logger_type.downcase}_logger"
        set_logger(eval("MCollective::Logger::#{logger_type.capitalize}_logger.new"))
      else
        set_logger(logger)
        @configured = true
      end

      @logger.start
    rescue Exception => e
      @configured = false
      STDERR.puts "Could not start logger: #{e.class} #{e}"
    end

cycle_level() click to toggle source

increments the active log level

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

debug(msg) click to toggle source

Logs at debug level

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

error(msg) click to toggle source

Logs at error level

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

fatal(msg) click to toggle source

Logs at fatal level

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

from() click to toggle source

figures out the filename that called us

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

info(msg) click to toggle source

Logs at info level

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

instance() click to toggle source

handle old code that relied on this class being a singleton

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

log(level, msg) click to toggle source

logs a message at a certain level

    # File lib/mcollective/log.rb, line 48
    def log(level, msg)
      configure unless @configured

      raise "Unknown log level" unless [:error, :fatal, :debug, :warn, :info].include?(level)

      if @logger
        @logger.log(level, from, msg)
      else
        t = Time.new.strftime("%H:%M:%S")

        STDERR.puts "#{t}: #{level}: #{from}: #{msg}"
      end
    end

logger() click to toggle source

Obtain the class name of the currently configured logger

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

set_logger(logger) click to toggle source

sets the logger class to use

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

warn(msg) click to toggle source

Logs at warn level

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.