minato_logger 0.2.13 → 0.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 11f2e7e39012b964d05e807bc6e41196166842c527430f8f94f700f7b7dde6c3
|
|
4
|
+
data.tar.gz: f55d180a17a03bac367ec93f8bf8d5939e47ab09f430b71b244abd3c03b5f1dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 58a321a141ae059022e2303389d41bd8766a38c9d02e7aab5f2700766d1abd4d31438d831b99a06b85c9cbae5c74200d581e829fef0ec5109af45a4d0b0486d1
|
|
7
|
+
data.tar.gz: 0ab555ce2babcc1a5787ea59e8fec0661c7681f971ed249696f398c42a44d154335adcaa7a303f2424d5a838ce587ed53284fbd8076f1160f8ed8b86c2d9f00a
|
data/.rubocop.yml
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
module MinatoLogger
|
|
4
4
|
class Configuration
|
|
5
|
-
attr_reader :middleware
|
|
5
|
+
attr_reader :middleware, :route_blacklist
|
|
6
6
|
|
|
7
7
|
def initialize
|
|
8
8
|
@middleware = MinatoLogger::Middleware.new
|
|
9
|
+
@route_blacklist = %w[/health/alive /health/ready]
|
|
9
10
|
|
|
10
11
|
yield(self) if block_given?
|
|
11
12
|
end
|
data/lib/minato_logger/logger.rb
CHANGED
|
@@ -15,14 +15,13 @@ module MinatoLogger
|
|
|
15
15
|
private
|
|
16
16
|
|
|
17
17
|
def call_app(request, env)
|
|
18
|
-
|
|
18
|
+
should_log = should_log?(request)
|
|
19
|
+
log_request(request, env) if should_log
|
|
19
20
|
handle = dispatch_request_event(request)
|
|
20
21
|
data = process_request(env)
|
|
21
|
-
|
|
22
|
-
ensure
|
|
23
|
-
duration = ((current_time - data[:start_time]) * 1000).round(2)
|
|
24
|
-
log_response(request, env, data.merge({ duration: duration }))
|
|
22
|
+
log_response(request, env, data) if should_log
|
|
25
23
|
finish_request_instrumentation(handle, env['rails.rack_logger_tag_count'])
|
|
24
|
+
[data[:status], data[:headers], [data[:body]]]
|
|
26
25
|
end
|
|
27
26
|
|
|
28
27
|
def compute_tags(request)
|
|
@@ -35,6 +34,15 @@ module MinatoLogger
|
|
|
35
34
|
end
|
|
36
35
|
end
|
|
37
36
|
|
|
37
|
+
def should_log?(request)
|
|
38
|
+
blacklist = Rails.application.config.minato_logger.route_blacklist || []
|
|
39
|
+
blacklist.none? do |item|
|
|
40
|
+
next item.call(request) if item.is_a?(Proc)
|
|
41
|
+
|
|
42
|
+
request.path == item
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
38
46
|
def process_request(env)
|
|
39
47
|
data = { body: '', status: 500, start_time: current_time, headers: {} }
|
|
40
48
|
|
|
@@ -51,15 +59,16 @@ module MinatoLogger
|
|
|
51
59
|
end
|
|
52
60
|
|
|
53
61
|
def log_request(request, env)
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
payload = default_log_data(request, env).merge({
|
|
63
|
+
type: 'REQUEST',
|
|
64
|
+
message: "Receiving request #{request.method} #{request.fullpath}"
|
|
65
|
+
})
|
|
66
|
+
payload[:request].merge!({ headers: extract_request_headers(request), body: extract_request_body(request) })
|
|
67
|
+
log(payload)
|
|
60
68
|
end
|
|
61
69
|
|
|
62
70
|
def log_response(request, env, data)
|
|
71
|
+
data[:duration] = ((current_time - data[:start_time]) * 1000).round(2)
|
|
63
72
|
payload = build_response_payload(request, env, data)
|
|
64
73
|
log_level = data[:status] >= 500 ? :error : :info
|
|
65
74
|
log(payload, log_level)
|
|
@@ -67,19 +76,23 @@ module MinatoLogger
|
|
|
67
76
|
|
|
68
77
|
def default_log_data(request, env)
|
|
69
78
|
route = env['action_dispatch.route_uri_pattern'] || request.path
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
79
|
+
request = { id: request.request_id, method: request.method,
|
|
80
|
+
time: Time.zone.now.iso8601, remote_ip: request.remote_ip, route: route, ip: request.ip,
|
|
81
|
+
path: request.fullpath, params: filter_params(request) }
|
|
82
|
+
{ rails_version: Rails.version, request: request }
|
|
73
83
|
end
|
|
74
84
|
|
|
75
85
|
def build_response_payload(request, env, data)
|
|
76
|
-
default_log_data(request, env).merge({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
payload = default_log_data(request, env).merge({
|
|
87
|
+
type: 'RESPONSE', duration: data[:duration], status: data[:status],
|
|
88
|
+
message: "Responding #{request.method} #{request.fullpath} " \
|
|
89
|
+
"- #{data[:status]} (#{data[:duration]}ms)"
|
|
90
|
+
})
|
|
91
|
+
payload[:response] = {
|
|
92
|
+
body: safe_parse_json(data[:body]), headers: filter_sensitive_headers(data[:headers]),
|
|
93
|
+
status: data[:status], duration: data[:duration]
|
|
94
|
+
}
|
|
95
|
+
payload
|
|
83
96
|
end
|
|
84
97
|
|
|
85
98
|
def log(payload, level = :info)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: minato_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ferreri
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-02-
|
|
11
|
+
date: 2026-02-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|