Module: Output
- Defined in:
- lib/output/output.rb,
lib/output/writer.rb,
lib/output/devices.rb,
lib/output/build_logger.rb,
lib/output/writer_macro.rb
Defined Under Namespace
Modules: ClassMethods, Devices
Classes: Writer, WriterMacro
Constant Summary
collapse
- DEFAULT_LOGGER_LEVEL =
:info
- DEFAULT_PATTERN =
'%m\n'
- DEFAULT_DEVICE =
:stdout
Class Method Summary
collapse
Instance Method Summary
collapse
-
#add_device(device) ⇒ Object
-
#build_writer(name, level, device_options = nil, message_transformer = nil) ⇒ Object
-
#disable ⇒ Object
-
#each_writer ⇒ Object
-
#enable ⇒ Object
-
#initial_level? ⇒ Boolean
-
#last_method ⇒ Object
-
#last_method=(val) ⇒ Object
-
#last_method?(*methods) ⇒ Boolean
-
#level ⇒ Object
-
#level=(level) ⇒ Object
-
#levels ⇒ Object
-
#pop_device ⇒ Object
-
#pop_level ⇒ Object
-
#push_device(device, options = {}, &block) ⇒ Object
-
#push_device__obj(device, &block) ⇒ Object
-
#push_device__opts(type, options = {}, &block) ⇒ Object
-
#push_level(level) ⇒ Object
-
#reset_level ⇒ Object
-
#suspend_devices(device, &block) ⇒ Object
-
#suspend_devices__device_selector(device_selector, &block) ⇒ Object
-
#suspend_devices__name(name, &block) ⇒ Object
-
#suspend_devices__obj(device, &block) ⇒ Object
-
#to_s ⇒ Object
-
#write(method, message) ⇒ Object
-
#writer(name) ⇒ Object
Class Method Details
.included(base) ⇒ Object
8
9
10
|
# File 'lib/output/output.rb', line 8
def self.included(base)
base.extend ClassMethods
end
|
Instance Method Details
#add_device(device) ⇒ Object
175
176
177
178
179
180
|
# File 'lib/output/output.rb', line 175
def add_device(device)
each_writer do |writer|
writer.add_device device
end
device
end
|
#build_writer(name, level, device_options = nil, message_transformer = nil) ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/output/output.rb', line 44
def build_writer(name, level, device_options = nil, message_transformer=nil)
device_options ||= {}
device_options = self.class.device_options.merge device_options
logger_name = Writer::Naming.fully_qualified(self.class, name)
writer = Writer.build name, level, message_transformer, self.level, logger_name, device_options
writer
end
|
#disable ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/output/output.rb', line 12
def disable
each_writer { |w| w.disable }
if block_given?
yield
enable
end
end
|
#each_writer ⇒ Object
52
53
54
55
56
57
|
# File 'lib/output/output.rb', line 52
def each_writer
self.class.writer_names.each do |name|
writer = send self.class.writer_attribute(name)
yield writer
end
end
|
#enable ⇒ Object
20
21
22
|
# File 'lib/output/output.rb', line 20
def enable
each_writer { |w| w.enable }
end
|
#initial_level? ⇒ Boolean
69
70
71
|
# File 'lib/output/output.rb', line 69
def initial_level?
level == self.class.logger_level
end
|
#last_method ⇒ Object
32
33
34
|
# File 'lib/output/output.rb', line 32
def last_method
@last_method
end
|
#last_method=(val) ⇒ Object
36
37
38
|
# File 'lib/output/output.rb', line 36
def last_method=(val)
@last_method = val
end
|
#last_method?(*methods) ⇒ Boolean
40
41
42
|
# File 'lib/output/output.rb', line 40
def last_method?(*methods)
methods.include? last_method
end
|
#level ⇒ Object
59
60
61
|
# File 'lib/output/output.rb', line 59
def level
@level ||= self.class.logger_level
end
|
#level=(level) ⇒ Object
63
64
65
66
67
|
# File 'lib/output/output.rb', line 63
def level=(level)
@level = level
each_writer { |w| w.logger_level = level }
level
end
|
#levels ⇒ Object
73
74
75
|
# File 'lib/output/output.rb', line 73
def levels
@levels ||= []
end
|
#pop_device ⇒ Object
168
169
170
171
172
173
|
# File 'lib/output/output.rb', line 168
def pop_device
each_writer do |writer|
writer.pop_device
end
nil
end
|
#pop_level ⇒ Object
97
98
99
100
101
|
# File 'lib/output/output.rb', line 97
def pop_level
level = levels.shift unless levels.empty?
self.level = level
level
end
|
#push_device(device, options = {}, &block) ⇒ Object
143
144
145
146
147
148
149
|
# File 'lib/output/output.rb', line 143
def push_device(device, options = {}, &block)
return device if device.nil?
return push_device__obj(device, &block) if device.is_a? Logging::Appender
push_device__opts(type = device, options, &block)
end
|
#push_device__obj(device, &block) ⇒ Object
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/output/output.rb', line 157
def push_device__obj(device, &block)
each_writer do |writer|
writer.push_device device
end
if block_given?
yield
pop_device
end
device
end
|
#push_device__opts(type, options = {}, &block) ⇒ Object
151
152
153
154
155
|
# File 'lib/output/output.rb', line 151
def push_device__opts(type, options = {}, &block)
options = self.class.device_options.merge(options)
device = Output::Devices.build_device(type, options)
push_device__obj device, &block
end
|
#push_level(level) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/output/output.rb', line 85
def push_level(level)
levels.unshift self.level
self.level = level
if block_given?
yield
self.level = pop_level
end
level
end
|
#reset_level ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/output/output.rb', line 77
def reset_level
@level = self.class.logger_level
each_writer do |writer|
writer.reset_level
end
end
|
#suspend_devices(device, &block) ⇒ Object
103
104
105
106
|
# File 'lib/output/output.rb', line 103
def suspend_devices(device, &block)
return suspend_devices__obj(device, &block) if device.is_a? Logging::Appender
suspend_devices__name device, &block
end
|
#suspend_devices__device_selector(device_selector, &block) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/output/output.rb', line 118
def suspend_devices__device_selector(device_selector, &block)
suspensions = []
each_writer do |writer|
device = device_selector.call writer
suspension = Writer::DeviceSuspension.new writer, device
suspensions << suspension
suspension.suspend
end
yield
suspensions.each { |suspension| suspension.restore }
end
|
#suspend_devices__name(name, &block) ⇒ Object
113
114
115
116
|
# File 'lib/output/output.rb', line 113
def suspend_devices__name(name, &block)
device_selector = ->(writer) { writer.device name }
suspend_devices__device_selector device_selector, &block
end
|
#suspend_devices__obj(device, &block) ⇒ Object
108
109
110
111
|
# File 'lib/output/output.rb', line 108
def suspend_devices__obj(device, &block)
device_selector = ->(writer) { device }
suspend_devices__device_selector device_selector, &block
end
|
#to_s ⇒ Object
133
134
135
136
137
138
139
140
141
|
# File 'lib/output/output.rb', line 133
def to_s
details = "Output : #{self.class.name} - Object Id:#{self.object_id}\n"
details << "Level: #{self.level}\n"
details << "Writer Details: \n"
each_writer do |writer|
details << "#{writer.to_s}\n"
end
details
end
|
#write(method, message) ⇒ Object
24
25
26
|
# File 'lib/output/output.rb', line 24
def write(method, message)
send method, message
end
|
#writer(name) ⇒ Object
28
29
30
|
# File 'lib/output/output.rb', line 28
def writer(name)
send self.class.writer_attribute(name)
end
|