-
Notifications
You must be signed in to change notification settings - Fork 100
/
names.rb
43 lines (36 loc) · 1.56 KB
/
names.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# :stopdoc:
#
# Loggers and appenders can be looked up by name. The bracket notation is
# used to find these objects:
#
# Logging.logger['foo']
# Logging.appenders['bar']
#
# A logger will be created if a new name is used. Appenders are different;
# nil is returned when an unknown appender name is used. The reason for this
# is that appenders come in many different flavors (so it is unclear which
# type should be created), but there is only one type of logger.
#
# So it is useful to be able to create an appender and then reference it by
# name to add it to multiple loggers. When the same name is used, the same
# object will be returned by the bracket methods.
#
# Layouts do not have names. Some are stateful, and none are threadsafe. So
# each appender is configured with it's own layout.
#
require 'logging'
Logging.appenders.file('Debug File', :filename => 'debug.log')
Logging.appenders.stderr('Standard Error', :level => :error)
# configure the root logger
Logging.logger.root.appenders = 'Debug File'
Logging.logger.root.level = :debug
# add the Standard Error appender to the Critical logger (it will use it's
# own appender and the root logger's appender, too)
Logging.logger['Critical'].appenders = 'Standard Error'
# if you'll notice above, assigning appenders using just the name is valid
# the logger is smart enough to figure out it was given a string and then
# go lookup the appender by name
# and now log some messages
Logging.logger['Critical'].info 'just keeping you informed'
Logging.logger['Critical'].fatal 'WTF!!'
# :startdoc: