rails_semantic_logger 4.17.0 → 4.18.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/lib/rails_semantic_logger/action_controller/log_subscriber.rb +14 -2
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +19 -4
- data/lib/rails_semantic_logger/engine.rb +7 -0
- data/lib/rails_semantic_logger/extensions/action_dispatch/debug_exceptions.rb +7 -3
- data/lib/rails_semantic_logger/options.rb +25 -16
- data/lib/rails_semantic_logger/rack/logger.rb +12 -4
- data/lib/rails_semantic_logger/sidekiq/defaults.rb +2 -2
- data/lib/rails_semantic_logger/version.rb +1 -1
- data/lib/rails_semantic_logger.rb +10 -2
- metadata +4 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db5e6b03ccd16cbe212ef23f0fad1e7f14138f8b2e22e7572613aa3e52d5b66d
|
4
|
+
data.tar.gz: d46ee20a271e77d51f551926629257d221db96301facefe7be9a641d9ddffc77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f07be5e786b9f93669b278027cf2ba578132dc90ec3e6aa575c0df7b85fdd851d9d54965172a59bf7e9b40ad002d4fd0bd1a677ee8c3b77de129010c2b93b781
|
7
|
+
data.tar.gz: ebcc3799d581accf18af62739310ed25d183346c72a5006fa32a5a82f828a7371a9607df9646664574fd164be524ab76fa0c23f3845632285d76457134ed90f7
|
@@ -3,9 +3,13 @@ module RailsSemanticLogger
|
|
3
3
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
4
4
|
INTERNAL_PARAMS = %w[controller action format _method only_path].freeze
|
5
5
|
|
6
|
+
class << self
|
7
|
+
attr_accessor :action_message_format
|
8
|
+
end
|
9
|
+
|
6
10
|
# Log as debug to hide Processing messages in production
|
7
11
|
def start_processing(event)
|
8
|
-
controller_logger(event).debug { "Processing
|
12
|
+
controller_logger(event).debug { action_message("Processing", event.payload) }
|
9
13
|
end
|
10
14
|
|
11
15
|
def process_action(event)
|
@@ -59,7 +63,7 @@ module RailsSemanticLogger
|
|
59
63
|
payload.delete(:response)
|
60
64
|
|
61
65
|
{
|
62
|
-
message: "Completed
|
66
|
+
message: action_message("Completed", event.payload),
|
63
67
|
duration: event.duration,
|
64
68
|
payload: payload
|
65
69
|
}
|
@@ -122,6 +126,14 @@ module RailsSemanticLogger
|
|
122
126
|
index = path.index("?")
|
123
127
|
index ? path[0, index] : path
|
124
128
|
end
|
129
|
+
|
130
|
+
def action_message(message, payload)
|
131
|
+
if self.class.action_message_format
|
132
|
+
self.class.action_message_format.call(message, payload)
|
133
|
+
else
|
134
|
+
"#{message} ##{payload[:action]}"
|
135
|
+
end
|
136
|
+
end
|
125
137
|
end
|
126
138
|
end
|
127
139
|
end
|
@@ -33,6 +33,7 @@ module RailsSemanticLogger
|
|
33
33
|
log_payload[:binds] = bind_values(payload) unless (payload[:binds] || []).empty?
|
34
34
|
log_payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
35
35
|
log_payload[:cached] = event.payload[:cached]
|
36
|
+
log_payload[:async] = true if event.payload[:async]
|
36
37
|
|
37
38
|
log = {
|
38
39
|
message: name,
|
@@ -54,11 +55,25 @@ module RailsSemanticLogger
|
|
54
55
|
|
55
56
|
# When multiple values are received for a single bound field, it is converted into an array
|
56
57
|
def add_bind_value(binds, key, value)
|
57
|
-
key
|
58
|
-
|
58
|
+
key = key.downcase.to_sym unless key.nil?
|
59
|
+
|
60
|
+
if rails_filter_params_include?(key)
|
61
|
+
value = "[FILTERED]"
|
62
|
+
elsif binds.key?(key)
|
63
|
+
value = (Array(binds[key]) << value)
|
64
|
+
end
|
65
|
+
|
59
66
|
binds[key] = value
|
60
67
|
end
|
61
68
|
|
69
|
+
def rails_filter_params_include?(key)
|
70
|
+
filter_parameters = Rails.configuration.filter_parameters
|
71
|
+
|
72
|
+
return filter_parameters.first.match? key if filter_parameters.first.is_a? Regexp
|
73
|
+
|
74
|
+
filter_parameters.include? key
|
75
|
+
end
|
76
|
+
|
62
77
|
def logger
|
63
78
|
self.class.logger
|
64
79
|
end
|
@@ -196,8 +211,8 @@ module RailsSemanticLogger
|
|
196
211
|
alias bind_values bind_values_v5_0_3
|
197
212
|
alias render_bind render_bind_v5_0_3
|
198
213
|
alias type_casted_binds type_casted_binds_v5_0_3
|
199
|
-
elsif (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR > 0) ||
|
200
|
-
Rails::VERSION::MAJOR
|
214
|
+
elsif (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR > 0) ||
|
215
|
+
Rails::VERSION::MAJOR >= 7 # ~> 6.1.0 && >= 7.x.x
|
201
216
|
alias bind_values bind_values_v6_1
|
202
217
|
alias render_bind render_bind_v6_1
|
203
218
|
alias type_casted_binds type_casted_binds_v5_1_5
|
@@ -226,6 +226,7 @@ module RailsSemanticLogger
|
|
226
226
|
if defined?(::ActionController)
|
227
227
|
require "action_controller/log_subscriber"
|
228
228
|
|
229
|
+
RailsSemanticLogger::ActionController::LogSubscriber.action_message_format = config.rails_semantic_logger.action_message_format
|
229
230
|
RailsSemanticLogger.swap_subscriber(
|
230
231
|
::ActionController::LogSubscriber,
|
231
232
|
RailsSemanticLogger::ActionController::LogSubscriber,
|
@@ -265,6 +266,12 @@ module RailsSemanticLogger
|
|
265
266
|
# Re-open appenders after Spring has forked a process
|
266
267
|
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
267
268
|
|
269
|
+
# Re-open appenders after SolidQueue worker/dispatcher/scheduler has finished booting
|
270
|
+
SolidQueue.on_start { ::SemanticLogger.reopen } if defined?(SolidQueue.on_start)
|
271
|
+
SolidQueue.on_worker_start { ::SemanticLogger.reopen } if defined?(SolidQueue.on_worker_start)
|
272
|
+
SolidQueue.on_dispatcher_start { ::SemanticLogger.reopen } if defined?(SolidQueue.on_dispatcher_start)
|
273
|
+
SolidQueue.on_scheduler_start { ::SemanticLogger.reopen } if defined?(SolidQueue.on_scheduler_start)
|
274
|
+
|
268
275
|
console do |_app|
|
269
276
|
# Don't use a background thread for logging
|
270
277
|
SemanticLogger.sync!
|
@@ -7,15 +7,19 @@ module ActionDispatch
|
|
7
7
|
|
8
8
|
undef_method :log_error
|
9
9
|
if (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
|
10
|
-
def log_error(
|
10
|
+
def log_error(request, wrapper)
|
11
11
|
Rails.application.deprecators.silence do
|
12
|
-
|
12
|
+
return if !log_rescued_responses?(request) && wrapper.rescue_response?
|
13
|
+
|
14
|
+
level = request.get_header("action_dispatch.debug_exception_log_level")
|
15
|
+
ActionController::Base.logger.log(level, wrapper.exception)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
else
|
16
19
|
def log_error(_request, wrapper)
|
17
20
|
ActiveSupport::Deprecation.silence do
|
18
|
-
|
21
|
+
level = wrapper.respond_to?(:rescue_response?) && wrapper.rescue_response? ? :debug : :fatal
|
22
|
+
ActionController::Base.logger.log(level, wrapper.exception)
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -22,14 +22,14 @@ module RailsSemanticLogger
|
|
22
22
|
#
|
23
23
|
# config.rails_semantic_logger.rendered = false
|
24
24
|
#
|
25
|
-
# * Override the
|
25
|
+
# * Override the Amazing Print options for logging Hash data as text:
|
26
26
|
#
|
27
|
-
# Any valid
|
27
|
+
# Any valid Amazing Print option for rendering data.
|
28
28
|
# The defaults can changed be creating a `~/.aprc` file.
|
29
|
-
# See: https://github.com/
|
29
|
+
# See: https://github.com/amazing-print/amazing_print
|
30
30
|
#
|
31
31
|
# Note: The option :multiline is set to false if not supplied.
|
32
|
-
# Note: Has no effect if
|
32
|
+
# Note: Has no effect if Amazing Print is not installed.
|
33
33
|
#
|
34
34
|
# config.rails_semantic_logger.ap_options = {multiline: false}
|
35
35
|
#
|
@@ -100,23 +100,32 @@ module RailsSemanticLogger
|
|
100
100
|
# * named_tags: *DEPRECATED*
|
101
101
|
# Instead, supply a Hash to config.log_tags
|
102
102
|
# config.rails_semantic_logger.named_tags = nil
|
103
|
+
#
|
104
|
+
# * Change the message format of Action Controller action.
|
105
|
+
# A block that will be called to format the message.
|
106
|
+
# It is supplied with the `message` and `payload` and should return the formatted data.
|
107
|
+
#
|
108
|
+
# config.rails_semantic_logger.action_message_format = -> (message, payload) do
|
109
|
+
# "#{message} - #{payload[:controller]}##{payload[:action]}"
|
110
|
+
# end
|
103
111
|
class Options
|
104
112
|
attr_accessor :semantic, :started, :processing, :rendered, :ap_options, :add_file_appender,
|
105
|
-
:quiet_assets, :format, :named_tags, :filter, :console_logger
|
113
|
+
:quiet_assets, :format, :named_tags, :filter, :console_logger, :action_message_format
|
106
114
|
|
107
115
|
# Setup default values
|
108
116
|
def initialize
|
109
|
-
@semantic
|
110
|
-
@started
|
111
|
-
@processing
|
112
|
-
@rendered
|
113
|
-
@ap_options
|
114
|
-
@add_file_appender
|
115
|
-
@quiet_assets
|
116
|
-
@format
|
117
|
-
@named_tags
|
118
|
-
@filter
|
119
|
-
@console_logger
|
117
|
+
@semantic = true
|
118
|
+
@started = false
|
119
|
+
@processing = false
|
120
|
+
@rendered = false
|
121
|
+
@ap_options = {multiline: false}
|
122
|
+
@add_file_appender = true
|
123
|
+
@quiet_assets = false
|
124
|
+
@format = :default
|
125
|
+
@named_tags = nil
|
126
|
+
@filter = nil
|
127
|
+
@console_logger = true
|
128
|
+
@action_message_format = nil
|
120
129
|
end
|
121
130
|
end
|
122
131
|
end
|
@@ -36,10 +36,18 @@ module RailsSemanticLogger
|
|
36
36
|
|
37
37
|
def call_app(request, env)
|
38
38
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
if (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) || Rails::VERSION::MAJOR > 7
|
40
|
+
handle = instrumenter.build_handle "request.action_dispatch", request: request
|
41
|
+
instrumenter_finish = lambda {
|
42
|
+
handle.finish
|
43
|
+
}
|
44
|
+
handle.start
|
45
|
+
else
|
46
|
+
instrumenter_state = instrumenter.start "request.action_dispatch", request: request
|
47
|
+
instrumenter_finish = lambda {
|
48
|
+
instrumenter.finish_with_state(instrumenter_state, "request.action_dispatch", request: request)
|
49
|
+
}
|
50
|
+
end
|
43
51
|
|
44
52
|
logger.send(self.class.started_request_log_level) { started_request_message(request) }
|
45
53
|
status, headers, body = @app.call(env)
|
@@ -9,7 +9,7 @@ module RailsSemanticLogger
|
|
9
9
|
unless ctx.empty?
|
10
10
|
job_hash = ctx[:job] || {}
|
11
11
|
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
|
12
|
-
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
12
|
+
logger = klass ? SemanticLogger[klass] : ::Sidekiq.logger
|
13
13
|
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
|
14
14
|
end
|
15
15
|
end
|
@@ -18,7 +18,7 @@ module RailsSemanticLogger
|
|
18
18
|
unless ctx.empty?
|
19
19
|
job_hash = ctx[:job] || {}
|
20
20
|
klass = job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"]
|
21
|
-
logger = klass ? SemanticLogger[klass] : Sidekiq.logger
|
21
|
+
logger = klass ? SemanticLogger[klass] : ::Sidekiq.logger
|
22
22
|
ctx[:context] ? logger.warn(ctx[:context], ctx) : logger.warn(ctx)
|
23
23
|
end
|
24
24
|
end
|
@@ -49,7 +49,7 @@ module RailsSemanticLogger
|
|
49
49
|
|
50
50
|
def self.unattach(subscriber)
|
51
51
|
subscriber_patterns(subscriber).each do |pattern|
|
52
|
-
ActiveSupport::Notifications.notifier
|
52
|
+
listeners_for(ActiveSupport::Notifications.notifier, pattern).each do |sub|
|
53
53
|
next unless sub.instance_variable_get(:@delegate) == subscriber
|
54
54
|
|
55
55
|
ActiveSupport::Notifications.unsubscribe(sub)
|
@@ -67,7 +67,15 @@ module RailsSemanticLogger
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
|
70
|
+
def self.listeners_for(notifier, pattern)
|
71
|
+
if notifier.respond_to?(:all_listeners_for) # Rails >= 7.1
|
72
|
+
notifier.all_listeners_for(pattern)
|
73
|
+
else
|
74
|
+
notifier.listeners_for(pattern)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private_class_method :listeners_for, :subscriber_patterns, :unattach
|
71
79
|
end
|
72
80
|
|
73
81
|
require("rails_semantic_logger/extensions/mongoid/config") if defined?(Mongoid)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
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.18.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rack
|
@@ -52,8 +51,6 @@ dependencies:
|
|
52
51
|
- - "~>"
|
53
52
|
- !ruby/object:Gem::Version
|
54
53
|
version: '4.16'
|
55
|
-
description:
|
56
|
-
email:
|
57
54
|
executables: []
|
58
55
|
extensions: []
|
59
56
|
extra_rdoc_files: []
|
@@ -95,9 +92,8 @@ licenses:
|
|
95
92
|
metadata:
|
96
93
|
bug_tracker_uri: https://github.com/reidmorrison/rails_semantic_logger/issues
|
97
94
|
documentation_uri: https://logger.rocketjob.io
|
98
|
-
source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.
|
95
|
+
source_code_uri: https://github.com/reidmorrison/rails_semantic_logger/tree/v4.18.0
|
99
96
|
rubygems_mfa_required: 'true'
|
100
|
-
post_install_message:
|
101
97
|
rdoc_options: []
|
102
98
|
require_paths:
|
103
99
|
- lib
|
@@ -112,8 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
108
|
- !ruby/object:Gem::Version
|
113
109
|
version: '0'
|
114
110
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
111
|
+
rubygems_version: 3.6.9
|
117
112
|
specification_version: 4
|
118
113
|
summary: Feature rich logging framework that replaces the Rails logger.
|
119
114
|
test_files: []
|