101 basic usage

rudionrails edited this page Mar 22, 2012 · 2 revisions

Yell 101 - How To: Basic Usage

On the basics, Yell works just like any other logging library. However, it enriches your log messages to make it 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

Naturally, if you pass a :filename to Yell it will write the message in there:

# The following two Yell instances are identical
logger = Yell.new 'yell.log'
logger = Yell.new :filename => 'yell.log'

Let The ENV Decide

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

# CHecking the RACK_ENV
puts ENV['RACK_ENV']
#=> "production"

# Log something
logger = Yell.new
logger.info "Hello World!"

# Tail the production.log
# ==== production.log ===
#=> "2012-02-29T09:30:00+01:00 [ INFO] 65784 : Hello World!"

Alternatively, you may define ENV['YELL_ENV'] to control 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.