-
Notifications
You must be signed in to change notification settings - Fork 21
101 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
Instead of defining logger = Yell.new STDOUT
, you may also define it as follows:
logger = Yell.new do |l|
l.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 |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.
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