Class: ActiveSupport::EventReporter::LogSubscriber
- Inherits:
-
Object
- Object
- ActiveSupport::EventReporter::LogSubscriber
show all
- Includes:
- ColorizeLogging
- Defined in:
- activesupport/lib/active_support/event_reporter/log_subscriber.rb
Constant Summary
collapse
- LEVEL_CHECKS =
{
debug: -> (logger) { logger.debug? },
info: -> (logger) { logger.info? },
error: -> (logger) { logger.error? },
}
ColorizeLogging::BLACK, ColorizeLogging::BLUE, ColorizeLogging::CYAN, ColorizeLogging::GREEN, ColorizeLogging::MAGENTA, ColorizeLogging::MODES, ColorizeLogging::RED, ColorizeLogging::WHITE, ColorizeLogging::YELLOW
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#color, #colorize_logging, #debug, #error, #fatal, #info, #mode_from, #unknown, #warn
Methods included from Concern
#append_features, #class_methods, extended, #included, #prepend_features, #prepended
Class Attribute Details
19
20
21
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 19
def logger
@logger || default_logger
end
|
.namespace ⇒ Object
Returns the value of attribute namespace.
28
29
30
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 28
def namespace
@namespace
end
|
Class Method Details
.default_logger ⇒ Object
23
24
25
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 23
def default_logger
raise NotImplementedError
end
|
.event_log_level(method_name, level) ⇒ Object
15
16
17
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 15
def event_log_level(method_name, level)
log_levels[method_name.to_s] = level
end
|
.subscription_filter ⇒ Object
30
31
32
33
34
35
36
37
38
39
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 30
def subscription_filter
namespace = self.namespace.to_s
proc do |event|
name = event[:name]
if (dot_idx = name.index("."))
event_namespace = name[0, dot_idx]
namespace == event_namespace
end
end
end
|
Instance Method Details
#emit(event) ⇒ Object
44
45
46
47
48
49
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 44
def emit(event)
return unless logger
name = event[:name]
event_method = name[name.index(".") + 1, name.length]
public_send(event_method, event) if LEVEL_CHECKS[log_levels[event_method]]&.call(logger)
end
|
51
52
53
|
# File 'activesupport/lib/active_support/event_reporter/log_subscriber.rb', line 51
def logger
self.class.logger
end
|