Class: Log4r::Logger

### Home Classes Methods

### In Files

- lib/log4r/logger.rb
- lib/log4r/loggerfactory.rb
- lib/log4r/repository.rb
- lib/log4r/staticlogger.rb

### Parent

Object

### Methods

- ::[]
- ::each
- ::each_logger
- ::get
- ::global
- ::log_internal
- ::new
- ::root
- #==
- #add
- #additive=
- #is_root?
- #level=
- #levels
- #outputters=
- #parent=
- #remove
- #trace=

### Files

- GDC
- MDC
- NDC
- configurator
- emailoutputter
- formatter
- log4jxmlformatter
- log4r
- logger
- logserver
- outputter
- patternformatter
- scribeoutputter
- syslogoutputter
- win32eventoutputter
- yamlconfigurator

### Class/Module Index

Quicksearch

- Log4r
- Log4r::BasicFormatter
- Log4r::ConfigError
- Log4r::Configurator
- Log4r::DateFileOutputter
- Log4r::DefaultFormatter
- Log4r::EmailOutputter
- Log4r::FileOutputter
- Log4r::Formatter
- Log4r::GDC
- Log4r::IOOutputter
- Log4r::Log4jXmlFormatter
- Log4r::Log4rTools
- Log4r::LogEvent
- Log4r::LogServer
- Log4r::Logger
- Log4r::MDC
- Log4r::NDC
- Log4r::ObjectFormatter
- Log4r::Outputter
- Log4r::PatternFormatter
- Log4r::RemoteOutputter
- Log4r::RollingFileOutputter
- Log4r::RootLogger
- Log4r::ScribeOutputter
- Log4r::SimpleFormatter
- Log4r::StderrOutputter
- Log4r::StdoutOutputter
- Log4r::SyslogOutputter
- Log4r::UDPOutputter
- Log4r::YamlConfigurator
- REXML
- Object

No matching classes.

# Log4r::Logger

See log4r/logger.rb

### Attributes

additive[R]
fullname[R]
level[R]
name[R]
outputters[R]
parent[R]
path[R]
trace[R]

### Public Class Methods

[](_fullname) click to toggle source

Get a logger with a fullname from the repository or nil if logger wasn't found.

    # File lib/log4r/staticlogger.rb, line 12
    def self.[](_fullname)
      # forces creation of RootLogger if it doesn't exist yet.
      return RootLogger.instance if _fullname=='root' or _fullname=='global'
      Repository[_fullname]
    end

each() click to toggle source

Yields fullname and logger for every logger in the system.

    # File lib/log4r/staticlogger.rb, line 29
    def self.each
      for fullname, logger in Repository.instance.loggers
        yield fullname, logger
      end
    end

each_logger() click to toggle source

    # File lib/log4r/staticlogger.rb, line 35
    def self.each_logger
      Repository.instance.loggers.each_value {|logger| yield logger}
    end

get(_fullname) click to toggle source

Like Logger[] except that it raises NameError if Logger wasn't found.

    # File lib/log4r/staticlogger.rb, line 20
    def self.get(_fullname)
      logger = self[_fullname]
      if logger.nil?
        raise NameError, "Logger '#{_fullname}' not found.", caller
      end
      logger
    end

global() click to toggle source

Returns the root logger. Identical to Logger.root

    # File lib/log4r/staticlogger.rb, line 7
    def self.global; return root end

log_internal(level=1) click to toggle source

Internal logging for Log4r components. Accepts only blocks. To see such log events, create a logger named 'log4r' and give it an outputter.

    # File lib/log4r/staticlogger.rb, line 43
    def self.log_internal(level=1)
      internal = Logger['log4r']
      return if internal.nil?
      internal.send(LNAMES[level].downcase, yield)
    end

new(_fullname, _level=nil, _additive=true, _trace=false) click to toggle source

Logger requires a name. The last 3 parameters are:

level | Do I have a level? (Otherwise, I'll inherit my parent's)
additive | Am I additive?
trace | Do I record the execution trace? (slows things a wee bit)

    # File lib/log4r/logger.rb, line 26
    def initialize(_fullname, _level=nil, _additive=true, _trace=false)
      # validation
      raise ArgumentError, "Logger must have a name", caller if _fullname.nil?
      Log4rTools.validate_level(_level) unless _level.nil?
      validate_name(_fullname)

      # create the logger
      @fullname = _fullname
      @outputters = []
      @additive = _additive
      deal_with_inheritance(_level)
      LoggerFactory.define_methods(self)
      self.trace = _trace
      Repository[@fullname] = self
    end

root() click to toggle source

Returns the root logger. Identical to Logger.global

    # File lib/log4r/staticlogger.rb, line 5
    def self.root; return RootLogger.instance end

### Public Instance Methods

==(other) click to toggle source

    # File lib/log4r/logger.rb, line 145
    def ==(other)
      return true if self.object_id == other.object_id
    end

add(*_outputters) click to toggle source

Add outputters by name or by reference. Can be done any time.

    # File lib/log4r/logger.rb, line 119
    def add(*_outputters)
      for thing in _outputters
        o = (thing.kind_of?(Outputter) ? thing : Outputter[thing])
        # some basic validation
        if not o.kind_of?(Outputter)
          raise TypeError, "Expected kind of Outputter, got #{o.class}", caller
        elsif o.nil?
          raise TypeError, "Couldn't find Outputter '#{thing}'", caller
        end
        @outputters.push o
        Logger.log_internal {"Added outputter '#{o.name}' to '#{@fullname}'"}
      end
      @outputters
    end

additive=(_additive) click to toggle source

Set the additivity of the logger dynamically. True or false.

    # File lib/log4r/logger.rb, line 87
    def additive=(_additive)
      @additive = _additive
      LoggerFactory.define_methods(self)
      Logger.log_internal {"Logger '#{@fullname}' is additive"}
      @additive
    end

is_root?() click to toggle source

    # File lib/log4r/logger.rb, line 143
    def is_root?; false end

level=(_level) click to toggle source

Set the logger level dynamically. Does not affect children.

    # File lib/log4r/logger.rb, line 73
    def level=(_level)
      Log4rTools.validate_level(_level)
      @level = _level
      LoggerFactory.define_methods(self)
      Logger.log_internal {"Logger '#{@fullname}' set to #{LNAMES[@level]}"}
      @level
    end

levels() click to toggle source

Return array of defined levels.

    # File lib/log4r/logger.rb, line 82
    def levels
      LNAMES
    end

outputters=(_outputters) click to toggle source

Set the Outputters dynamically by name or reference. Can be done any time.

    # File lib/log4r/logger.rb, line 113
    def outputters=(_outputters)
      @outputters.clear
      add(*_outputters)
    end

parent=(parent) click to toggle source

Please don't reset the parent

    # File lib/log4r/logger.rb, line 107
    def parent=(parent)
      @parent = parent
    end

remove(*_outputters) click to toggle source

Remove outputters from this logger by name only. Can be done any time.

    # File lib/log4r/logger.rb, line 135
    def remove(*_outputters)
      for name in _outputters
        o = Outputter[name]
        @outputters.delete o
        Logger.log_internal {"Removed outputter '#{o.name}' from '#{@fullname}'"}
      end
    end

trace=(_trace) click to toggle source

Set whether the logger traces. Can be set dynamically. Defaults to false and understands the strings 'true' and 'false'.

    # File lib/log4r/logger.rb, line 96
    def trace=(_trace)
      @trace =
        case _trace
        when "true", true then true
        else false end
      LoggerFactory.define_methods(self)
      Logger.log_internal {"Logger '#{@fullname}' is tracing"} if @trace
      @trace
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.