Parent

Log4r::Logger

See log4r/logger.rb

Attributes

name[R]

(Not documented)

fullname[R]

(Not documented)

path[R]

(Not documented)

level[R]

(Not documented)

parent[R]

(Not documented)

additive[R]

(Not documented)

trace[R]

(Not documented)

outputters[R]

(Not documented)

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 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 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

(Not documented)

# File 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 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 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 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 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 log4r/staticlogger.rb, line 5
    def self.root; return RootLogger.instance end

Public Instance Methods

==(other) click to toggle source

(Not documented)

# File log4r/logger.rb, line 140
    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 log4r/logger.rb, line 114
    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 log4r/logger.rb, line 82
    def additive=(_additive)
      @additive = _additive
      LoggerFactory.define_methods(self)
      Logger.log_internal {"Logger '#{@fullname}' is additive"}
      @additive
    end
is_root?() click to toggle source

(Not documented)

# File log4r/logger.rb, line 138
    def is_root?; false end
level=(_level) click to toggle source

Set the logger level dynamically. Does not affect children.

# File 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
outputters=(_outputters) click to toggle source

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

# File log4r/logger.rb, line 108
    def outputters=(_outputters)
      @outputters.clear
      add(*_outputters)
    end
parent=(parent) click to toggle source

Please don’t reset the parent

# File log4r/logger.rb, line 102
    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 log4r/logger.rb, line 130
    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 log4r/logger.rb, line 91
    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

Private Instance Methods

deal_with_inheritance(_level) click to toggle source

Parses name for location in heiarchy, sets the parent, and deals with level inheritance

# File log4r/logger.rb, line 53
    def deal_with_inheritance(_level)
      mypath = @fullname.split Log4rConfig::LoggerPathDelimiter
      @name = mypath.pop
      if mypath.empty? # then root is my daddy
        @path = ""
        # This is one of the guarantees that RootLogger gets created
        @parent = Logger.root
      else
        @path = mypath.join(Log4rConfig::LoggerPathDelimiter)
        @parent = Repository.find_ancestor(@path)
        @parent = Logger.root if @parent.nil?
      end
      # inherit the level if no level defined
      if _level.nil? then @level = @parent.level
      else @level = _level end
      Repository.reassign_any_children(self)
    end
validate_name(_fullname) click to toggle source

(Not documented)

# File log4r/logger.rb, line 42
    def validate_name(_fullname)
      parts = _fullname.split Log4rConfig::LoggerPathDelimiter
      for part in parts
        raise ArgumentError, "Malformed path", caller[1..-1] if part.empty?
      end
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.