log_sanity 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +120 -84
- data/README.md +9 -7
- data/lib/log_sanity/extensions/broadcast_logger.rb +13 -0
- data/lib/log_sanity/log_subscribers/action_dispatch.rb +4 -0
- data/lib/log_sanity/log_subscribers/active_job.rb +27 -0
- data/lib/log_sanity/middleware/request_logger.rb +16 -13
- data/lib/log_sanity/railtie.rb +44 -43
- data/lib/log_sanity/version.rb +1 -1
- data/lib/log_sanity.rb +15 -18
- data/log_sanity.gemspec +1 -1
- data/test/dummy/config/application.rb +2 -0
- metadata +5 -6
- data/lib/log_sanity/extensions/active_support_subscriber.rb +0 -25
- data/lib/log_sanity/middleware/routing_error_catcher.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a0edb320430f364dcba88e455a88eb3cea47cc2630b691457e70b9727001a70
|
4
|
+
data.tar.gz: db6591479d06b2b435bbd8992f3abf28e47dc15414bc87ccf6d7d3f0864e998d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef54dae274716b9d5c2bc180747b44cda69892a42e1c7addb7c8bee1275869ec9d4db97e88a5c0428eb15562bc49b1611c94160031fae6022c88c49902bda53f
|
7
|
+
data.tar.gz: '0191a93198383de05c394f38d3cf4f046d0189d3b5ef78da900fd237353aab913bff98665fc606225a0179e187cd063e87e1947b617a08beebeead11d77cf8d6'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
#### 2.0.0
|
2
|
+
|
3
|
+
- (Breaking) Require Rails 7.1
|
4
|
+
For Rails 5.2, 6.x, and 7.0, use log_sanity 1.x
|
5
|
+
- (Potentially breaking) Remove RoutingErrorCatcher middleware
|
6
|
+
Shouldn't break unless directly referenced during app's middleware setup
|
7
|
+
Mostly not needed on Rails 7.1, but for an alternative, see [rails-hush](https://github.com/zarqman/rails-hush) gem
|
8
|
+
- Handle new events and updated payloads for Rails 7.1
|
9
|
+
- Use updated instrumentation API in request_logger
|
10
|
+
- Refactor initializer to use on_load
|
11
|
+
|
12
|
+
#### 1.3.2
|
13
|
+
|
14
|
+
- Fix logging on Rails 7.1 due to default use of BroadcastLogger
|
15
|
+
|
1
16
|
#### 1.3.1
|
2
17
|
|
3
18
|
- Handle updated show_exceptions values in Rails 7.1
|
data/Gemfile.lock
CHANGED
@@ -1,86 +1,103 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
log_sanity (
|
5
|
-
rails (>=
|
4
|
+
log_sanity (2.0.0)
|
5
|
+
rails (>= 7.1, < 7.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (7.0
|
11
|
-
actionpack (= 7.0
|
12
|
-
activesupport (= 7.0
|
10
|
+
actioncable (7.1.0)
|
11
|
+
actionpack (= 7.1.0)
|
12
|
+
activesupport (= 7.1.0)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
zeitwerk (~> 2.6)
|
16
|
+
actionmailbox (7.1.0)
|
17
|
+
actionpack (= 7.1.0)
|
18
|
+
activejob (= 7.1.0)
|
19
|
+
activerecord (= 7.1.0)
|
20
|
+
activestorage (= 7.1.0)
|
21
|
+
activesupport (= 7.1.0)
|
21
22
|
mail (>= 2.7.1)
|
22
23
|
net-imap
|
23
24
|
net-pop
|
24
25
|
net-smtp
|
25
|
-
actionmailer (7.0
|
26
|
-
actionpack (= 7.0
|
27
|
-
actionview (= 7.0
|
28
|
-
activejob (= 7.0
|
29
|
-
activesupport (= 7.0
|
26
|
+
actionmailer (7.1.0)
|
27
|
+
actionpack (= 7.1.0)
|
28
|
+
actionview (= 7.1.0)
|
29
|
+
activejob (= 7.1.0)
|
30
|
+
activesupport (= 7.1.0)
|
30
31
|
mail (~> 2.5, >= 2.5.4)
|
31
32
|
net-imap
|
32
33
|
net-pop
|
33
34
|
net-smtp
|
34
|
-
rails-dom-testing (~> 2.
|
35
|
-
actionpack (7.0
|
36
|
-
actionview (= 7.0
|
37
|
-
activesupport (= 7.0
|
38
|
-
|
35
|
+
rails-dom-testing (~> 2.2)
|
36
|
+
actionpack (7.1.0)
|
37
|
+
actionview (= 7.1.0)
|
38
|
+
activesupport (= 7.1.0)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
rack (>= 2.2.4)
|
41
|
+
rack-session (>= 1.0.1)
|
39
42
|
rack-test (>= 0.6.3)
|
40
|
-
rails-dom-testing (~> 2.
|
41
|
-
rails-html-sanitizer (~> 1.
|
42
|
-
actiontext (7.0
|
43
|
-
actionpack (= 7.0
|
44
|
-
activerecord (= 7.0
|
45
|
-
activestorage (= 7.0
|
46
|
-
activesupport (= 7.0
|
43
|
+
rails-dom-testing (~> 2.2)
|
44
|
+
rails-html-sanitizer (~> 1.6)
|
45
|
+
actiontext (7.1.0)
|
46
|
+
actionpack (= 7.1.0)
|
47
|
+
activerecord (= 7.1.0)
|
48
|
+
activestorage (= 7.1.0)
|
49
|
+
activesupport (= 7.1.0)
|
47
50
|
globalid (>= 0.6.0)
|
48
51
|
nokogiri (>= 1.8.5)
|
49
|
-
actionview (7.0
|
50
|
-
activesupport (= 7.0
|
52
|
+
actionview (7.1.0)
|
53
|
+
activesupport (= 7.1.0)
|
51
54
|
builder (~> 3.1)
|
52
|
-
erubi (~> 1.
|
53
|
-
rails-dom-testing (~> 2.
|
54
|
-
rails-html-sanitizer (~> 1.
|
55
|
-
activejob (7.0
|
56
|
-
activesupport (= 7.0
|
55
|
+
erubi (~> 1.11)
|
56
|
+
rails-dom-testing (~> 2.2)
|
57
|
+
rails-html-sanitizer (~> 1.6)
|
58
|
+
activejob (7.1.0)
|
59
|
+
activesupport (= 7.1.0)
|
57
60
|
globalid (>= 0.3.6)
|
58
|
-
activemodel (7.0
|
59
|
-
activesupport (= 7.0
|
60
|
-
activerecord (7.0
|
61
|
-
activemodel (= 7.0
|
62
|
-
activesupport (= 7.0
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
activemodel (7.1.0)
|
62
|
+
activesupport (= 7.1.0)
|
63
|
+
activerecord (7.1.0)
|
64
|
+
activemodel (= 7.1.0)
|
65
|
+
activesupport (= 7.1.0)
|
66
|
+
timeout (>= 0.4.0)
|
67
|
+
activestorage (7.1.0)
|
68
|
+
actionpack (= 7.1.0)
|
69
|
+
activejob (= 7.1.0)
|
70
|
+
activerecord (= 7.1.0)
|
71
|
+
activesupport (= 7.1.0)
|
68
72
|
marcel (~> 1.0)
|
69
|
-
|
70
|
-
|
73
|
+
activesupport (7.1.0)
|
74
|
+
base64
|
75
|
+
bigdecimal
|
71
76
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
77
|
+
connection_pool (>= 2.2.5)
|
78
|
+
drb
|
72
79
|
i18n (>= 1.6, < 2)
|
73
80
|
minitest (>= 5.1)
|
81
|
+
mutex_m
|
74
82
|
tzinfo (~> 2.0)
|
83
|
+
base64 (0.1.1)
|
84
|
+
bigdecimal (3.1.4)
|
75
85
|
builder (3.2.4)
|
76
86
|
concurrent-ruby (1.2.2)
|
87
|
+
connection_pool (2.4.1)
|
77
88
|
crass (1.0.6)
|
78
89
|
date (3.3.3)
|
90
|
+
drb (2.1.1)
|
91
|
+
ruby2_keywords
|
79
92
|
erubi (1.12.0)
|
80
|
-
globalid (1.1
|
81
|
-
activesupport (>=
|
82
|
-
i18n (1.
|
93
|
+
globalid (1.2.1)
|
94
|
+
activesupport (>= 6.1)
|
95
|
+
i18n (1.14.1)
|
83
96
|
concurrent-ruby (~> 1.0)
|
97
|
+
io-console (0.6.0)
|
98
|
+
irb (1.8.1)
|
99
|
+
rdoc
|
100
|
+
reline (>= 0.3.8)
|
84
101
|
loofah (2.21.3)
|
85
102
|
crass (~> 1.0.2)
|
86
103
|
nokogiri (>= 1.12.0)
|
@@ -90,65 +107,84 @@ GEM
|
|
90
107
|
net-pop
|
91
108
|
net-smtp
|
92
109
|
marcel (1.0.2)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
net-imap (0.
|
110
|
+
mini_mime (1.1.5)
|
111
|
+
minitest (5.20.0)
|
112
|
+
mutex_m (0.1.2)
|
113
|
+
net-imap (0.4.1)
|
97
114
|
date
|
98
115
|
net-protocol
|
99
116
|
net-pop (0.1.2)
|
100
117
|
net-protocol
|
101
118
|
net-protocol (0.2.1)
|
102
119
|
timeout
|
103
|
-
net-smtp (0.
|
120
|
+
net-smtp (0.4.0)
|
104
121
|
net-protocol
|
105
122
|
nio4r (2.5.9)
|
106
|
-
nokogiri (1.15.
|
123
|
+
nokogiri (1.15.4-arm64-darwin)
|
124
|
+
racc (~> 1.4)
|
125
|
+
nokogiri (1.15.4-x86_64-darwin)
|
126
|
+
racc (~> 1.4)
|
127
|
+
nokogiri (1.15.4-x86_64-linux)
|
107
128
|
racc (~> 1.4)
|
108
|
-
|
109
|
-
|
129
|
+
psych (5.1.0)
|
130
|
+
stringio
|
131
|
+
racc (1.7.1)
|
132
|
+
rack (3.0.8)
|
133
|
+
rack-session (2.0.0)
|
134
|
+
rack (>= 3.0.0)
|
110
135
|
rack-test (2.1.0)
|
111
136
|
rack (>= 1.3)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
137
|
+
rackup (2.1.0)
|
138
|
+
rack (>= 3)
|
139
|
+
webrick (~> 1.8)
|
140
|
+
rails (7.1.0)
|
141
|
+
actioncable (= 7.1.0)
|
142
|
+
actionmailbox (= 7.1.0)
|
143
|
+
actionmailer (= 7.1.0)
|
144
|
+
actionpack (= 7.1.0)
|
145
|
+
actiontext (= 7.1.0)
|
146
|
+
actionview (= 7.1.0)
|
147
|
+
activejob (= 7.1.0)
|
148
|
+
activemodel (= 7.1.0)
|
149
|
+
activerecord (= 7.1.0)
|
150
|
+
activestorage (= 7.1.0)
|
151
|
+
activesupport (= 7.1.0)
|
124
152
|
bundler (>= 1.15.0)
|
125
|
-
railties (= 7.0
|
126
|
-
rails-dom-testing (2.0
|
127
|
-
activesupport (>=
|
153
|
+
railties (= 7.1.0)
|
154
|
+
rails-dom-testing (2.2.0)
|
155
|
+
activesupport (>= 5.0.0)
|
156
|
+
minitest
|
128
157
|
nokogiri (>= 1.6)
|
129
158
|
rails-html-sanitizer (1.6.0)
|
130
159
|
loofah (~> 2.21)
|
131
160
|
nokogiri (~> 1.14)
|
132
|
-
railties (7.0
|
133
|
-
actionpack (= 7.0
|
134
|
-
activesupport (= 7.0
|
135
|
-
|
161
|
+
railties (7.1.0)
|
162
|
+
actionpack (= 7.1.0)
|
163
|
+
activesupport (= 7.1.0)
|
164
|
+
irb
|
165
|
+
rackup (>= 1.0.0)
|
136
166
|
rake (>= 12.2)
|
137
|
-
thor (~> 1.0)
|
138
|
-
zeitwerk (~> 2.
|
167
|
+
thor (~> 1.0, >= 1.2.2)
|
168
|
+
zeitwerk (~> 2.6)
|
139
169
|
rake (13.0.6)
|
170
|
+
rdoc (6.5.0)
|
171
|
+
psych (>= 4.0.0)
|
172
|
+
reline (0.3.9)
|
173
|
+
io-console (~> 0.5)
|
174
|
+
ruby2_keywords (0.0.5)
|
175
|
+
stringio (3.0.8)
|
140
176
|
thor (1.2.2)
|
141
|
-
timeout (0.
|
177
|
+
timeout (0.4.0)
|
142
178
|
tzinfo (2.0.6)
|
143
179
|
concurrent-ruby (~> 1.0)
|
144
|
-
|
180
|
+
webrick (1.8.1)
|
181
|
+
websocket-driver (0.7.6)
|
145
182
|
websocket-extensions (>= 0.1.0)
|
146
183
|
websocket-extensions (0.1.5)
|
147
|
-
zeitwerk (2.6.
|
184
|
+
zeitwerk (2.6.12)
|
148
185
|
|
149
186
|
PLATFORMS
|
150
187
|
arm64-darwin
|
151
|
-
ruby
|
152
188
|
x86_64-darwin
|
153
189
|
x86_64-linux
|
154
190
|
|
@@ -156,4 +192,4 @@ DEPENDENCIES
|
|
156
192
|
log_sanity!
|
157
193
|
|
158
194
|
BUNDLED WITH
|
159
|
-
2.
|
195
|
+
2.4.10
|
data/README.md
CHANGED
@@ -27,11 +27,16 @@ Example output: (Multi-line and extra whitespace added for readability; normally
|
|
27
27
|
|
28
28
|
### Installation
|
29
29
|
|
30
|
-
|
30
|
+
For Rails 7.1+, use log_sanity 2.x:
|
31
31
|
```ruby
|
32
32
|
gem 'log_sanity'
|
33
33
|
```
|
34
34
|
|
35
|
+
For Rails 5.2, 6.x, or 7.0, use log_sanity 1.x:
|
36
|
+
```ruby
|
37
|
+
gem 'log_sanity', '~> 1'
|
38
|
+
```
|
39
|
+
|
35
40
|
By default, LogSanity does not enable itself. To do so, in `config/environments/production.rb` add:
|
36
41
|
```ruby
|
37
42
|
config.logsanity.enabled = true
|
@@ -47,7 +52,7 @@ LogSanity initializes after running `application.rb` and `config/environments/*.
|
|
47
52
|
|
48
53
|
However, `initializers/*.rb` may be used to reduce the scope of what's logged. For example, to skip logging of ActiveJob requests only:
|
49
54
|
```ruby
|
50
|
-
# initializers/
|
55
|
+
# initializers/log_sanity.rb
|
51
56
|
LogSanity::LogSubscriber::ActiveJob.detach_from :active_job
|
52
57
|
```
|
53
58
|
|
@@ -130,7 +135,7 @@ However, if `true`, you'll see:
|
|
130
135
|
|
131
136
|
##### String formatting
|
132
137
|
|
133
|
-
When LogSanity initializes, it replaces the Rails log formatter with its own, but saves the old one for outputting strings (
|
138
|
+
When LogSanity initializes, it replaces the Rails log formatter with its own, but saves the old one for outputting strings (used when `json_strings` is `false`). This means you can still configure the formatting of those. For example, to use Logger's default formatting (instead of Rails' default):
|
134
139
|
|
135
140
|
```ruby
|
136
141
|
config.log_formatter = ::Logger::Formatter.new
|
@@ -152,7 +157,7 @@ LogSanity takes these and adds them to the default request log entry (but _not_
|
|
152
157
|
|
153
158
|
### Additional notes
|
154
159
|
|
155
|
-
LogSanity is intended for production use at log_level info. At level debug, some logs are simply turned off. Others may continue to output as normal strings (such as ActiveRecord).
|
160
|
+
LogSanity is intended for production use at log_level info. At level debug, some logs are simply turned off. Others may continue to output as normal strings (such as ActiveRecord queries).
|
156
161
|
|
157
162
|
If not using tags, there is no need to use ActiveSupport::TaggedLogging with your logger. Just set the logger directly (if not using the default):
|
158
163
|
```ruby
|
@@ -161,8 +166,6 @@ config.logger = ActiveSupport::Logger.new(STDOUT)
|
|
161
166
|
|
162
167
|
All default output includes the :uuid/:request_id using the key "rq". There is no need to add \[:uuid] to `config.log_tags`.
|
163
168
|
|
164
|
-
`ActionController::RoutingError` exceptions are always silenced and turned into a simple 404 log entry.
|
165
|
-
|
166
169
|
The request path is not included, as it mostly just duplicates `route` and `params`. If you need it, you could add it using `config.log_tags = [:filtered_path]`. Alternatively, consider adding X-Request-Id to your `nginx` (or other webserver) logs and correlating to those logs instead.
|
167
170
|
|
168
171
|
The `total` duration may be longer than you're used to seeing. By default, Rails only counts the time inside the application controller. In contrast, LogSanity also includes all the middleware between itself and the application controller. While this isn't the entire picture, it is closer to the actual real time elapsed.
|
@@ -173,7 +176,6 @@ The `total` duration may be longer than you're used to seeing. By default, Rails
|
|
173
176
|
In short:
|
174
177
|
* Removes all default Rails logging, replacing it with its own
|
175
178
|
* Replaces Rails::Rack::Logger middleware with its own
|
176
|
-
* Adds middleware to intercept routing errors
|
177
179
|
* Replaces the current logger's formatter
|
178
180
|
|
179
181
|
|
@@ -13,6 +13,11 @@ module LogSanity
|
|
13
13
|
'queue' => job.queue_name
|
14
14
|
}
|
15
15
|
e['params'] = job.arguments if job.arguments.any?
|
16
|
+
if error = event.payload[:exception_object] || job.enqueue_error
|
17
|
+
e['error'] = error
|
18
|
+
elsif event.payload[:aborted]
|
19
|
+
e['callback_halt'] = 'before_enqueue'
|
20
|
+
end
|
16
21
|
e
|
17
22
|
end
|
18
23
|
end
|
@@ -29,10 +34,27 @@ module LogSanity
|
|
29
34
|
'start_at' => job.scheduled_at
|
30
35
|
}
|
31
36
|
e['params'] = job.arguments if job.arguments.any?
|
37
|
+
if error = event.payload[:exception_object] || job.enqueue_error
|
38
|
+
e['error'] = error
|
39
|
+
elsif event.payload[:aborted]
|
40
|
+
e['callback_halt'] = 'before_enqueue'
|
41
|
+
end
|
32
42
|
e
|
33
43
|
end
|
34
44
|
end
|
35
45
|
|
46
|
+
def enqueue_all(event)
|
47
|
+
info do
|
48
|
+
total = event.payload[:jobs].size
|
49
|
+
enqueued = event.payload[:enqueued_count]
|
50
|
+
{ 'at' => Time.now,
|
51
|
+
'event' => 'bulk_enqueue',
|
52
|
+
'enqueued' => enqueued,
|
53
|
+
'failed' => total - enqueued,
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
36
58
|
# def perform_start(event)
|
37
59
|
# info do
|
38
60
|
# job = event.payload[:job]
|
@@ -60,6 +82,11 @@ module LogSanity
|
|
60
82
|
'duration' => {'total' => event.duration.round}
|
61
83
|
}
|
62
84
|
e['params'] = job.arguments if job.arguments.any?
|
85
|
+
if error = event.payload[:exception_object]
|
86
|
+
e['error'] = error
|
87
|
+
elsif event.payload[:aborted]
|
88
|
+
e['callback_halt'] = 'before_perform'
|
89
|
+
end
|
63
90
|
e
|
64
91
|
end
|
65
92
|
end
|
@@ -9,15 +9,21 @@ module LogSanity
|
|
9
9
|
request = ActionDispatch::Request.new(env)
|
10
10
|
|
11
11
|
conditionally_silence(request) do |silence|
|
12
|
+
payload = {env: env, request: request, silence: silence}
|
13
|
+
handle = start(payload)
|
12
14
|
begin
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
status, headers, body = response = @app.call(env)
|
16
|
+
payload[:response] = response
|
17
|
+
body = Rack::BodyProxy.new(body){ handle.finish }
|
18
|
+
if response.frozen?
|
19
|
+
[status, headers, body]
|
20
|
+
else
|
21
|
+
response[2] = body
|
22
|
+
response
|
17
23
|
end
|
18
|
-
resp
|
19
24
|
rescue Exception => e
|
20
|
-
|
25
|
+
payload[:exception] = e
|
26
|
+
handle.finish
|
21
27
|
raise e
|
22
28
|
end
|
23
29
|
end
|
@@ -39,15 +45,12 @@ module LogSanity
|
|
39
45
|
|
40
46
|
private
|
41
47
|
|
42
|
-
def start(
|
48
|
+
def start(payload)
|
43
49
|
LogSanity.reset_fields
|
44
50
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
45
|
-
instrumenter.
|
46
|
-
|
47
|
-
|
48
|
-
def finish(params)
|
49
|
-
instrumenter = ActiveSupport::Notifications.instrumenter
|
50
|
-
instrumenter.finish 'request.action_dispatch', params
|
51
|
+
instrumenter.build_handle('request.action_dispatch', payload).tap do |handle|
|
52
|
+
handle.start
|
53
|
+
end
|
51
54
|
end
|
52
55
|
|
53
56
|
def silence_path?(request)
|
data/lib/log_sanity/railtie.rb
CHANGED
@@ -13,71 +13,72 @@ module LogSanity
|
|
13
13
|
end
|
14
14
|
|
15
15
|
initializer "log_sanity.configure", before: :load_config_initializers do |app|
|
16
|
+
ActiveSupport::BroadcastLogger.include LogSanity::Extensions::BroadcastLogger
|
16
17
|
app.config.log_tags ||= []
|
18
|
+
|
17
19
|
if app.config.logsanity.enabled
|
18
20
|
orig_formatter = Rails.logger.formatter
|
19
21
|
Rails.logger.formatter = LogSanity::Formatter.new
|
20
22
|
if app.config.logsanity.json_strings
|
21
23
|
Rails.logger.formatter.string_formatter = false
|
22
|
-
|
23
|
-
Rails.logger.formatter.string_formatter = orig_formatter
|
24
|
+
elsif orig_formatter
|
25
|
+
Rails.logger.formatter.string_formatter = orig_formatter
|
24
26
|
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if defined?(ActionMailer)
|
31
|
-
require 'action_mailer/log_subscriber'
|
32
|
-
ActionMailer::LogSubscriber.detach_from :action_mailer
|
33
|
-
end
|
34
|
-
if defined?(ActionView)
|
35
|
-
require 'action_view/log_subscriber'
|
36
|
-
ActionView::LogSubscriber.detach_from :action_view
|
37
|
-
end
|
38
|
-
if defined?(ActiveJob)
|
39
|
-
require 'active_job/logging'
|
40
|
-
begin
|
41
|
-
require 'active_job/log_subscriber' # >= 6.1
|
42
|
-
rescue LoadError
|
43
|
-
end
|
44
|
-
if defined?(ActiveJob::LogSubscriber) # >= 6.1
|
45
|
-
ActiveJob::LogSubscriber.detach_from :active_job
|
46
|
-
else # < 6.1
|
47
|
-
ActiveJob::Logging::LogSubscriber.detach_from :active_job
|
48
|
-
end
|
49
|
-
end
|
50
|
-
if defined?(ActiveRecord)
|
51
|
-
# require 'active_record/log_subscriber'
|
52
|
-
# ActiveRecord::LogSubscriber.detach_from :active_record
|
53
|
-
# this turns off measurements too
|
54
|
-
if ActiveRecord::Base.logger.debug?
|
55
|
-
Rails.logger.info '[LogSanity] ActiveRecord::Base.logger in debug mode and will still log queries'
|
56
|
-
end
|
28
|
+
app.middleware.swap Rails::Rack::Logger, LogSanity::RequestLogger
|
29
|
+
|
30
|
+
ActiveSupport.on_load(:action_cable_connection) do
|
31
|
+
prepend LogSanity::Extensions::ActionCableConnection
|
57
32
|
end
|
58
33
|
|
59
34
|
ActiveSupport.on_load(:action_cable) do
|
35
|
+
# set just ActionCable's logger to :warn to silence several non-instrumented logs
|
60
36
|
orig_logger = logger || Rails.logger
|
61
37
|
if orig_logger.level < Logger::WARN
|
62
38
|
self.logger = orig_logger.clone.tap do |l|
|
63
39
|
l.level = Logger::WARN
|
64
40
|
end
|
65
41
|
end
|
42
|
+
LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
|
66
43
|
end
|
67
|
-
|
68
|
-
|
44
|
+
|
45
|
+
ActiveSupport.on_load(:action_controller, run_once: true) do
|
46
|
+
ActionController::LogSubscriber.detach_from :action_controller
|
47
|
+
LogSanity::LogSubscriber::ActionController.attach_to :action_controller
|
69
48
|
end
|
70
49
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
LogSanity::LogSubscriber::ActiveJob.attach_to :active_job
|
50
|
+
ActiveSupport.on_load(:action_dispatch_request) do
|
51
|
+
ActionDispatch::LogSubscriber.detach_from :action_dispatch
|
52
|
+
LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
|
53
|
+
end
|
76
54
|
|
77
|
-
|
55
|
+
ActiveSupport.on_load(:action_mailer) do
|
56
|
+
ActionMailer::LogSubscriber.detach_from :action_mailer
|
57
|
+
LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
|
58
|
+
end
|
59
|
+
|
60
|
+
ActiveSupport.on_load(:action_view) do
|
61
|
+
ActionView::LogSubscriber.detach_from :action_view
|
62
|
+
if ActionView::LogSubscriber.logger.debug?
|
63
|
+
ActiveSupport::Notifications.unsubscribe 'render_template.action_view'
|
64
|
+
ActiveSupport::Notifications.unsubscribe 'render_layout.action_view'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
ActiveSupport.on_load(:active_job) do
|
69
|
+
ActiveJob::LogSubscriber.detach_from :active_job
|
70
|
+
LogSanity::LogSubscriber::ActiveJob.attach_to :active_job
|
71
|
+
end
|
72
|
+
|
73
|
+
ActiveSupport.on_load(:active_record) do
|
74
|
+
# ActiveRecord::LogSubscriber.detach_from :active_record
|
75
|
+
# only logs at :debug level. since log_sanity offers no replacements, don't detach. if logging in
|
76
|
+
# production at :debug, may silence anyway by adding an initializer with the above detach_from.
|
77
|
+
if ActiveRecord::Base.logger.debug?
|
78
|
+
Rails.logger.info '[LogSanity] ActiveRecord::Base.logger in debug mode and will still log queries'
|
79
|
+
end
|
80
|
+
end
|
78
81
|
|
79
|
-
show_exceptions_app = app.config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
|
80
|
-
app.middleware.use LogSanity::RoutingErrorCatcher, show_exceptions_app
|
81
82
|
end
|
82
83
|
end
|
83
84
|
|
data/lib/log_sanity/version.rb
CHANGED
data/lib/log_sanity.rb
CHANGED
@@ -1,28 +1,25 @@
|
|
1
|
-
%w(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
%w(
|
2
|
+
formatter
|
3
|
+
railtie
|
4
|
+
log_subscribers/base
|
5
|
+
log_subscribers/action_cable
|
6
|
+
log_subscribers/action_controller
|
7
|
+
log_subscribers/action_dispatch
|
8
|
+
log_subscribers/action_mailer
|
9
|
+
log_subscribers/active_job
|
10
|
+
middleware/request_logger
|
11
|
+
extensions/action_cable_connection
|
12
|
+
extensions/action_controller_helper
|
13
|
+
extensions/broadcast_logger
|
14
|
+
).each do |fn|
|
15
15
|
require_relative "log_sanity/#{fn}"
|
16
16
|
end
|
17
17
|
|
18
|
-
if Rails.version < '6'
|
19
|
-
ActiveSupport::Subscriber.include LogSanity::Extensions::ActiveSupportSubscriber
|
20
|
-
end
|
21
|
-
|
22
18
|
module LogSanity
|
23
19
|
module_function
|
24
20
|
|
25
21
|
def fields
|
22
|
+
# this is fiber-local
|
26
23
|
Thread.current[:logsanity_fields] || reset_fields
|
27
24
|
end
|
28
25
|
|
data/log_sanity.gemspec
CHANGED
@@ -12,6 +12,8 @@ require "log_sanity"
|
|
12
12
|
|
13
13
|
module Dummy
|
14
14
|
class Application < Rails::Application
|
15
|
+
config.load_defaults Rails::VERSION::STRING.to_f
|
16
|
+
|
15
17
|
# Settings in config/environments/* take precedence over those specified here.
|
16
18
|
# Application configuration should go into files in config/initializers
|
17
19
|
# -- all .rb files in that directory are automatically loaded.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log_sanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thomas morgan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '7.2'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '7.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.2'
|
@@ -48,7 +48,7 @@ files:
|
|
48
48
|
- lib/log_sanity.rb
|
49
49
|
- lib/log_sanity/extensions/action_cable_connection.rb
|
50
50
|
- lib/log_sanity/extensions/action_controller_helper.rb
|
51
|
-
- lib/log_sanity/extensions/
|
51
|
+
- lib/log_sanity/extensions/broadcast_logger.rb
|
52
52
|
- lib/log_sanity/formatter.rb
|
53
53
|
- lib/log_sanity/log_subscribers/action_cable.rb
|
54
54
|
- lib/log_sanity/log_subscribers/action_controller.rb
|
@@ -57,7 +57,6 @@ files:
|
|
57
57
|
- lib/log_sanity/log_subscribers/active_job.rb
|
58
58
|
- lib/log_sanity/log_subscribers/base.rb
|
59
59
|
- lib/log_sanity/middleware/request_logger.rb
|
60
|
-
- lib/log_sanity/middleware/routing_error_catcher.rb
|
61
60
|
- lib/log_sanity/railtie.rb
|
62
61
|
- lib/log_sanity/version.rb
|
63
62
|
- lib/tasks/log_sanity_tasks.rake
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module LogSanity
|
2
|
-
module Extensions
|
3
|
-
module ActiveSupportSubscriber
|
4
|
-
extend ActiveSupport::Concern
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def detach_from(namespace, notifier=ActiveSupport::Notifications)
|
8
|
-
subscribers.select{|s| s.is_a? self}.each do |subscriber|
|
9
|
-
subscriber.public_methods(false).each do |event|
|
10
|
-
pattern = "#{event}.#{namespace}"
|
11
|
-
notifier.notifier.listeners_for(pattern).each do |listener|
|
12
|
-
if listener.instance_variable_get(:@delegate) == subscriber
|
13
|
-
notifier.unsubscribe listener
|
14
|
-
subscriber.patterns.delete pattern
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
subscribers.delete subscriber if subscriber.patterns.empty?
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# middleware to catch and sanely handle routing errors without treating them
|
2
|
-
# like all other exceptions (that is, without verbose backtraces and other
|
3
|
-
# such).
|
4
|
-
# intended to be added to the end of the middleware stack (nearest the app).
|
5
|
-
# while built on top of ShowExceptions to reuse its error rendering logic,
|
6
|
-
# does not replace it.
|
7
|
-
|
8
|
-
module LogSanity
|
9
|
-
class RoutingErrorCatcher < ActionDispatch::ShowExceptions
|
10
|
-
|
11
|
-
def call(env)
|
12
|
-
request = ActionDispatch::Request.new env
|
13
|
-
_, headers, body = response = @app.call(env)
|
14
|
-
|
15
|
-
if headers['X-Cascade'] == 'pass'
|
16
|
-
body.close if body.respond_to?(:close)
|
17
|
-
raise ActionController::RoutingError, "No route matches [#{env['REQUEST_METHOD']}] #{env['PATH_INFO'].inspect}"
|
18
|
-
end
|
19
|
-
|
20
|
-
response
|
21
|
-
rescue ActionController::RoutingError => exception
|
22
|
-
if Rails.version >= '7.1'
|
23
|
-
backtrace_cleaner = request.get_header('action_dispatch.backtrace_cleaner')
|
24
|
-
wrapper = ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, exception)
|
25
|
-
if wrapper.show?(request)
|
26
|
-
render_exception(request, wrapper)
|
27
|
-
else
|
28
|
-
raise exception
|
29
|
-
end
|
30
|
-
else
|
31
|
-
if request.show_exceptions?
|
32
|
-
render_exception(request, exception)
|
33
|
-
else
|
34
|
-
raise exception
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|