rails_semantic_logger 4.9.0 → 4.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rails_semantic_logger/action_mailer/log_subscriber.rb +135 -0
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +2 -1
- data/lib/rails_semantic_logger/engine.rb +11 -3
- data/lib/rails_semantic_logger/extensions/rails/server.rb +2 -2
- data/lib/rails_semantic_logger/version.rb +1 -1
- data/lib/rails_semantic_logger.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6944c99a390bc385a4d5a83daea0fc340dbd4dd2913631ae3a812590ec1503e4
|
4
|
+
data.tar.gz: ebb36106bde192de58b716077fc4c1b5c51d474ee9e86e5a93ef4a77fc25d1be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e1cf6df574f6dd146029407d80d2a4b51e1bfb222dbf511dbc6b540070e8d7432cff0eaf4cf94227b2d5440eb21c2ebab7222db774dd9408ebda613ae0df3bf
|
7
|
+
data.tar.gz: 2da852f09a5417bc91e155f1bb80d9a1c50baa823cd39c46ee2ea7a9ecfa366f95b551c996a3a295d6074424224fd5aaf390c14c7f08b88effdcae31486d3bc4
|
data/README.md
CHANGED
@@ -21,7 +21,7 @@ SemanticLogger::Processor.instance.instance_variable_set(:@queue, Queue.new)
|
|
21
21
|
|
22
22
|
## Supports
|
23
23
|
|
24
|
-
For the complete list of supported Ruby and Rails versions, see the [Testing file](https://github.com/reidmorrison/rails_semantic_logger/blob/master/.
|
24
|
+
For the complete list of supported Ruby and Rails versions, see the [Testing file](https://github.com/reidmorrison/rails_semantic_logger/blob/master/.github/workflows/ci.yml).
|
25
25
|
|
26
26
|
## Author
|
27
27
|
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require "active_support/log_subscriber"
|
2
|
+
require "action_mailer"
|
3
|
+
|
4
|
+
module RailsSemanticLogger
|
5
|
+
module ActionMailer
|
6
|
+
class LogSubscriber < ::ActiveSupport::LogSubscriber
|
7
|
+
def deliver(event)
|
8
|
+
ex = event.payload[:exception_object]
|
9
|
+
message_id = event.payload[:message_id]
|
10
|
+
duration = event.duration.round(1)
|
11
|
+
if ex
|
12
|
+
log_with_formatter event: event, log_duration: true, level: :error do |fmt|
|
13
|
+
{
|
14
|
+
message: "Error delivering mail #{message_id} (#{duration}ms)",
|
15
|
+
exception: ex
|
16
|
+
}
|
17
|
+
end
|
18
|
+
else
|
19
|
+
message = begin
|
20
|
+
if event.payload[:perform_deliveries]
|
21
|
+
"Delivered mail #{message_id} (#{duration}ms)"
|
22
|
+
else
|
23
|
+
"Skipped delivery of mail #{message_id} as `perform_deliveries` is false"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
log_with_formatter event: event, log_duration: true do |fmt|
|
27
|
+
{ message: message }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# An email was generated.
|
33
|
+
def process(event)
|
34
|
+
mailer = event.payload[:mailer]
|
35
|
+
action = event.payload[:action]
|
36
|
+
duration = event.duration.round(1)
|
37
|
+
log_with_formatter event: event do |fmt|
|
38
|
+
{ message: "#{mailer}##{action}: processed outbound mail in #{duration}ms" }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
class EventFormatter
|
45
|
+
def initialize(event:, log_duration: false)
|
46
|
+
@event = event
|
47
|
+
@log_duration = log_duration
|
48
|
+
end
|
49
|
+
|
50
|
+
def mailer
|
51
|
+
event.payload[:mailer]
|
52
|
+
end
|
53
|
+
|
54
|
+
def payload
|
55
|
+
{}.tap do |h|
|
56
|
+
h[:event_name] = event.name
|
57
|
+
h[:mailer] = mailer
|
58
|
+
h[:action] = action
|
59
|
+
h[:message_id] = event.payload[:message_id]
|
60
|
+
h[:perform_deliveries] = event.payload[:perform_deliveries]
|
61
|
+
h[:subject] = event.payload[:subject]
|
62
|
+
h[:to] = event.payload[:to]
|
63
|
+
h[:from] = event.payload[:from]
|
64
|
+
h[:bcc] = event.payload[:bcc]
|
65
|
+
h[:cc] = event.payload[:cc]
|
66
|
+
h[:date] = date
|
67
|
+
h[:duration] = event.duration.round(2) if log_duration?
|
68
|
+
h[:args] = formatted_args
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def date
|
73
|
+
if event.payload[:date].respond_to?(:to_time)
|
74
|
+
event.payload[:date].to_time.utc
|
75
|
+
elsif event.payload[:date].is_a?(String)
|
76
|
+
Time.parse(date).utc
|
77
|
+
else
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
attr_reader :event
|
85
|
+
|
86
|
+
def mailer
|
87
|
+
event.payload[:mailer]
|
88
|
+
end
|
89
|
+
|
90
|
+
def action
|
91
|
+
event.payload[:action]
|
92
|
+
end
|
93
|
+
|
94
|
+
def formatted_args
|
95
|
+
if defined?(mailer.contantize.log_arguments?) && !mailer.contantize.log_arguments?
|
96
|
+
""
|
97
|
+
else
|
98
|
+
JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) }) if event.payload[:args].present?
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def format(arg)
|
103
|
+
case arg
|
104
|
+
when Hash
|
105
|
+
arg.transform_values { |value| format(value) }
|
106
|
+
when Array
|
107
|
+
arg.map { |value| format(value) }
|
108
|
+
when GlobalID::Identification
|
109
|
+
begin
|
110
|
+
arg.to_global_id
|
111
|
+
rescue StandardError
|
112
|
+
arg
|
113
|
+
end
|
114
|
+
else
|
115
|
+
arg
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def log_duration?
|
120
|
+
@log_duration
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def log_with_formatter(level: :info, **kw_args)
|
125
|
+
fmt = EventFormatter.new(**kw_args)
|
126
|
+
msg = yield fmt
|
127
|
+
logger.public_send(level, **msg, payload: fmt.payload)
|
128
|
+
end
|
129
|
+
|
130
|
+
def logger
|
131
|
+
::ActionMailer::Base.logger
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -198,7 +198,8 @@ module RailsSemanticLogger
|
|
198
198
|
alias bind_values bind_values_v5_0_3
|
199
199
|
alias render_bind render_bind_v5_0_3
|
200
200
|
alias type_casted_binds type_casted_binds_v5_0_3
|
201
|
-
elsif Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR > 0 # ~> 6.1.0
|
201
|
+
elsif (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR > 0) || # ~> 6.1.0
|
202
|
+
Rails::VERSION::MAJOR == 7
|
202
203
|
alias bind_values bind_values_v6_1
|
203
204
|
alias render_bind render_bind_v6_1
|
204
205
|
alias type_casted_binds type_casted_binds_v5_1_5
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "rails"
|
2
2
|
require "action_controller/log_subscriber"
|
3
3
|
require "action_view/log_subscriber"
|
4
|
+
require "action_mailer/log_subscriber"
|
4
5
|
require "rails_semantic_logger/options"
|
5
6
|
|
6
7
|
module RailsSemanticLogger
|
@@ -107,13 +108,13 @@ module RailsSemanticLogger
|
|
107
108
|
Mongo::Logger.logger = SemanticLogger[Mongo] if defined?(Mongo::Logger)
|
108
109
|
|
109
110
|
# Replace the Resque Logger
|
110
|
-
Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger)
|
111
|
+
Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger=)
|
111
112
|
|
112
113
|
# Replace the Sidekiq logger
|
113
|
-
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
|
114
|
+
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq) && Sidekiq.respond_to?(:logger=)
|
114
115
|
|
115
116
|
# Replace the Sidetiq logger
|
116
|
-
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq)
|
117
|
+
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq) && Sidetiq.respond_to?(:logger=)
|
117
118
|
|
118
119
|
# Replace the DelayedJob logger
|
119
120
|
if defined?(Delayed::Worker)
|
@@ -198,6 +199,13 @@ module RailsSemanticLogger
|
|
198
199
|
RailsSemanticLogger::ActionController::LogSubscriber,
|
199
200
|
:action_controller
|
200
201
|
)
|
202
|
+
|
203
|
+
# Action Mailer
|
204
|
+
RailsSemanticLogger.swap_subscriber(
|
205
|
+
::ActionMailer::LogSubscriber,
|
206
|
+
RailsSemanticLogger::ActionMailer::LogSubscriber,
|
207
|
+
:action_mailer
|
208
|
+
)
|
201
209
|
end
|
202
210
|
|
203
211
|
#
|
@@ -5,11 +5,11 @@ module Rails
|
|
5
5
|
class Server
|
6
6
|
private
|
7
7
|
|
8
|
-
undef_method :log_to_stdout
|
8
|
+
undef_method :log_to_stdout if method_defined?(:log_to_stdout)
|
9
9
|
def log_to_stdout
|
10
10
|
wrapped_app # touch the app so the logger is set up
|
11
11
|
|
12
|
-
SemanticLogger.add_appender(io: $stdout, formatter: :color)
|
12
|
+
SemanticLogger.add_appender(io: $stdout, formatter: :color) unless SemanticLogger.appenders.console_output?
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -6,6 +6,9 @@ module RailsSemanticLogger
|
|
6
6
|
module ActionController
|
7
7
|
autoload :LogSubscriber, "rails_semantic_logger/action_controller/log_subscriber"
|
8
8
|
end
|
9
|
+
module ActionMailer
|
10
|
+
autoload :LogSubscriber, "rails_semantic_logger/action_mailer/log_subscriber"
|
11
|
+
end
|
9
12
|
module ActionView
|
10
13
|
autoload :LogSubscriber, "rails_semantic_logger/action_view/log_subscriber"
|
11
14
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- Rakefile
|
64
64
|
- lib/rails_semantic_logger.rb
|
65
65
|
- lib/rails_semantic_logger/action_controller/log_subscriber.rb
|
66
|
+
- lib/rails_semantic_logger/action_mailer/log_subscriber.rb
|
66
67
|
- lib/rails_semantic_logger/action_view/log_subscriber.rb
|
67
68
|
- lib/rails_semantic_logger/active_job/log_subscriber.rb
|
68
69
|
- lib/rails_semantic_logger/active_record/log_subscriber.rb
|
@@ -101,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
102
|
- !ruby/object:Gem::Version
|
102
103
|
version: '0'
|
103
104
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
105
|
+
rubygems_version: 3.1.6
|
105
106
|
signing_key:
|
106
107
|
specification_version: 4
|
107
108
|
summary: Feature rich logging framework that replaces the Rails logger.
|