Module: Superlogger
- Defined in:
- lib/superlogger.rb,
lib/superlogger/logger.rb,
lib/superlogger/railtie.rb,
lib/superlogger/version.rb,
lib/superlogger/superlogger_middleware.rb,
lib/superlogger/action_view_log_subscriber.rb,
lib/superlogger/active_record_log_subscriber.rb,
lib/superlogger/action_controller_log_subscriber.rb
Defined Under Namespace
Classes: ActionControllerLogSubscriber, ActionViewLogSubscriber, ActiveRecordLogSubscriber, Logger, Railtie, SuperloggerMiddleware
Constant Summary
collapse
- VERSION =
'1.1.0'
- @@enabled =
false
- @@include_log_fields =
nil
Class Method Summary
collapse
Class Method Details
.attach_superlogger_log_subscribers ⇒ Object
51
52
53
54
55
|
# File 'lib/superlogger.rb', line 51
def attach_superlogger_log_subscribers
require 'superlogger/action_controller_log_subscriber'
require 'superlogger/action_view_log_subscriber'
require 'superlogger/active_record_log_subscriber'
end
|
.detach_existing_log_subscribers ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/superlogger.rb', line 27
def detach_existing_log_subscribers
require 'action_controller/log_subscriber'
require 'active_record/log_subscriber'
require 'action_view/log_subscriber'
remove_patterns = %w(sql.active_record
start_processing.action_controller
process_action.action_controller
render_template.action_view
render_partial.action_view
render_collection.action_view)
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber|
patterns = subscriber.patterns
patterns = patterns.is_a?(Hash) ? patterns.keys : patterns
patterns.each do |pattern|
ActiveSupport::Notifications.unsubscribe pattern if remove_patterns.include?(pattern)
end
end
end
|
.enabled ⇒ Object
77
78
79
|
# File 'lib/superlogger.rb', line 77
def enabled
@@enabled
end
|
.enabled=(enabled) ⇒ Object
73
74
75
|
# File 'lib/superlogger.rb', line 73
def enabled=(enabled)
@@enabled=enabled
end
|
.include_log_fields ⇒ Object
85
86
87
|
# File 'lib/superlogger.rb', line 85
def include_log_fields
@@include_log_fields
end
|
.include_log_fields=(include_log_fields) ⇒ Object
81
82
83
|
# File 'lib/superlogger.rb', line 81
def include_log_fields=(include_log_fields)
@@include_log_fields=include_log_fields
end
|
.insert_superlogger_middleware(app) ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/superlogger.rb', line 18
def insert_superlogger_middleware(app)
require 'superlogger/superlogger_middleware'
app.middleware.use Superlogger::SuperloggerMiddleware, {
include_log_fields: @@include_log_fields
}.compact
end
|
.request_id ⇒ Object
69
70
71
|
# File 'lib/superlogger.rb', line 69
def request_id
RequestStore.store[:superlogger_request_id]
end
|
.request_id=(request_id) ⇒ Object
65
66
67
|
# File 'lib/superlogger.rb', line 65
def request_id=(request_id)
RequestStore.store[:superlogger_request_id] = request_id
end
|
.session_id ⇒ Object
61
62
63
|
# File 'lib/superlogger.rb', line 61
def session_id
RequestStore.store[:superlogger_session_id]
end
|
.session_id=(session_id) ⇒ Object
57
58
59
|
# File 'lib/superlogger.rb', line 57
def session_id=(session_id)
RequestStore.store[:superlogger_session_id] = session_id
end
|
.setup(app) ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/superlogger.rb', line 10
def setup(app)
return unless (Rails.env.production? || enabled)
insert_superlogger_middleware(app)
detach_existing_log_subscribers
attach_superlogger_log_subscribers
end
|