rails_semantic_logger 4.4.6 → 4.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/rails_semantic_logger.rb +4 -0
- data/lib/rails_semantic_logger/action_controller/log_subscriber.rb +5 -2
- data/lib/rails_semantic_logger/action_view/log_subscriber.rb +5 -2
- data/lib/rails_semantic_logger/active_job/log_subscriber.rb +17 -8
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +33 -2
- data/lib/rails_semantic_logger/engine.rb +19 -7
- data/lib/rails_semantic_logger/extensions/action_controller/live.rb +1 -0
- data/lib/rails_semantic_logger/extensions/action_dispatch/debug_exceptions.rb +1 -0
- data/lib/rails_semantic_logger/extensions/action_view/streaming_template_renderer.rb +1 -0
- data/lib/rails_semantic_logger/extensions/active_support/logger.rb +24 -0
- data/lib/rails_semantic_logger/extensions/active_support/tagged_logging.rb +8 -0
- data/lib/rails_semantic_logger/extensions/mongoid/config.rb +11 -0
- data/lib/rails_semantic_logger/extensions/rack/server.rb +12 -0
- data/lib/rails_semantic_logger/extensions/rails/server.rb +2 -0
- data/lib/rails_semantic_logger/rack/logger.rb +1 -1
- data/lib/rails_semantic_logger/version.rb +1 -1
- metadata +11 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0816ddc6820dfc94fed6b737d023c2cfdc6e6df3019d34ff1e71c40a2a6ccb2f'
|
4
|
+
data.tar.gz: b0c7f329c6e1ecf72687617155d994b6c37ef731d5166e30b76543a41e825efb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42fadbc4b768c9f64f719e36cdf453bc80b88639fd8fe169704ae5b37375be8706b59d3ede6ef8a6eac090a0433be1fe514e90ea306f2f1288f026042e48b18
|
7
|
+
data.tar.gz: f16dec6c5a4336c0d0a0a2862891ec2117cbf103257a759e8611376725167476bc090c2444a7011df7b4c4e323583f2d5392dd498dea72e03f23f3555c45bde8
|
data/README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# Rails Semantic Logger
|
2
|
-
[![Gem Version](https://img.shields.io/gem/v/rails_semantic_logger.svg)](https://rubygems.org/gems/rails_semantic_logger) [![Build Status](https://
|
2
|
+
[![Gem Version](https://img.shields.io/gem/v/rails_semantic_logger.svg)](https://rubygems.org/gems/rails_semantic_logger) [![Build Status](https://github.com/reidmorrison/rails_semantic_logger/workflows/build/badge.svg)](https://github.com/reidmorrison/rails_semantic_logger/actions?query=workflow%3Abuild) [![Downloads](https://img.shields.io/gem/dt/rails_semantic_logger.svg)](https://rubygems.org/gems/rails_semantic_logger) [![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](http://opensource.org/licenses/Apache-2.0) ![](https://img.shields.io/badge/status-Production%20Ready-blue.svg)
|
3
3
|
|
4
|
-
Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](
|
4
|
+
Rails Semantic Logger replaces the Rails default logger with [Semantic Logger](https://logger.rocketjob.io/)
|
5
5
|
|
6
|
-
* http://github.com/
|
6
|
+
* http://github.com/reidmorrison/rails_semantic_logger
|
7
7
|
|
8
8
|
## Documentation
|
9
9
|
|
10
|
-
For complete documentation see:
|
10
|
+
For complete documentation see: https://logger.rocketjob.io/rails
|
11
11
|
|
12
12
|
## Upgrading to Semantic Logger v4.4
|
13
13
|
|
@@ -21,13 +21,13 @@ 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/
|
24
|
+
For the complete list of supported Ruby and Rails versions, see the [Testing file](https://github.com/reidmorrison/rails_semantic_logger/blob/master/.travis.yml).
|
25
25
|
|
26
26
|
## Author
|
27
27
|
|
28
28
|
[Reid Morrison](https://github.com/reidmorrison)
|
29
29
|
|
30
|
-
[Contributors](https://github.com/
|
30
|
+
[Contributors](https://github.com/reidmorrison/rails_semantic_logger/graphs/contributors)
|
31
31
|
|
32
32
|
## Versioning
|
33
33
|
|
@@ -52,3 +52,7 @@ module RailsSemanticLogger
|
|
52
52
|
|
53
53
|
private_class_method :subscriber_patterns, :unattach
|
54
54
|
end
|
55
|
+
|
56
|
+
require("rails_semantic_logger/extensions/mongoid/config") if defined?(Mongoid)
|
57
|
+
require("rails_semantic_logger/extensions/active_support/logger") if defined?(ActiveSupport::Logger)
|
58
|
+
require("rails_semantic_logger/extensions/rack/server") if defined?(Rack::Server)
|
@@ -15,10 +15,10 @@ module RailsSemanticLogger
|
|
15
15
|
# Unused, but needed for Devise 401 status code monkey patch to still work.
|
16
16
|
::ActionController::Base.log_process_action(payload)
|
17
17
|
|
18
|
-
# According to PR https://github.com/
|
18
|
+
# According to PR https://github.com/reidmorrison/rails_semantic_logger/pull/37/files
|
19
19
|
# payload[:params] is not always a Hash.
|
20
20
|
payload[:params] = payload[:params].to_unsafe_h unless payload[:params].is_a?(Hash)
|
21
|
-
payload[:params].except
|
21
|
+
payload[:params] = payload[:params].except(*INTERNAL_PARAMS)
|
22
22
|
payload.delete(:params) if payload[:params].empty?
|
23
23
|
|
24
24
|
format = payload[:format]
|
@@ -37,6 +37,9 @@ module RailsSemanticLogger
|
|
37
37
|
payload[key] = payload[key].to_f.round(2) if key.to_s =~ /(.*)_runtime/
|
38
38
|
end
|
39
39
|
|
40
|
+
# Rails 6+ includes allocation count
|
41
|
+
payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
42
|
+
|
40
43
|
payload[:status_message] = ::Rack::Utils::HTTP_STATUS_CODES[payload[:status]] if payload[:status].present?
|
41
44
|
|
42
45
|
# Causes excessive log output with Rails 5 RC1
|
@@ -23,6 +23,7 @@ module RailsSemanticLogger
|
|
23
23
|
template: from_rails_root(event.payload[:identifier])
|
24
24
|
}
|
25
25
|
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
|
26
|
+
payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
26
27
|
|
27
28
|
logger.measure(
|
28
29
|
self.class.rendered_log_level,
|
@@ -39,7 +40,8 @@ module RailsSemanticLogger
|
|
39
40
|
partial: from_rails_root(event.payload[:identifier])
|
40
41
|
}
|
41
42
|
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
|
42
|
-
payload[:cache] = payload[:cache_hit] unless event.payload[:cache_hit].nil?
|
43
|
+
payload[:cache] = event.payload[:cache_hit] unless event.payload[:cache_hit].nil?
|
44
|
+
payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
43
45
|
|
44
46
|
logger.measure(
|
45
47
|
self.class.rendered_log_level,
|
@@ -58,7 +60,8 @@ module RailsSemanticLogger
|
|
58
60
|
template: from_rails_root(identifier),
|
59
61
|
count: event.payload[:count]
|
60
62
|
}
|
61
|
-
payload[:cache_hits] = payload[:cache_hits] if payload[:cache_hits]
|
63
|
+
payload[:cache_hits] = event.payload[:cache_hits] if event.payload[:cache_hits]
|
64
|
+
payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
62
65
|
|
63
66
|
logger.measure(
|
64
67
|
self.class.rendered_log_level,
|
@@ -5,29 +5,34 @@ module RailsSemanticLogger
|
|
5
5
|
class LogSubscriber < ::ActiveSupport::LogSubscriber
|
6
6
|
def enqueue(event)
|
7
7
|
log_with_formatter event: event do |fmt|
|
8
|
-
"Enqueued #{fmt.job_info}"
|
8
|
+
{message: "Enqueued #{fmt.job_info}"}
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
12
|
def enqueue_at(event)
|
13
13
|
log_with_formatter event: event do |fmt|
|
14
|
-
"Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"
|
14
|
+
{message: "Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"}
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def perform_start(event)
|
19
19
|
log_with_formatter event: event do |fmt|
|
20
|
-
"Performing #{fmt.job_info}"
|
20
|
+
{message: "Performing #{fmt.job_info}"}
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
def perform(event)
|
25
25
|
ex = event.payload[:exception_object]
|
26
26
|
if ex
|
27
|
-
|
27
|
+
log_with_formatter event: event, log_duration: true, level: :error do |fmt|
|
28
|
+
{
|
29
|
+
message: "Error performing #{fmt.job_info} in #{event.duration.round(2)}ms",
|
30
|
+
exception: ex
|
31
|
+
}
|
32
|
+
end
|
28
33
|
else
|
29
34
|
log_with_formatter event: event, log_duration: true do |fmt|
|
30
|
-
"Performed #{fmt.job_info} in #{event.duration.round(2)}ms"
|
35
|
+
{message: "Performed #{fmt.job_info} in #{event.duration.round(2)}ms"}
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
@@ -78,7 +83,11 @@ module RailsSemanticLogger
|
|
78
83
|
end
|
79
84
|
|
80
85
|
def formatted_args
|
81
|
-
|
86
|
+
if defined?(job.class.log_arguments?) && !job.class.log_arguments?
|
87
|
+
""
|
88
|
+
else
|
89
|
+
JSON.pretty_generate(job.arguments.map { |arg| format(arg) })
|
90
|
+
end
|
82
91
|
end
|
83
92
|
|
84
93
|
def format(arg)
|
@@ -103,10 +112,10 @@ module RailsSemanticLogger
|
|
103
112
|
end
|
104
113
|
end
|
105
114
|
|
106
|
-
def log_with_formatter(**kw_args)
|
115
|
+
def log_with_formatter(level: :info, **kw_args)
|
107
116
|
fmt = EventFormatter.new(**kw_args)
|
108
117
|
msg = yield fmt
|
109
|
-
logger.
|
118
|
+
logger.public_send(level, **msg, payload: fmt.payload)
|
110
119
|
end
|
111
120
|
|
112
121
|
def logger
|
@@ -31,6 +31,8 @@ module RailsSemanticLogger
|
|
31
31
|
|
32
32
|
log_payload = {sql: payload[:sql]}
|
33
33
|
log_payload[:binds] = bind_values(payload) unless (payload[:binds] || []).empty?
|
34
|
+
log_payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
35
|
+
log_payload[:cached] = event.payload[:cached]
|
34
36
|
|
35
37
|
log = {
|
36
38
|
message: name,
|
@@ -40,7 +42,7 @@ module RailsSemanticLogger
|
|
40
42
|
|
41
43
|
# Log the location of the query itself.
|
42
44
|
if logger.send(:level_index) >= SemanticLogger.backtrace_level_index
|
43
|
-
log[:backtrace] = SemanticLogger::Utils.strip_backtrace
|
45
|
+
log[:backtrace] = SemanticLogger::Utils.strip_backtrace(caller)
|
44
46
|
end
|
45
47
|
|
46
48
|
logger.debug(log)
|
@@ -52,7 +54,7 @@ module RailsSemanticLogger
|
|
52
54
|
|
53
55
|
# When multiple values are received for a single bound field, it is converted into an array
|
54
56
|
def add_bind_value(binds, key, value)
|
55
|
-
key = key.downcase.to_sym
|
57
|
+
key = key.downcase.to_sym unless key.nil?
|
56
58
|
value = (Array(binds[key]) << value) if binds.key?(key)
|
57
59
|
binds[key] = value
|
58
60
|
end
|
@@ -115,6 +117,16 @@ module RailsSemanticLogger
|
|
115
117
|
binds
|
116
118
|
end
|
117
119
|
|
120
|
+
def bind_values_v6_1(payload)
|
121
|
+
binds = {}
|
122
|
+
casted_params = type_casted_binds(payload[:type_casted_binds])
|
123
|
+
payload[:binds].each_with_index do |attr, i|
|
124
|
+
attr_name, value = render_bind(attr, casted_params[i])
|
125
|
+
add_bind_value(binds, attr_name, value)
|
126
|
+
end
|
127
|
+
binds
|
128
|
+
end
|
129
|
+
|
118
130
|
def render_bind_v4_2(column, value)
|
119
131
|
if column
|
120
132
|
if column.binary?
|
@@ -154,6 +166,21 @@ module RailsSemanticLogger
|
|
154
166
|
[attr&.name, value]
|
155
167
|
end
|
156
168
|
|
169
|
+
def render_bind_v6_1(attr, value)
|
170
|
+
case attr
|
171
|
+
when ActiveModel::Attribute
|
172
|
+
if attr.type.binary? && attr.value
|
173
|
+
value = "<#{attr.value_for_database.to_s.bytesize} bytes of binary data>"
|
174
|
+
end
|
175
|
+
when Array
|
176
|
+
attr = attr.first
|
177
|
+
else
|
178
|
+
attr = nil
|
179
|
+
end
|
180
|
+
|
181
|
+
[attr&.name || :nil, value]
|
182
|
+
end
|
183
|
+
|
157
184
|
def type_casted_binds_v5_0_3(binds, casted_binds)
|
158
185
|
casted_binds || ::ActiveRecord::Base.connection.type_casted_binds(binds)
|
159
186
|
end
|
@@ -171,6 +198,10 @@ module RailsSemanticLogger
|
|
171
198
|
alias bind_values bind_values_v5_0_3
|
172
199
|
alias render_bind render_bind_v5_0_3
|
173
200
|
alias type_casted_binds type_casted_binds_v5_0_3
|
201
|
+
elsif Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR > 0 # ~> 6.1.0
|
202
|
+
alias bind_values bind_values_v6_1
|
203
|
+
alias render_bind render_bind_v6_1
|
204
|
+
alias type_casted_binds type_casted_binds_v5_1_5
|
174
205
|
elsif Rails::VERSION::MAJOR >= 5 # ~> 5.1.5 && ~> 5.0.7 && 6.x.x
|
175
206
|
alias bind_values bind_values_v5_1_5
|
176
207
|
alias render_bind render_bind_v5_0_3
|
@@ -127,18 +127,20 @@ module RailsSemanticLogger
|
|
127
127
|
|
128
128
|
# After any initializers run, but after the gems have been loaded
|
129
129
|
config.after_initialize do
|
130
|
+
config = Rails.application.config
|
131
|
+
|
130
132
|
# Replace the Bugsnag logger
|
131
|
-
Bugsnag.configure { |
|
133
|
+
Bugsnag.configure { |bugsnag_config| bugsnag_config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
132
134
|
|
133
135
|
# Rails Patches
|
134
|
-
require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(ActionCable)
|
135
|
-
require("rails_semantic_logger/extensions/action_controller/live") if defined?(ActionController::Live)
|
136
|
-
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(ActionDispatch::DebugExceptions)
|
137
|
-
if defined?(ActionView::StreamingTemplateRenderer::Body)
|
136
|
+
require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(::ActionCable)
|
137
|
+
require("rails_semantic_logger/extensions/action_controller/live") if defined?(::ActionController::Live)
|
138
|
+
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(::ActionDispatch::DebugExceptions)
|
139
|
+
if defined?(::ActionView::StreamingTemplateRenderer::Body)
|
138
140
|
require("rails_semantic_logger/extensions/action_view/streaming_template_renderer")
|
139
141
|
end
|
140
142
|
require("rails_semantic_logger/extensions/active_job/logging") if defined?(::ActiveJob)
|
141
|
-
require("rails_semantic_logger/extensions/active_model_serializers/logging") if defined?(ActiveModelSerializers)
|
143
|
+
require("rails_semantic_logger/extensions/active_model_serializers/logging") if defined?(::ActiveModelSerializers)
|
142
144
|
|
143
145
|
if config.rails_semantic_logger.semantic
|
144
146
|
# Active Job
|
@@ -174,7 +176,8 @@ module RailsSemanticLogger
|
|
174
176
|
|
175
177
|
# Silence asset logging by applying a filter to the Rails logger itself, not any of the appenders.
|
176
178
|
if config.rails_semantic_logger.quiet_assets && config.assets.prefix
|
177
|
-
|
179
|
+
assets_root = config.relative_url_root.to_s + config.assets.prefix
|
180
|
+
assets_regex = %r(\A/{0,2}#{assets_root})
|
178
181
|
RailsSemanticLogger::Rack::Logger.logger.filter = ->(log) { log.payload[:path] !~ assets_regex if log.payload }
|
179
182
|
end
|
180
183
|
|
@@ -211,6 +214,15 @@ module RailsSemanticLogger
|
|
211
214
|
|
212
215
|
# Re-open appenders after Spring has forked a process
|
213
216
|
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
217
|
+
|
218
|
+
console do |_app|
|
219
|
+
# Don't use a background thread for logging
|
220
|
+
SemanticLogger.sync!
|
221
|
+
SemanticLogger.add_appender(io: STDERR, formatter: :color)
|
222
|
+
|
223
|
+
# Include method names on log entries in the console
|
224
|
+
SemanticLogger.backtrace_level = SemanticLogger.default_level
|
225
|
+
end
|
214
226
|
end
|
215
227
|
end
|
216
228
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "active_support/logger"
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# More hacks to try and stop Rails from being it's own worst enemy.
|
5
|
+
class Logger
|
6
|
+
class << self
|
7
|
+
undef :logger_outputs_to?, :broadcast
|
8
|
+
end
|
9
|
+
|
10
|
+
# Prevent Console from trying to merge loggers
|
11
|
+
def self.logger_outputs_to?(*args)
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
# Prevent broadcasting since SemanticLogger already supports multiple loggers
|
16
|
+
def self.broadcast(logger)
|
17
|
+
Module.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.new(*args, **kwargs)
|
21
|
+
SemanticLogger[self]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
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.6.1
|
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: 2021-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -44,17 +44,16 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '4.
|
47
|
+
version: '4.8'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '4.
|
54
|
+
version: '4.8'
|
55
55
|
description:
|
56
56
|
email:
|
57
|
-
- reidmo@gmail.com
|
58
57
|
executables: []
|
59
58
|
extensions: []
|
60
59
|
extra_rdoc_files: []
|
@@ -75,11 +74,15 @@ files:
|
|
75
74
|
- lib/rails_semantic_logger/extensions/action_view/streaming_template_renderer.rb
|
76
75
|
- lib/rails_semantic_logger/extensions/active_job/logging.rb
|
77
76
|
- lib/rails_semantic_logger/extensions/active_model_serializers/logging.rb
|
77
|
+
- lib/rails_semantic_logger/extensions/active_support/logger.rb
|
78
|
+
- lib/rails_semantic_logger/extensions/active_support/tagged_logging.rb
|
79
|
+
- lib/rails_semantic_logger/extensions/mongoid/config.rb
|
80
|
+
- lib/rails_semantic_logger/extensions/rack/server.rb
|
78
81
|
- lib/rails_semantic_logger/extensions/rails/server.rb
|
79
82
|
- lib/rails_semantic_logger/options.rb
|
80
83
|
- lib/rails_semantic_logger/rack/logger.rb
|
81
84
|
- lib/rails_semantic_logger/version.rb
|
82
|
-
homepage: https://
|
85
|
+
homepage: https://logger.rocketjob.io
|
83
86
|
licenses:
|
84
87
|
- Apache-2.0
|
85
88
|
metadata: {}
|
@@ -91,14 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
94
|
requirements:
|
92
95
|
- - ">="
|
93
96
|
- !ruby/object:Gem::Version
|
94
|
-
version: '2.
|
97
|
+
version: '2.5'
|
95
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
99
|
requirements:
|
97
100
|
- - ">="
|
98
101
|
- !ruby/object:Gem::Version
|
99
102
|
version: '0'
|
100
103
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.2.22
|
102
105
|
signing_key:
|
103
106
|
specification_version: 4
|
104
107
|
summary: Feature rich logging framework that replaces the Rails logger.
|