Module Logging
In: lib/logging.rb
lib/logging/appender.rb
lib/logging/config/yaml_configurator.rb
lib/logging/layout.rb
lib/logging/layouts/basic.rb
lib/logging/layouts/pattern.rb
lib/logging/log_event.rb
lib/logging/logger.rb
lib/logging/repository.rb
lib/logging/root_logger.rb

Methods

Classes and Modules

Module Logging::Appenders
Module Logging::Config
Module Logging::Layouts
Class Logging::Appender
Class Logging::Layout
Class Logging::LogEvent
Class Logging::Logger
Class Logging::Repository
Class Logging::RootLogger

Public Class methods

Configures the Logging framework using the configuration information found in the given file. The file extension should be either ’.yaml’ or ’.yml’ (XML configuration is not yet supported).

Defines the default obj_format method to use when converting objects into string representations for logging. obj_format can be one of :string, :inspect, or :yaml. These formatting commands map to the following object methods

  • :string => to_s
  • :inspect => inspect
  • :yaml => to_yaml

An ArgumentError is raised if anything other than +:string+, +:inspect+, +:yaml+ is passed to this method.

Defines the levels available to the loggers. The levels is an array of strings and symbols. Each element in the array is downcased and converted to a symbol; these symbols are used to create the logging methods in the loggers.

The first element in the array is the lowest logging level. Setting the logging level to this value will enable all log messages. The last element in the array is the highest logging level. Setting the logging level to this value will disable all log messages except this highest level.

This method should only be invoked once to configure the logging levels. It is automatically invoked with the default logging levels when the first logger is created.

The levels "all" and "off" are reserved and will be ignored if passed to this method.

Example:

   Logging.init :debug, :info, :warn, :error, :fatal
   log = Logging::Logger['my logger']
   log.level = :warn
   log.warn 'Danger! Danger! Will Robinson'
   log.info 'Just FYI'                        # => not logged

or

   Logging.init %w(DEBUG INFO NOTICE WARNING ERR CRIT ALERT EMERG)
   log = Logging::Logger['syslog']
   log.level = :notice
   log.warning 'This is your first warning'
   log.info 'Just FYI'                        # => not logged

Returns the library path for the module. If any arguments are given, they will be joined to the end of the libray path using File.join.

This convenience method returns a Logger instance configured to behave similarly to a core Ruby Logger instance.

The device is the logging destination. This can be a filename (String) or an IO object (STDERR, STDOUT, an open File, etc.). The age is the number of old log files to keep or the frequency of rotation (daily, weekly, or monthly). The size is the maximum logfile size and is only used when age is a number.

Using the same device twice will result in the same Logger instance being returned. For example, if a Logger is created using STDOUT then the same Logger instance will be returned the next time STDOUT is used. A new Logger instance can be obtained by closing the previous logger instance.

   log1 = Logging.logger(STDOUT)
   log2 = Logging.logger(STDOUT)
   log1.object_id == log2.object_id  #=> true

   log1.close
   log2 = Logging.logger(STDOUT)
   log1.object_id == log2.object_id  #=> false

The format of the log messages can be changed using a few optional parameters. The :pattern can be used to change the log message format. The :date_pattern can be used to change how timestamps are formatted.

   log = Logging.logger(STDOUT,
             :pattern => "[%d] %-5l : %m\n",
             :date_pattern => "%Y-%m-%d %H:%M:%S.%s")

See the documentation for the Logging::Layouts::Pattern class for a full description of the :pattern and :date_pattern formatting strings.

Returns the lpath for the module. If any arguments are given, they will be joined to the end of the path using File.join.

Utility method used to rquire all files ending in .rb that lie in the directory below this file that has the same name as the filename passed in. Optionally, a specific directory name can be passed in such that the filename does not have to be equivalent to the directory.

This method is used to show the configuration of the logging framework. The information is written to the given io stream (defaulting to stdout). Normally the configuration is dumped starting with the root logger, but any logger name can be given.

Each line contains information for a single logger and it‘s appenders. A child logger is indented two spaces from it‘s parent logger. Each line contains the logger name, level, additivity, and trace settings. Here is a brief example:

   root  ...........................   *info      -T
     LoggerA  ......................    info  +A  -T
       LoggerA::LoggerB  ...........    info  +A  -T
       LoggerA::LoggerC  ...........  *debug  +A  -T
     LoggerD  ......................   *warn  -A  +T

The lines can be deciphered as follows:

   1) name       - the name of the logger

   2) level      - the logger level; if it is preceeded by an
                   asterisk then the level was explicitly set for that
                   logger (as opposed to being inherited from the parent
                   logger)

   3) additivity - a "+A" shows the logger is additive, and log events
                   will be passed up to the parent logger; "-A" shows
                   that the logger will *not* pass log events up to the
                   parent logger

   4) trace      - a "+T" shows that the logger will include trace
                   information in generated log events (this includes
                   filename and line number of the log message; "-T"
                   shows that the logger does not include trace
                   information in the log events)

If a logger has appenders then they are listed, on per line, immediately below the logger. Appender lines are pre-pended with a single dash:

   root  ...........................   *info      -T
   - <Appenders::Stdout:0x8b02a4 name="stdout">
     LoggerA  ......................    info  +A  -T
       LoggerA::LoggerB  ...........    info  +A  -T
       LoggerA::LoggerC  ...........  *debug  +A  -T
     LoggerD  ......................   *warn  -A  +T
     - <Appenders::Stderr:0x8b04ca name="stderr">

We can see in this configuration dump that all the loggers will append to stdout via the Stdout appender configured in the root logger. All the loggers are additive, and so their generated log events will be passed up to the root logger.

The exception in this configuration is LoggerD. Its additivity is set to false. It uses its own appender to send messages to stderr.

Returns the version string for the library.

[Validate]