Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Yell - Your Extensible Logging Library

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Yell - Your Extensible Logging Library

Build Status Code Climate

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.

If you want to use Yell with Rails, then head over to yell-rails.


System wide:

gem install yell

Or in your Gemfile:

gem "yell"


On the basics, you can use Yell just like any other logging library with a more sophisticated message formatter.

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

The strength of Yell, however, comes when using multiple adapters. The already built-in ones are IO-based and require no further configuration. Also, there are additional ones available as separate gems. Please consult the wiki on that - they are listed there.

The standard adapters are:

:stdout : Messages will be written to STDOUT
: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 = do |l|
  l.adapter STDOUT, :level => [:debug, :info, :warn]
  l.adapter STDERR, :level => [:error, :fatal]
Example: Typical production Logger

We setup a logger that starts passing messages at the :info level. Severities below :error go into the 'production.log', whereas anything higher is written into the 'error.log'.

logger = do |l|
  l.level = :info # will only pass :info and above to the adapters

  l.adapter :datefile, 'production.log', :level => Yell.level.lte(:warn)
  l.adapter :datefile, 'error.log', :level => Yell.level.gte(:error)

But I'm used to Log4r and I don't want to move on

One of the really nice features of Log4r is its repository. The following example is taken from the official Log4r documentation.

require 'log4r'
include Log4r

# create a logger named 'mylog' that logs to stdout
mylog = 'mylog'
mylog.outputters = Outputter.stdout

# later in the code, you can get the logger back

With Yell you can do the same thing with less:

require 'yell'

# create a logger named 'mylog' that logs to stdout :stdout, :name => 'mylog'

# later in the code, you can get the logger back

There is no need to define outputters separately and you don't have to taint you global namespace with Yell's subclasses.

You want any class to have a logger?

Yell comes with a simple module: +Yell::Loggable+. Simply include this in a class and you are good to go.

# Before you can use it, you will need to define a logger and 
# provide it with the `:name` of your class. :stdout, :name => 'Foo'

class Foo
  include Yell::Loggable

# Now you can log "Hello World"

It even works with class inheritance:

# Given the above example, we inherit from Foo
class Bar < Foo

# The logger will fallback to the Foo superclass "Hello World"

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

Additional Adapters

Graylog2 (GELF)


How To: Writing Your Own Adapter

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.