epilog 0.3.1 → 0.4.0
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 +4 -4
- data/CHANGLOG.md +4 -0
- data/lib/epilog/context_logging.rb +57 -0
- data/lib/epilog/log_formatter.rb +3 -0
- data/lib/epilog/logger.rb +2 -0
- data/lib/epilog/mock_logger.rb +18 -3
- data/lib/epilog/rails/action_controller_subscriber.rb +11 -4
- data/lib/epilog/rails/active_job_subscriber.rb +9 -0
- data/lib/epilog/rails/log_subscriber.rb +8 -0
- data/lib/epilog/version.rb +1 -1
- data/lib/epilog.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c182e5b6fad45d60dcbf0e37843e075e6775d76e3888a632056cef356235768
|
4
|
+
data.tar.gz: bb7095818994ab3532c70c691180fe1018089e587cc7819faf1441bb6532acf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07552c37f2ebcc5febb7d94f227801c8f89e15eae7904e493c6575bd83819a1989b7229a9d1559ffc9f4651884611160b77779cfce11fa1abcf48c71bd484612
|
7
|
+
data.tar.gz: 5664a1841cdd95b1af21e8796a374f30d5ddfd26faf6ef4782abc9de435098d351f3e29d2b778358e74c1af5ae55b9cb4d4155c0cba776201ed9d350286abc41
|
data/CHANGLOG.md
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Epilog
|
4
|
+
module ContextLogger
|
5
|
+
def with_context(context)
|
6
|
+
push_context(context)
|
7
|
+
yield
|
8
|
+
pop_context
|
9
|
+
end
|
10
|
+
|
11
|
+
def push_context(context)
|
12
|
+
formatter.push_context(context)
|
13
|
+
end
|
14
|
+
|
15
|
+
def pop_context
|
16
|
+
formatter.pop_context
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module ContextFormatter
|
21
|
+
def context
|
22
|
+
Thread.current[current_context_key] ||= begin
|
23
|
+
result = {}
|
24
|
+
context_stack.each { |frame| result.merge!(frame) }
|
25
|
+
result
|
26
|
+
end.freeze
|
27
|
+
end
|
28
|
+
|
29
|
+
def push_context(frame)
|
30
|
+
clear_context
|
31
|
+
context_stack.push(frame)
|
32
|
+
end
|
33
|
+
|
34
|
+
def pop_context
|
35
|
+
clear_context
|
36
|
+
context_stack.pop
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def clear_context
|
42
|
+
Thread.current[current_context_key] = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def context_stack
|
46
|
+
Thread.current[stack_key] ||= []
|
47
|
+
end
|
48
|
+
|
49
|
+
def stack_key
|
50
|
+
@stack_key ||= "epilog_context_stack:#{object_id}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def current_context_key
|
54
|
+
@current_context_key ||= "epilog_context_current:#{object_id}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/epilog/log_formatter.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Epilog
|
4
4
|
class Formatter
|
5
|
+
include ContextFormatter
|
6
|
+
|
5
7
|
SEVERITY_MAP = {
|
6
8
|
'FATAL' => 'ALERT',
|
7
9
|
'WARN' => 'WARNING'
|
@@ -18,6 +20,7 @@ module Epilog
|
|
18
20
|
|
19
21
|
def call(severity, time, progname, msg)
|
20
22
|
log = base_log(severity, time, progname)
|
23
|
+
log.merge!(context)
|
21
24
|
log.merge!(message(msg))
|
22
25
|
|
23
26
|
if log[:exception].is_a?(Exception)
|
data/lib/epilog/logger.rb
CHANGED
data/lib/epilog/mock_logger.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Epilog
|
4
4
|
class MockLogger < ::Logger
|
5
|
-
def initialize
|
6
|
-
super(nil)
|
5
|
+
def initialize(**options)
|
6
|
+
super(nil, **options)
|
7
7
|
reset
|
8
8
|
end
|
9
9
|
|
@@ -44,6 +44,21 @@ module Epilog
|
|
44
44
|
|
45
45
|
def reset
|
46
46
|
@logs = []
|
47
|
+
@context = []
|
48
|
+
end
|
49
|
+
|
50
|
+
def with_context(context)
|
51
|
+
push_context(context)
|
52
|
+
yield
|
53
|
+
pop_context
|
54
|
+
end
|
55
|
+
|
56
|
+
def push_context(context)
|
57
|
+
@context << context
|
58
|
+
end
|
59
|
+
|
60
|
+
def pop_context
|
61
|
+
@context.pop
|
47
62
|
end
|
48
63
|
|
49
64
|
private
|
@@ -53,7 +68,7 @@ module Epilog
|
|
53
68
|
end
|
54
69
|
|
55
70
|
def write(severity, time, prog, message)
|
56
|
-
@logs << [severity, time, prog, message]
|
71
|
+
@logs << [severity, time, prog, message, @context.dup]
|
57
72
|
end
|
58
73
|
end
|
59
74
|
end
|
@@ -7,24 +7,31 @@ module Epilog
|
|
7
7
|
RAILS_PARAMS = %i[controller action format _method only_path].freeze
|
8
8
|
|
9
9
|
def request_received(event)
|
10
|
+
push_context(
|
11
|
+
{ request: short_request_hash(event) }
|
12
|
+
.merge(event.payload[:context])
|
13
|
+
)
|
14
|
+
|
10
15
|
info do
|
11
|
-
|
16
|
+
{
|
12
17
|
message: "#{request_string(event)} started",
|
13
18
|
request: request_hash(event)
|
14
|
-
|
19
|
+
}
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
23
|
def process_request(event)
|
19
24
|
info do
|
20
|
-
|
25
|
+
{
|
21
26
|
message: response_string(event),
|
22
27
|
request: short_request_hash(event),
|
23
28
|
response: response_hash(event),
|
24
29
|
metrics: process_metrics(event.payload[:metrics]
|
25
30
|
.merge(request_runtime: event.duration.round(2)))
|
26
|
-
|
31
|
+
}
|
27
32
|
end
|
33
|
+
|
34
|
+
pop_context
|
28
35
|
end
|
29
36
|
|
30
37
|
def start_processing(*)
|
@@ -12,6 +12,7 @@ module Epilog
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def perform_start(event)
|
15
|
+
push_context(job: short_job_hash(event.payload[:job]))
|
15
16
|
info { event_hash('Performing job', event) }
|
16
17
|
end
|
17
18
|
|
@@ -23,6 +24,7 @@ module Epilog
|
|
23
24
|
}
|
24
25
|
)
|
25
26
|
end
|
27
|
+
pop_context
|
26
28
|
end
|
27
29
|
|
28
30
|
private
|
@@ -45,6 +47,13 @@ module Epilog
|
|
45
47
|
}
|
46
48
|
end
|
47
49
|
|
50
|
+
def short_job_hash(job)
|
51
|
+
{
|
52
|
+
class: job.class.name,
|
53
|
+
id: job.job_id
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
48
57
|
def format_time(time)
|
49
58
|
Time.at(time).utc.strftime(Epilog::Formatter::DEFAULT_TIME_FORMAT)
|
50
59
|
end
|
data/lib/epilog/version.rb
CHANGED
data/lib/epilog.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epilog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -231,6 +231,7 @@ files:
|
|
231
231
|
- bin/yri
|
232
232
|
- epilog.gemspec
|
233
233
|
- lib/epilog.rb
|
234
|
+
- lib/epilog/context_logging.rb
|
234
235
|
- lib/epilog/filter.rb
|
235
236
|
- lib/epilog/filter/blacklist.rb
|
236
237
|
- lib/epilog/filter/filter_parameters.rb
|