Class: SmartLoggerWrapper
- Inherits:
-
Logger
- Object
- Logger
- SmartLoggerWrapper
show all
- Includes:
- Logger::Severity
- Defined in:
- lib/smart_logger_wrapper.rb,
lib/smart_logger_wrapper/options.rb,
lib/smart_logger_wrapper/version.rb,
lib/smart_logger_wrapper/options/to.rb,
lib/smart_logger_wrapper/utils/path.rb,
lib/smart_logger_wrapper/options/base.rb,
lib/smart_logger_wrapper/utils/backtrace.rb,
lib/smart_logger_wrapper/options/with_position.rb,
lib/smart_logger_wrapper/options/append_backtrace.rb
Defined Under Namespace
Modules: Options, Utils
Constant Summary
collapse
- LOGGER_SHORTCUT_OFFSET =
3
- SEVERITY_MAPPING =
{
debug: DEBUG,
info: INFO,
warn: WARN,
error: ERROR,
fatal: FATAL,
unknown: UNKNOWN
}.freeze
- DELEGETING_METHODS =
%i(<< reopen close log add level debug? level= progname datetime_format= datetime_format formatter sev_threshold sev_threshold= info? warn? error? fatal? progname= formatter=)
- VERSION =
"0.4.3"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(logger = Logger.new(STDOUT), *loggers, **options) ⇒ SmartLoggerWrapper
22
23
24
25
26
27
28
|
# File 'lib/smart_logger_wrapper.rb', line 22
def initialize(logger = Logger.new(STDOUT), *loggers, **options)
@loggers = [logger, *loggers].freeze
@options = options.freeze
@offset = LOGGER_SHORTCUT_OFFSET
@_loggers_cache = {}
@_loggers_with_offset_cache = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/smart_logger_wrapper.rb', line 101
def method_missing(method_name, *args, &block)
if Options.defined_option?(method_name)
arg = args.first
@_loggers_cache[method_name] = {} unless @_loggers_cache.include?(method_name)
new_logger = @_loggers_cache[method_name][arg] ||= clone.tap do |cloned|
cloned.overwrite_options(method_name => arg)
end
return block.(new_logger) if block_given?
new_logger
else
super
end
end
|
Instance Attribute Details
#loggers ⇒ Object
Returns the value of attribute loggers.
20
21
22
|
# File 'lib/smart_logger_wrapper.rb', line 20
def loggers
@loggers
end
|
#offset ⇒ Object
Returns the value of attribute offset.
20
21
22
|
# File 'lib/smart_logger_wrapper.rb', line 20
def offset
@offset
end
|
#options ⇒ Object
Returns the value of attribute options.
20
21
22
|
# File 'lib/smart_logger_wrapper.rb', line 20
def options
@options
end
|
Instance Method Details
66
67
68
|
# File 'lib/smart_logger_wrapper.rb', line 66
def format_message(severity, datetime, progname, msg)
loggers.first.send(:format_message, severity, datetime, progname, msg)
end
|
62
63
64
|
# File 'lib/smart_logger_wrapper.rb', line 62
def format_severity(severity)
loggers.first.send(:format_severity, severity)
end
|
#overwrite_options(_options) ⇒ Object
58
59
60
|
# File 'lib/smart_logger_wrapper.rb', line 58
def overwrite_options(_options)
@options = options.merge(_options).freeze
end
|
#with_offset(_offset) ⇒ Object
52
53
54
55
56
|
# File 'lib/smart_logger_wrapper.rb', line 52
def with_offset(_offset)
@_loggers_with_offset_cache[_offset] ||= clone.tap do |logger_with_offset|
logger_with_offset.instance_variable_set(:@offset, _offset)
end
end
|