Class: Climatic::Logger::Accumulator
- Inherits:
-
Object
- Object
- Climatic::Logger::Accumulator
show all
- Defined in:
- lib/climatic/logger/accumulator.rb
Constant Summary
collapse
- STACK_OPS =
i(debug info warn error fatal unknown).freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Accumulator.
10
11
12
|
# File 'lib/climatic/logger/accumulator.rb', line 10
def initialize
@log_lines = [{op: :debug, args: ['Starting special temporary "accumulator" logger...']}]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/climatic/logger/accumulator.rb', line 30
def method_missing(method_name, *args)
if STACK_OPS.include? method_name
stack method_name, *args
else
super
end
end
|
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
8
9
10
|
# File 'lib/climatic/logger/accumulator.rb', line 8
def level
@level
end
|
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
38
39
40
|
# File 'lib/climatic/logger/accumulator.rb', line 38
def respond_to_missing?(method_name, include_private = false)
STACK_OPS.include?(method_name) || super
end
|
#stack(op, *args) ⇒ Object
14
15
16
|
# File 'lib/climatic/logger/accumulator.rb', line 14
def stack(op, *args)
log_lines << {op: op, args: args}
end
|
#transfer_content_to(other_logger) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/climatic/logger/accumulator.rb', line 18
def transfer_content_to(other_logger)
debug "Transferring accumulated logs to logger '#{other_logger.inspect}'"
if other_logger.nil?
@log_lines = []
return
end
log_lines.each do |log_line|
other_logger.send log_line[:op], *log_line[:args]
end
@log_lines = []
end
|