kristianmandrup / log4r-color

log4r now with color outputs to terminal/console
Other
6 stars 2 forks source link

h1. A flexible logging library for Ruby, now in color

This project is currently decoupled from the main log4r project which it rests on. The main addition to log4r in this project is the ColorOutputter which uses "colorize":https://github.com/fazibear/colorize to display logs in the console/terminal with colorschemes for each log level to make it easy to distinquish them.

This project is used in "logging_assist":https://github.com/kristianmandrup/logging_assist which wraps log4r-color in a convenient DSL syntax.

h2. Release

This release: 1.2 Release date: Jan/2011 License: LGPLv3

h2. Contributors

"Homepage":http://log4r.rubyforge.org/ "Download":http://rubyforge.org/frs/?group_id=203

h2. Summary

Log4r is a comprehensive and flexible logging library written in Ruby for use in Ruby programs. It features a hierarchical logging system of any number of levels, custom level names, logger inheritance, multiple output destinations per log event, execution tracing, custom formatting, thread safteyness, XML and YAML configuration, and more.

h2. Requirements

h3. Gem requirements

h2. Install

gem install log4r-color

h2. Usage

Here is an example of setting up a logger with ColorOutputter using a color scheme. While logging, one of the color schemes is changed and it applies immediately to log messages after.

require 'log4r-color'
include Log4r

Logger.global.level = ALL
formatter = PatternFormatter.new(:pattern => "%l - %m - %c")

ColorOutputter.new 'color', {:colors => 
  { 
    :debug  => :light_blue, 
    :info   => :light_blue, 
    :warn   => :yellow, 
    :error  => :red, 
    :fatal  => {:color => :red, :background => :white} 
  } 
}

Logger.new('color_logger', DEBUG).add('color')

def do_logging(log)
  puts "--"
  log.debug "This is debug"
  log.info "This is info"
  log.warn "This is warn"
  Outputter['color'].colors[:info] = :green
  log.info "This is info again, now in green"
  log.error "This is error"
  log.fatal "This is fatal"  
end

do_logging Logger['color_logger']  

Note: You can set the log levels you allow via the `Log4r.LNAMES` constant, by default set to `['ALL']` to allow any log level.

h2. More Info

h2. Usability

Log4r works really well, so please take advantage of it right away! :) All versions since 0.9.2 have been stable and backward-compatible. The code is stable enough that updates are infrequent and usually only for adding features or keeping the code up to date with Ruby.

h2. Platform Issues

Log4r is known to work on Linux and WindowsXP. It's safe to assume that Log4r will work on any Ruby-supported platform.

h2. When Trouble Strikes

Log4r comes with an internal logger. To see its output, create a logger named 'log4r' before any others and give it a suitable outputter,

  trouble = Logger.new['log4r']
  trouble.add Outputter.stdout