Class: Logz::LoggerWrapper
- Inherits:
-
Object
- Object
- Logz::LoggerWrapper
show all
- Defined in:
- lib/logz/logger_wrapper.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of LoggerWrapper.
5
6
7
8
|
# File 'lib/logz/logger_wrapper.rb', line 5
def initialize(logger)
@logger = Logger.new(logger)
reset
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/logz/logger_wrapper.rb', line 52
def method_missing(m, *args, &block)
if has_level?(m)
add(m, *args)
elsif logger.respond_to?(m)
logger.send(m, *args)
elsif Rainbow::X11ColorNames::NAMES.include?(m)
color(m)
else
super
end
end
|
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
3
4
5
|
# File 'lib/logz/logger_wrapper.rb', line 3
def logger
@logger
end
|
Instance Method Details
#add(severity, message = nil, progname = nil) ⇒ Object
43
44
45
46
47
48
|
# File 'lib/logz/logger_wrapper.rb', line 43
def add(severity, message = nil, progname = nil)
severity = Logger.const_get(severity.upcase) if severity.is_a?(Symbol)
logger.send(:add, severity, to_output(message), progname)
ensure
reset
end
|
#color(color_name) ⇒ Object
15
16
17
18
|
# File 'lib/logz/logger_wrapper.rb', line 15
def color(color_name)
@color = color_name.to_sym
self
end
|
#has_level?(level) ⇒ Boolean
39
40
41
|
# File 'lib/logz/logger_wrapper.rb', line 39
def has_level?(level)
Logz.config.levels.include?(level)
end
|
#reset ⇒ Object
10
11
12
13
|
# File 'lib/logz/logger_wrapper.rb', line 10
def reset
@tags = []
@color = nil
end
|