101 using adapters
Clone this wiki locally
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.
Out of the box, Yell comes shipped with the following adapters:
: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
Logging to STDOUT
Instead of defining
logger = Yell.new STDOUT, you may also define it as follows:
logger = Yell.new do |l| l.adapter STDOUT end
Logging to Files
While logging to
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
# 1. Shortcut logger = Yell.new 'development.log' # 2. Shortcut (more concise) logger = Yell.new :file, 'development.log' # 3. Block logger = Yell.new do |l| l.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 |l| l.adapter STDOUT l.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