Skip to content

101 using adapters

rudionrails edited this page Mar 28, 2012 · 5 revisions

Yell 101 - How To: Using Adapters

Yell allows you to attach adapters in various combinations. This document will cover their basic usage. For more advanced configurations, you continue to reading: How To: Different Adapters for Different Log Levels

Instead of defining logger = Yell.new STDOUT, you may also define it as follows:

logger = Yell.new do
  adapter STDOUT
end

While logging to STDOUT or STDERR remains trivial, you will need to be more concise when logging to files. The following definitions are all equal and will result in using the build-in File adapter:

# 1. Shortcut
logger = Yell.new 'development.log'

# 2. Shortcut (more concise)
logger = Yell.new :file, 'development.log'

# 3. Block
logger = Yell.new do
  adapter :file, 'development.log'
end

NOTE: You are not able to default to the File adapter with the shortcut: adapter 'development.log'. In that case, you need to tell which adapter to use.

Multiple Adapters in one Logger

Of course, you are able to combine multiple adapters in one logger instance:

logger = Yell.new do
  adapter STDOUT
  adapter :file, 'development.log'
end

logger.info "Hello World!"

The above example will write the log message into both adapters at the same time. However, you are able to configure adapters separately. Reading How To: Different Adapters for Different Log Levels covers that topic.

If you want to know more, continue to How To: The Datefile Adapter