# logging-1.8.1 Documentation

by Tim Pease

- Homepage

- Github Project

- email tim dot pease at gmail dot com

## DESCRIPTION

Logging is a flexible logging library for use in Ruby programs based on the design of Java's log4j library. It features a hierarchical logging system, custom level names, multiple output destinations per log event, custom formatting, and more.

## INSTALL

    gem install logging

## EXAMPLE

This example configures a logger to output messages in a format similar to the core ruby Logger class. Only log messages that are warnings or higher will be logged.

    require 'logging'

    logger = Logging.logger(STDOUT)
    logger.level = :warn

    logger.debug "this debug message will not be output by the logger"
    logger.warn "this is your last warning"

In this example, a single logger is created that will append to STDOUT and to a file. Only log messages that are informational or higher will be logged.

    require 'logging'

    logger = Logging.logger['example_logger']
    logger.add_appenders(
        Logging.appenders.stdout,
        Logging.appenders.file('example.log')
    )
    logger.level = :info

    logger.debug "this debug message will not be output by the logger"
    logger.info "just some friendly advice"

The Logging library was created to allow each class in a program to have its own configurable logger. The logging level for a particular class can be changed independently of all other loggers in the system. This example shows the recommended way of accomplishing this.

    require 'logging'

    Logging.logger['FirstClass'].level = :warn
    Logging.logger['SecondClass'].level = :debug

    class FirstClass
      def initialize
        @logger = Logging.logger[self]
      end

      def some_method
        @logger.debug "some method was called on #{self.inspect}"
      end
    end

    class SecondClass
      def initialize
        @logger = Logging.logger[self]
      end

      def another_method
        @logger.debug "another method was called on #{self.inspect}"
      end
    end

There are many more examples in the "examples" folder of the logging package. The recommended reading order is the following:

- simple.rb

- rspec_integration.rb

- loggers.rb

- classes.rb

- hierarchies.rb

- names.rb

- lazy.rb

- appenders.rb

- layouts.rb

- formatting.rb

- colorization.rb

- consolidation.rb

- fork.rb

- mdc.rb

## NOTES

Although Logging is intended to supersede Log4r, it is not a one-to-one replacement for the Log4r library. Most notably is the difference in namespaces -- Logging vs. Log4r. Other differences include renaming Log4r::Outputter to Logging::Appender and renaming Log4r::Formatter to Logging::Layout. These changes were meant to bring the Logging class names more in line with the Log4j class names.

## REQUIREMENTS

The Logging source code relies on the Mr Bones project for default rake tasks. You will need to install the Mr Bones gem if you want to build or test the logging gem.

    gem install bones

After Mr Bones is installed you can install all the depdencies via the rake task.

    rake gem:install_dependencies

Always remember that "rake -T" is your friend!

## LICENSE

The MIT License

Copyright (c) 2012 Tim Pease

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Files

- History.txt
- README.rdoc

## Classes/Modules

- Logging
- Logging::Appender
- Logging::Appenders
- Logging::Appenders::Buffering
- Logging::Appenders::Email
- Logging::Appenders::File
- Logging::Appenders::Growl
- Logging::Appenders::IO
- Logging::Appenders::RollingFile
- Logging::Appenders::Stderr
- Logging::Appenders::Stdout
- Logging::Appenders::StringIo
- Logging::Appenders::Syslog
- Logging::ColorScheme
- Logging::Config
- Logging::Config::Configurator
- Logging::Config::Configurator::DSL
- Logging::Config::Configurator::Error
- Logging::Config::Configurator::TopLevelDSL
- Logging::Config::YamlConfigurator
- Logging::Config::YamlConfigurator::Error
- Logging::Layout
- Logging::Layouts
- Logging::Layouts::Basic
- Logging::Layouts::Parseable
- Logging::Layouts::Pattern
- Logging::Logger
- Logging::MappedDiagnosticContext
- Logging::NestedDiagnosticContext
- Logging::Proxy
- Logging::RailsCompat
- Logging::Repository
- Logging::Repository::Singleton
- Logging::RootLogger
- Logging::Stats
- Logging::Stats::Sampler
- Logging::Stats::Tracker
- RSpec
- RSpec::Core
- RSpec::Core::Configuration
- RSpec::LoggingHelper
- RSpec::LoggingHelper
- Spec
- Spec::Runner
- Spec::Runner::Configuration
- Object
- Object::LoggingHelper
- File
- FileUtils
- Hash
- Kernel
- Module
- ReentrantMutex
- String

## Methods

- ::[] — Logging::ColorScheme
- ::[]= — Logging::ColorScheme
- ::appenders — Logging
- ::assert_valid_logfile — Logging::Appenders::File
- ::backtrace — Logging
- ::basic — Logging::Layouts
- ::clear_diagnostic_contexts — Logging
- ::color_scheme — Logging
- ::concat — FileUtils
- ::configure — Logging
- ::consolidate — Logging
- ::email — Logging::Appenders
- ::file — Logging::Appenders
- ::format_as — Logging
- ::globally — Logging
- ::growl — Logging::Appenders
- ::init — Logging
- ::io — Logging::Appenders
- ::json — Logging::Layouts::Parseable
- ::json — Logging::Layouts
- ::keys — Logging::Stats::Sampler
- ::layouts — Logging
- ::libpath — Logging
- ::load — Logging::Config::YamlConfigurator
- ::logger — Logging
- ::mdc — Logging
- ::ndc — Logging
- ::new — Logging::Appenders::IO
- ::new — Logging::Appenders::RollingFile
- ::new — Logging::Appenders::Growl
- ::new — Logging::Appenders::StringIo
- ::new — Logging::Appenders::Buffering
- ::new — Logging::Appenders::File
- ::new — ReentrantMutex
- ::new — Logging::Appenders::Syslog
- ::new — Logging::Stats::Tracker
- ::new — Logging::Config::YamlConfigurator
- ::new — Logging::Appenders::Email
- ::new — Logging::Appenders::Stderr
- ::new — Logging::Appenders::Stdout
- ::new — Logging::Stats::Sampler
- ::new — Logging::Layouts::Parseable
- ::new — Logging::ColorScheme
- ::new — Logging::RootLogger
- ::new — Logging::Layouts::Pattern
- ::new — Logging::Repository
- ::new — Logging::Config::Configurator::TopLevelDSL
- ::new — Logging::Logger
- ::new — Logging::Proxy
- ::new — Logging::Appender
- ::new — Logging::Layout
- ::parseable — Logging::Layouts
- ::path — Logging
- ::pattern — Logging::Layouts
- ::process — Logging::Config::Configurator
- ::process — Logging::Config::Configurator::DSL
- ::reopen — Logging
- ::reset — Logging::ColorScheme
- ::rolling_file — Logging::Appenders
- ::root — Logging::Logger
- ::show_configuration — Logging
- ::stderr — Logging::Appenders
- ::stdout — Logging::Appenders
- ::string_io — Logging::Appenders
- ::syslog — Logging::Appenders
- ::version — Logging
- ::yaml — Logging::Layouts
- ::yaml — Logging::Layouts::Parseable
- #<< — Logging::Appender
- #<< — Logging::Logger
- #<< — Logging::NestedDiagnosticContext
- #<=> — Logging::RootLogger
- #<=> — Logging::Logger
- #[] — Logging::Appenders
- #[] — Logging::ColorScheme
- #[] — Logging::MappedDiagnosticContext
- #[] — Logging::Repository
- #[]= — Logging::ColorScheme
- #[]= — Logging::Repository
- #[]= — Logging::MappedDiagnosticContext
- #[]= — Logging::Appenders
- #__appenders — Logging::Config::Configurator::TopLevelDSL
- #__hash — Logging::Config::Configurator::DSL
- #__loggers — Logging::Config::Configurator::TopLevelDSL
- #__pre_config — Logging::Config::Configurator::TopLevelDSL
- #__store — Logging::Config::Configurator::DSL
- #add — Logging::Logger
- #add_appenders — Logging::Logger
- #add_master — Logging::Repository
- #additive= — Logging::Logger
- #append — Logging::Appender
- #appender — Logging::Config::Configurator::TopLevelDSL
- #appender — Logging::Config::Configurator
- #appender — Logging::Config::YamlConfigurator
- #appenders — Logging::Config::YamlConfigurator
- #appenders — Logging::Config::Configurator
- #appenders — Logging::Logger
- #appenders= — Logging::Logger
- #authentication= — Logging::Appenders::Email
- #auto_flushing= — Logging::Appenders::Buffering
- #capture_log_messages — RSpec::LoggingHelper
- #children — Logging::Repository
- #clear — Logging::MappedDiagnosticContext
- #clear — Logging::NestedDiagnosticContext
- #clear — Logging::Appenders::StringIo
- #clear_appenders — Logging::Logger
- #close — Logging::Appenders::IO
- #close — Logging::Appenders::Buffering
- #close — Logging::Appender
- #close — Logging::Appenders::Syslog
- #close — Logging::Appenders::Email
- #closed? — Logging::Appenders::Syslog
- #closed? — Logging::Appender
- #coalesce — Logging::Stats::Sampler
- #coalesce — Logging::Stats::Tracker
- #color — Logging::ColorScheme
- #configure_buffering — Logging::Appenders::Buffering
- #context — Logging::NestedDiagnosticContext
- #context — Logging::MappedDiagnosticContext
- #date_method= — Logging::Layouts::Pattern
- #date_pattern= — Logging::Layouts::Pattern
- #define_log_methods — Logging::Logger
- #delete — Logging::MappedDiagnosticContext
- #each — Logging::Appenders
- #encoding — Logging::Appender
- #encoding= — Logging::Appender
- #fetch — Logging::Repository
- #filename — Logging::Appenders::RollingFile
- #filename — Logging::Appenders::File
- #flock? — File
- #flock_sh — File
- #flush — Logging::Appenders::Buffering
- #flush — Logging::Appender
- #flush_period= — Logging::Appenders::Buffering
- #footer — Logging::Layout
- #format — Logging::Layout
- #format — Logging::Layouts::Basic
- #format_obj — Logging::Layout
- #format_obj — Logging::Layouts::Parseable
- #getopt — Hash
- #has_logger? — Logging::Repository
- #header — Logging::Layout
- #immediate? — Logging::Appenders::Buffering
- #immediate_at= — Logging::Appenders::Buffering
- #include? — Logging::ColorScheme
- #inherit — Logging::MappedDiagnosticContext
- #inherit — Logging::NestedDiagnosticContext
- #inspect — Logging::Logger
- #inspect — Logging::Appender
- #items= — Logging::Layouts::Parseable
- #layout — Logging::Config::Configurator
- #layout — Logging::Config::YamlConfigurator
- #layout= — Logging::Appender
- #level — Logging::Logger
- #level= — Logging::Appender
- #level= — Logging::RootLogger
- #level= — Logging::Logger
- #levels? — Logging::ColorScheme
- #lines? — Logging::ColorScheme
- #load — Logging::Config::Configurator
- #load — Logging::Config::YamlConfigurator
- #load_from_hash — Logging::ColorScheme
- #log_event — Logging::Logger
- #logger — Logging::Config::Configurator::TopLevelDSL
- #logger_name — Module
- #loggers — Logging::Config::Configurator
- #loggers — Logging::Config::YamlConfigurator
- #map= — Logging::Appenders::Growl
- #map= — Logging::Appenders::Syslog
- #mark — Logging::Stats::Sampler
- #mark — Logging::Stats::Tracker
- #master_for — Logging::Repository
- #mean — Logging::Stats::Sampler
- #method_missing — Logging::Proxy
- #method_missing — Logging::Config::Configurator::DSL
- #original_synchronize — ReentrantMutex
- #parent — Logging::Repository
- #parent= — Logging::Logger
- #parent_name — Logging::Repository
- #pattern= — Logging::Layouts::Pattern
- #peek — Logging::NestedDiagnosticContext
- #periodically_run — Logging::Stats::Tracker
- #pop — Logging::NestedDiagnosticContext
- #port= — Logging::Appenders::Email
- #pre_config — Logging::Config::Configurator
- #pre_config — Logging::Config::YamlConfigurator
- #pre_config — Logging::Config::Configurator::TopLevelDSL
- #push — Logging::NestedDiagnosticContext
- #reduce — String
- #remove — Logging::Appenders
- #remove_appenders — Logging::Logger
- #reopen — Logging::Appender
- #reopen — Logging::Appenders::StringIo
- #reopen — Logging::Appenders::Syslog
- #reopen — Logging::Appenders::RollingFile
- #reopen — Logging::Appenders::File
- #reopen — Logging::Appenders::Buffering
- #require? — Kernel
- #reset — Logging::Appenders::StringIo
- #reset — Logging::Stats::Tracker
- #reset — Logging::Stats::Sampler
- #sample — Logging::Stats::Tracker
- #sample — Logging::Stats::Sampler
- #sd — Logging::Stats::Sampler
- #silence — Logging::RailsCompat
- #stop — Logging::Stats::Tracker
- #sync — Logging::Stats::Tracker
- #synchronize — ReentrantMutex
- #tick — Logging::Stats::Tracker
- #tick — Logging::Stats::Sampler
- #time — Logging::Stats::Tracker
- #to= — Logging::Appenders::Email
- #to_a — Logging::Stats::Sampler
- #to_hash — Logging::Stats::Sampler
- #to_key — Logging::Repository
- #to_s — Logging::Stats::Sampler
- #trace= — Logging::Logger
- #try_json — Logging::Layout
- #try_yaml — Logging::Layout
- #write — Logging::Logger

[Validate]

Generated with the Darkfish Rdoc Generator 2.