Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Yell - Your Extensible Logging Library
Ruby

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
spec
.gitignore
.travis.yml
Gemfile
LICENSE.txt
README.md
Rakefile
yell.gemspec

README.md

Yell - Your Extensible Logging Library

Build Status

Yell works and is tested with ruby 1.8.7, 1.9.x, jruby 1.8 and 1.9 mode, rubinius 1.8 and 1.9 as well as ree.

Installation

System wide:

gem install yell

Or in your Gemfile:

gem "yell"

Usage

On the basics, Yell works just like any other logging library. However, it tries to make your log mesages more readable. By default, it will format the given message as follows:

logger = Yell.new STDOUT

logger.info "Hello World"
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World"
#    ^                         ^       ^       ^
#    ISO8601 Timestamp         Level   Pid     Message

When no arguments are given, Yell will check for ENV['RACK_ENV'] and determine the filename from that.

Alternatively, you may define ENV['YELL_ENV'] to set the filename. If neither YELL_ENV or RACK_ENV is defined, 'development' will be the default. Also, if a log directory exists, Yell will place the file there (only if you have not passed a filename explicitly.

Naturally, you can pass a :filename to Yell:

logger = Yell.new "yell.log"

Levels

Just like any other logging library, Yell allows you to define from which level onwarns you want to write your log message. here are some examples to show how you can combine those.

Example: Write from :info onwards
logger = Yell.new STDOUT, :level => :info # write on :info, :warn, :error, :fatal
Example: Write on :info and :error only
logger - Yell.new STDOUT, :level => [:info, :error] # write on :info and :error only
Example: Write between :info and :error
logger = Yell.new STDOUT, :level => (:info..:error)

# NOTE: The Range might only work with 1.9 compatible rubies!

There are more ways to set your logging level, please consult the wiki on that.

Adapters

Yell comes with various adapters already build-in. Those are the mainly IO-based adapters for every day use. There are additional ones available as separate gems. Please consult the wiki on that - they are listed there.

The standard adapters are:

:stdout or STDOUT: Messages will be written to STDOUT
:stderr or STDERR: Messages will be written to STDERR
:file: Messages will be written to a file
:datefile: Messages will be written to a timestamped file

Here are some short examples on how to combine them:

Example: Notice messages go into STDOUT and error messages into STDERR
logger = Yell.new do
  adapter STDOUT, :level => [:debug, :info, :warn]
  adapter STDERR, :level => [:error, :fatal]
end
Example: Notice messages to into application.log and error messages into error.log
logger = Yell.new do
  adapter :file, 'application.log', :level => [:debug, :info, :warn]
  adapter :file, 'error.log', :level => [:error, :fatal]
end
Example: Every log severity is handled by a separate adapter and we ignore :debug and :info levels
logger = Yell.new do
  level :warn # only start logging from :warn upwards

  adapter :stdout, :level => [:warn]
  adapter :datefile, 'error.log', :level => [:error]
  adapter :datefile, 'fatal.log', :level => [:fatal]
end

Further Readings

How To: Setting The Log Level
How To: Formatting Log Messages
How To: Using Adapters
How To: The Datefile Adapter
How To: Different Adapters for Different Log Levels

You can find further examples and additional adapters in the wiki. or have a look into the examples folder.

Copyright © 2011-2012 Rudolf Schmidt, released under the MIT license

Something went wrong with that request. Please try again.