log_sanity 1.3.2 → 2.1.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 +16 -0
- data/Gemfile.lock +126 -89
- data/README.md +9 -7
- 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 -46
- data/lib/log_sanity/version.rb +1 -1
- data/lib/log_sanity.rb +14 -18
- data/log_sanity.gemspec +1 -1
- data/test/dummy/config/application.rb +2 -0
- metadata +4 -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: a31fa8ea5e6350b0402815d4953541aacce034d1d551161324ea69cf08c17027
|
4
|
+
data.tar.gz: 2a159e4a522885f3b0490bdfb927339b9e7356e7674068a9b6dc48af639e9e5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8abd35592d9be60aed4d17d62cd796aefa8499d929995b1724d7c5c64b5c4df472f23617c1e8ff8a8bfcf721f7d1303951c734575c03bcc93a7e78a709895ea
|
7
|
+
data.tar.gz: bb0d38031237b63a970a7cdd07ba549aa3ab6a8bfb5dd4ab752a31bef51f09abc472284fcff6cecdfbb9a19004fe035f671739ed4e9f97ddc02c077a8f55473e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
#### 2.1.0
|
2
|
+
|
3
|
+
- Require Rails 7.1.2
|
4
|
+
- Remove BroadcastLogger extension
|
5
|
+
|
6
|
+
#### 2.0.0
|
7
|
+
|
8
|
+
- (Breaking) Require Rails 7.1
|
9
|
+
For Rails 5.2, 6.x, and 7.0, use log_sanity 1.x
|
10
|
+
- (Potentially breaking) Remove RoutingErrorCatcher middleware
|
11
|
+
Shouldn't break unless directly referenced during app's middleware setup
|
12
|
+
Mostly not needed on Rails 7.1, but for an alternative, see [rails-hush](https://github.com/zarqman/rails-hush) gem
|
13
|
+
- Handle new events and updated payloads for Rails 7.1
|
14
|
+
- Use updated instrumentation API in request_logger
|
15
|
+
- Refactor initializer to use on_load
|
16
|
+
|
1
17
|
#### 1.3.2
|
2
18
|
|
3
19
|
- Fix logging on Rails 7.1 due to default use of BroadcastLogger
|
data/Gemfile.lock
CHANGED
@@ -1,87 +1,105 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
log_sanity (1.
|
5
|
-
rails (>=
|
4
|
+
log_sanity (2.1.0)
|
5
|
+
rails (>= 7.1.2, < 7.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (7.
|
11
|
-
actionpack (= 7.
|
12
|
-
activesupport (= 7.
|
10
|
+
actioncable (7.1.2)
|
11
|
+
actionpack (= 7.1.2)
|
12
|
+
activesupport (= 7.1.2)
|
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.2)
|
17
|
+
actionpack (= 7.1.2)
|
18
|
+
activejob (= 7.1.2)
|
19
|
+
activerecord (= 7.1.2)
|
20
|
+
activestorage (= 7.1.2)
|
21
|
+
activesupport (= 7.1.2)
|
21
22
|
mail (>= 2.7.1)
|
22
23
|
net-imap
|
23
24
|
net-pop
|
24
25
|
net-smtp
|
25
|
-
actionmailer (7.
|
26
|
-
actionpack (= 7.
|
27
|
-
actionview (= 7.
|
28
|
-
activejob (= 7.
|
29
|
-
activesupport (= 7.
|
26
|
+
actionmailer (7.1.2)
|
27
|
+
actionpack (= 7.1.2)
|
28
|
+
actionview (= 7.1.2)
|
29
|
+
activejob (= 7.1.2)
|
30
|
+
activesupport (= 7.1.2)
|
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.
|
36
|
-
actionview (= 7.
|
37
|
-
activesupport (= 7.
|
38
|
-
|
35
|
+
rails-dom-testing (~> 2.2)
|
36
|
+
actionpack (7.1.2)
|
37
|
+
actionview (= 7.1.2)
|
38
|
+
activesupport (= 7.1.2)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
racc
|
41
|
+
rack (>= 2.2.4)
|
42
|
+
rack-session (>= 1.0.1)
|
39
43
|
rack-test (>= 0.6.3)
|
40
|
-
rails-dom-testing (~> 2.
|
41
|
-
rails-html-sanitizer (~> 1.
|
42
|
-
actiontext (7.
|
43
|
-
actionpack (= 7.
|
44
|
-
activerecord (= 7.
|
45
|
-
activestorage (= 7.
|
46
|
-
activesupport (= 7.
|
44
|
+
rails-dom-testing (~> 2.2)
|
45
|
+
rails-html-sanitizer (~> 1.6)
|
46
|
+
actiontext (7.1.2)
|
47
|
+
actionpack (= 7.1.2)
|
48
|
+
activerecord (= 7.1.2)
|
49
|
+
activestorage (= 7.1.2)
|
50
|
+
activesupport (= 7.1.2)
|
47
51
|
globalid (>= 0.6.0)
|
48
52
|
nokogiri (>= 1.8.5)
|
49
|
-
actionview (7.
|
50
|
-
activesupport (= 7.
|
53
|
+
actionview (7.1.2)
|
54
|
+
activesupport (= 7.1.2)
|
51
55
|
builder (~> 3.1)
|
52
|
-
erubi (~> 1.
|
53
|
-
rails-dom-testing (~> 2.
|
54
|
-
rails-html-sanitizer (~> 1.
|
55
|
-
activejob (7.
|
56
|
-
activesupport (= 7.
|
56
|
+
erubi (~> 1.11)
|
57
|
+
rails-dom-testing (~> 2.2)
|
58
|
+
rails-html-sanitizer (~> 1.6)
|
59
|
+
activejob (7.1.2)
|
60
|
+
activesupport (= 7.1.2)
|
57
61
|
globalid (>= 0.3.6)
|
58
|
-
activemodel (7.
|
59
|
-
activesupport (= 7.
|
60
|
-
activerecord (7.
|
61
|
-
activemodel (= 7.
|
62
|
-
activesupport (= 7.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
62
|
+
activemodel (7.1.2)
|
63
|
+
activesupport (= 7.1.2)
|
64
|
+
activerecord (7.1.2)
|
65
|
+
activemodel (= 7.1.2)
|
66
|
+
activesupport (= 7.1.2)
|
67
|
+
timeout (>= 0.4.0)
|
68
|
+
activestorage (7.1.2)
|
69
|
+
actionpack (= 7.1.2)
|
70
|
+
activejob (= 7.1.2)
|
71
|
+
activerecord (= 7.1.2)
|
72
|
+
activesupport (= 7.1.2)
|
68
73
|
marcel (~> 1.0)
|
69
|
-
|
70
|
-
|
74
|
+
activesupport (7.1.2)
|
75
|
+
base64
|
76
|
+
bigdecimal
|
71
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
78
|
+
connection_pool (>= 2.2.5)
|
79
|
+
drb
|
72
80
|
i18n (>= 1.6, < 2)
|
73
81
|
minitest (>= 5.1)
|
82
|
+
mutex_m
|
74
83
|
tzinfo (~> 2.0)
|
84
|
+
base64 (0.2.0)
|
85
|
+
bigdecimal (3.1.4)
|
75
86
|
builder (3.2.4)
|
76
87
|
concurrent-ruby (1.2.2)
|
88
|
+
connection_pool (2.4.1)
|
77
89
|
crass (1.0.6)
|
78
|
-
date (3.3.
|
90
|
+
date (3.3.4)
|
91
|
+
drb (2.2.0)
|
92
|
+
ruby2_keywords
|
79
93
|
erubi (1.12.0)
|
80
|
-
globalid (1.1
|
81
|
-
activesupport (>=
|
82
|
-
i18n (1.
|
94
|
+
globalid (1.2.1)
|
95
|
+
activesupport (>= 6.1)
|
96
|
+
i18n (1.14.1)
|
83
97
|
concurrent-ruby (~> 1.0)
|
84
|
-
|
98
|
+
io-console (0.6.0)
|
99
|
+
irb (1.9.0)
|
100
|
+
rdoc
|
101
|
+
reline (>= 0.3.8)
|
102
|
+
loofah (2.21.4)
|
85
103
|
crass (~> 1.0.2)
|
86
104
|
nokogiri (>= 1.12.0)
|
87
105
|
mail (2.8.1)
|
@@ -90,65 +108,84 @@ GEM
|
|
90
108
|
net-pop
|
91
109
|
net-smtp
|
92
110
|
marcel (1.0.2)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
net-imap (0.
|
111
|
+
mini_mime (1.1.5)
|
112
|
+
minitest (5.20.0)
|
113
|
+
mutex_m (0.2.0)
|
114
|
+
net-imap (0.4.4)
|
97
115
|
date
|
98
116
|
net-protocol
|
99
117
|
net-pop (0.1.2)
|
100
118
|
net-protocol
|
101
|
-
net-protocol (0.2.
|
119
|
+
net-protocol (0.2.2)
|
102
120
|
timeout
|
103
|
-
net-smtp (0.
|
121
|
+
net-smtp (0.4.0)
|
104
122
|
net-protocol
|
105
123
|
nio4r (2.5.9)
|
106
|
-
nokogiri (1.15.
|
124
|
+
nokogiri (1.15.4-arm64-darwin)
|
125
|
+
racc (~> 1.4)
|
126
|
+
nokogiri (1.15.4-x86_64-darwin)
|
127
|
+
racc (~> 1.4)
|
128
|
+
nokogiri (1.15.4-x86_64-linux)
|
107
129
|
racc (~> 1.4)
|
108
|
-
|
109
|
-
|
130
|
+
psych (5.1.1.1)
|
131
|
+
stringio
|
132
|
+
racc (1.7.3)
|
133
|
+
rack (3.0.8)
|
134
|
+
rack-session (2.0.0)
|
135
|
+
rack (>= 3.0.0)
|
110
136
|
rack-test (2.1.0)
|
111
137
|
rack (>= 1.3)
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
138
|
+
rackup (2.1.0)
|
139
|
+
rack (>= 3)
|
140
|
+
webrick (~> 1.8)
|
141
|
+
rails (7.1.2)
|
142
|
+
actioncable (= 7.1.2)
|
143
|
+
actionmailbox (= 7.1.2)
|
144
|
+
actionmailer (= 7.1.2)
|
145
|
+
actionpack (= 7.1.2)
|
146
|
+
actiontext (= 7.1.2)
|
147
|
+
actionview (= 7.1.2)
|
148
|
+
activejob (= 7.1.2)
|
149
|
+
activemodel (= 7.1.2)
|
150
|
+
activerecord (= 7.1.2)
|
151
|
+
activestorage (= 7.1.2)
|
152
|
+
activesupport (= 7.1.2)
|
124
153
|
bundler (>= 1.15.0)
|
125
|
-
railties (= 7.
|
126
|
-
rails-dom-testing (2.0
|
127
|
-
activesupport (>=
|
154
|
+
railties (= 7.1.2)
|
155
|
+
rails-dom-testing (2.2.0)
|
156
|
+
activesupport (>= 5.0.0)
|
157
|
+
minitest
|
128
158
|
nokogiri (>= 1.6)
|
129
159
|
rails-html-sanitizer (1.6.0)
|
130
160
|
loofah (~> 2.21)
|
131
161
|
nokogiri (~> 1.14)
|
132
|
-
railties (7.
|
133
|
-
actionpack (= 7.
|
134
|
-
activesupport (= 7.
|
135
|
-
|
162
|
+
railties (7.1.2)
|
163
|
+
actionpack (= 7.1.2)
|
164
|
+
activesupport (= 7.1.2)
|
165
|
+
irb
|
166
|
+
rackup (>= 1.0.0)
|
136
167
|
rake (>= 12.2)
|
137
|
-
thor (~> 1.0)
|
138
|
-
zeitwerk (~> 2.
|
139
|
-
rake (13.0
|
140
|
-
|
141
|
-
|
168
|
+
thor (~> 1.0, >= 1.2.2)
|
169
|
+
zeitwerk (~> 2.6)
|
170
|
+
rake (13.1.0)
|
171
|
+
rdoc (6.6.0)
|
172
|
+
psych (>= 4.0.0)
|
173
|
+
reline (0.4.0)
|
174
|
+
io-console (~> 0.5)
|
175
|
+
ruby2_keywords (0.0.5)
|
176
|
+
stringio (3.0.9)
|
177
|
+
thor (1.3.0)
|
178
|
+
timeout (0.4.1)
|
142
179
|
tzinfo (2.0.6)
|
143
180
|
concurrent-ruby (~> 1.0)
|
144
|
-
|
181
|
+
webrick (1.8.1)
|
182
|
+
websocket-driver (0.7.6)
|
145
183
|
websocket-extensions (>= 0.1.0)
|
146
184
|
websocket-extensions (0.1.5)
|
147
|
-
zeitwerk (2.6.
|
185
|
+
zeitwerk (2.6.12)
|
148
186
|
|
149
187
|
PLATFORMS
|
150
188
|
arm64-darwin
|
151
|
-
ruby
|
152
189
|
x86_64-darwin
|
153
190
|
x86_64-linux
|
154
191
|
|
@@ -156,4 +193,4 @@ DEPENDENCIES
|
|
156
193
|
log_sanity!
|
157
194
|
|
158
195
|
BUNDLED WITH
|
159
|
-
2.
|
196
|
+
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
@@ -14,72 +14,70 @@ module LogSanity
|
|
14
14
|
|
15
15
|
initializer "log_sanity.configure", before: :load_config_initializers do |app|
|
16
16
|
app.config.log_tags ||= []
|
17
|
+
|
17
18
|
if app.config.logsanity.enabled
|
18
19
|
orig_formatter = Rails.logger.formatter
|
19
20
|
Rails.logger.formatter = LogSanity::Formatter.new
|
20
21
|
if app.config.logsanity.json_strings
|
21
22
|
Rails.logger.formatter.string_formatter = false
|
22
|
-
|
23
|
-
Rails.logger.formatter.string_formatter = orig_formatter
|
23
|
+
elsif orig_formatter
|
24
|
+
Rails.logger.formatter.string_formatter = orig_formatter
|
25
|
+
end
|
26
|
+
|
27
|
+
app.middleware.swap Rails::Rack::Logger, LogSanity::RequestLogger
|
28
|
+
|
29
|
+
ActiveSupport.on_load(:action_cable_connection) do
|
30
|
+
prepend LogSanity::Extensions::ActionCableConnection
|
31
|
+
end
|
32
|
+
|
33
|
+
ActiveSupport.on_load(:action_cable) do
|
34
|
+
# set just ActionCable's logger to :warn to silence several non-instrumented logs
|
35
|
+
orig_logger = logger || Rails.logger
|
36
|
+
if orig_logger.level < Logger::WARN
|
37
|
+
self.logger = orig_logger.clone.tap do |l|
|
38
|
+
l.level = Logger::WARN
|
39
|
+
end
|
40
|
+
end
|
41
|
+
LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
|
24
42
|
end
|
25
43
|
|
26
|
-
|
27
|
-
require 'action_controller/log_subscriber'
|
44
|
+
ActiveSupport.on_load(:action_controller, run_once: true) do
|
28
45
|
ActionController::LogSubscriber.detach_from :action_controller
|
46
|
+
LogSanity::LogSubscriber::ActionController.attach_to :action_controller
|
29
47
|
end
|
30
|
-
|
31
|
-
|
48
|
+
|
49
|
+
ActiveSupport.on_load(:action_dispatch_request) do
|
50
|
+
ActionDispatch::LogSubscriber.detach_from :action_dispatch
|
51
|
+
LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
|
52
|
+
end
|
53
|
+
|
54
|
+
ActiveSupport.on_load(:action_mailer) do
|
32
55
|
ActionMailer::LogSubscriber.detach_from :action_mailer
|
56
|
+
LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
|
33
57
|
end
|
34
|
-
|
35
|
-
|
58
|
+
|
59
|
+
ActiveSupport.on_load(:action_view) do
|
36
60
|
ActionView::LogSubscriber.detach_from :action_view
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
61
|
+
if ActionView::LogSubscriber.logger.debug?
|
62
|
+
ActiveSupport::Notifications.unsubscribe 'render_template.action_view'
|
63
|
+
ActiveSupport::Notifications.unsubscribe 'render_layout.action_view'
|
48
64
|
end
|
49
65
|
end
|
50
|
-
|
51
|
-
|
66
|
+
|
67
|
+
ActiveSupport.on_load(:active_job) do
|
68
|
+
ActiveJob::LogSubscriber.detach_from :active_job
|
69
|
+
LogSanity::LogSubscriber::ActiveJob.attach_to :active_job
|
70
|
+
end
|
71
|
+
|
72
|
+
ActiveSupport.on_load(:active_record) do
|
52
73
|
# ActiveRecord::LogSubscriber.detach_from :active_record
|
53
|
-
#
|
74
|
+
# only logs at :debug level. since log_sanity offers no replacements, don't detach. if logging in
|
75
|
+
# production at :debug, may silence anyway by adding an initializer with the above detach_from.
|
54
76
|
if ActiveRecord::Base.logger.debug?
|
55
77
|
Rails.logger.info '[LogSanity] ActiveRecord::Base.logger in debug mode and will still log queries'
|
56
78
|
end
|
57
79
|
end
|
58
80
|
|
59
|
-
ActiveSupport.on_load(:action_cable) do
|
60
|
-
if Rails.version < '7.1'
|
61
|
-
orig_logger = logger || Rails.logger
|
62
|
-
if orig_logger.level < Logger::WARN
|
63
|
-
self.logger = orig_logger.clone.tap do |l|
|
64
|
-
l.level = Logger::WARN
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
ActiveSupport.on_load(:action_cable_connection) do
|
70
|
-
prepend LogSanity::Extensions::ActionCableConnection
|
71
|
-
end
|
72
|
-
|
73
|
-
LogSanity::LogSubscriber::ActionCable.attach_to :action_cable
|
74
|
-
LogSanity::LogSubscriber::ActionController.attach_to :action_controller
|
75
|
-
LogSanity::LogSubscriber::ActionDispatch.attach_to :action_dispatch
|
76
|
-
LogSanity::LogSubscriber::ActionMailer.attach_to :action_mailer
|
77
|
-
LogSanity::LogSubscriber::ActiveJob.attach_to :active_job
|
78
|
-
|
79
|
-
app.middleware.swap Rails::Rack::Logger, LogSanity::RequestLogger
|
80
|
-
|
81
|
-
show_exceptions_app = app.config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
|
82
|
-
app.middleware.use LogSanity::RoutingErrorCatcher, show_exceptions_app
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
data/lib/log_sanity/version.rb
CHANGED
data/lib/log_sanity.rb
CHANGED
@@ -1,28 +1,24 @@
|
|
1
|
-
%w(
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
).each do |fn|
|
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
|
+
).each do |fn|
|
15
14
|
require_relative "log_sanity/#{fn}"
|
16
15
|
end
|
17
16
|
|
18
|
-
if Rails.version < '6'
|
19
|
-
ActiveSupport::Subscriber.include LogSanity::Extensions::ActiveSupportSubscriber
|
20
|
-
end
|
21
|
-
|
22
17
|
module LogSanity
|
23
18
|
module_function
|
24
19
|
|
25
20
|
def fields
|
21
|
+
# this is fiber-local
|
26
22
|
Thread.current[:logsanity_fields] || reset_fields
|
27
23
|
end
|
28
24
|
|
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: 1.
|
4
|
+
version: 2.1.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-11-11 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.2
|
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.2
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '7.2'
|
@@ -48,7 +48,6 @@ 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/active_support_subscriber.rb
|
52
51
|
- lib/log_sanity/formatter.rb
|
53
52
|
- lib/log_sanity/log_subscribers/action_cable.rb
|
54
53
|
- lib/log_sanity/log_subscribers/action_controller.rb
|
@@ -57,7 +56,6 @@ files:
|
|
57
56
|
- lib/log_sanity/log_subscribers/active_job.rb
|
58
57
|
- lib/log_sanity/log_subscribers/base.rb
|
59
58
|
- lib/log_sanity/middleware/request_logger.rb
|
60
|
-
- lib/log_sanity/middleware/routing_error_catcher.rb
|
61
59
|
- lib/log_sanity/railtie.rb
|
62
60
|
- lib/log_sanity/version.rb
|
63
61
|
- 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
|