rails_semantic_logger 4.5.0 → 4.6.2
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/action_controller/log_subscriber.rb +2 -2
- data/lib/rails_semantic_logger/action_view/log_subscriber.rb +2 -2
- data/lib/rails_semantic_logger/active_job/log_subscriber.rb +12 -7
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +3 -2
- data/lib/rails_semantic_logger/engine.rb +25 -7
- data/lib/rails_semantic_logger/extensions/action_cable/tagged_logger_proxy.rb +1 -1
- data/lib/rails_semantic_logger/extensions/action_controller/live.rb +3 -1
- data/lib/rails_semantic_logger/extensions/action_dispatch/debug_exceptions.rb +3 -1
- data/lib/rails_semantic_logger/extensions/action_view/streaming_template_renderer.rb +2 -1
- data/lib/rails_semantic_logger/extensions/active_job/logging.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 +6 -2
- data/lib/rails_semantic_logger/options.rb +6 -1
- data/lib/rails_semantic_logger/rack/logger.rb +1 -1
- data/lib/rails_semantic_logger/version.rb +1 -1
- data/lib/rails_semantic_logger.rb +4 -0
- 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: 6a51cc8580e730f4cf67e6525e4f560bf4b75d36f6876f89dc4381654ce58bfc
|
4
|
+
data.tar.gz: db93994bb8dde3d26e6e474f31fb1f80c225268037f8789f8a2ade91bb60f52c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 652228c641c795518f5030573d8eaf434f81a0bea1104e210c1da2bef83bc0e0cd2b6f26efd3d76cf1dbe04d10f4053a717883ddbe3b6d5bedf9619151bdb121
|
7
|
+
data.tar.gz: bd56572399d0c83ec385ab9e9db12b3b7f48428c54bd71b9c905595e5c619cebaff6e9e0df8792e719d69e4e6f3693a28fba8bb5606450c56e384cedea7abade
|
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
|
|
@@ -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]
|
@@ -40,7 +40,7 @@ module RailsSemanticLogger
|
|
40
40
|
partial: from_rails_root(event.payload[:identifier])
|
41
41
|
}
|
42
42
|
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
|
43
|
-
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
44
|
payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
45
45
|
|
46
46
|
logger.measure(
|
@@ -60,7 +60,7 @@ module RailsSemanticLogger
|
|
60
60
|
template: from_rails_root(identifier),
|
61
61
|
count: event.payload[:count]
|
62
62
|
}
|
63
|
-
payload[:cache_hits] = payload[:cache_hits] if payload[:cache_hits]
|
63
|
+
payload[:cache_hits] = event.payload[:cache_hits] if event.payload[:cache_hits]
|
64
64
|
payload[:allocations] = event.allocations if event.respond_to?(:allocations)
|
65
65
|
|
66
66
|
logger.measure(
|
@@ -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
|
@@ -107,10 +112,10 @@ module RailsSemanticLogger
|
|
107
112
|
end
|
108
113
|
end
|
109
114
|
|
110
|
-
def log_with_formatter(**kw_args)
|
115
|
+
def log_with_formatter(level: :info, **kw_args)
|
111
116
|
fmt = EventFormatter.new(**kw_args)
|
112
117
|
msg = yield fmt
|
113
|
-
logger.
|
118
|
+
logger.public_send(level, **msg, payload: fmt.payload)
|
114
119
|
end
|
115
120
|
|
116
121
|
def logger
|
@@ -32,6 +32,7 @@ module RailsSemanticLogger
|
|
32
32
|
log_payload = {sql: payload[:sql]}
|
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
|
+
log_payload[:cached] = event.payload[:cached]
|
35
36
|
|
36
37
|
log = {
|
37
38
|
message: name,
|
@@ -41,7 +42,7 @@ module RailsSemanticLogger
|
|
41
42
|
|
42
43
|
# Log the location of the query itself.
|
43
44
|
if logger.send(:level_index) >= SemanticLogger.backtrace_level_index
|
44
|
-
log[:backtrace] = SemanticLogger::Utils.strip_backtrace
|
45
|
+
log[:backtrace] = SemanticLogger::Utils.strip_backtrace(caller)
|
45
46
|
end
|
46
47
|
|
47
48
|
logger.debug(log)
|
@@ -177,7 +178,7 @@ module RailsSemanticLogger
|
|
177
178
|
attr = nil
|
178
179
|
end
|
179
180
|
|
180
|
-
[attr&.name, value]
|
181
|
+
[attr&.name || :nil, value]
|
181
182
|
end
|
182
183
|
|
183
184
|
def type_casted_binds_v5_0_3(binds, casted_binds)
|
@@ -123,22 +123,27 @@ module RailsSemanticLogger
|
|
123
123
|
|
124
124
|
# Replace the Bugsnag logger
|
125
125
|
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
126
|
+
|
127
|
+
# Set the IOStreams PGP logger
|
128
|
+
IOStreams::Pgp.logger = SemanticLogger["IOStreams::Pgp"] if defined?(IOStreams)
|
126
129
|
end
|
127
130
|
|
128
131
|
# After any initializers run, but after the gems have been loaded
|
129
132
|
config.after_initialize do
|
133
|
+
config = Rails.application.config
|
134
|
+
|
130
135
|
# Replace the Bugsnag logger
|
131
|
-
Bugsnag.configure { |
|
136
|
+
Bugsnag.configure { |bugsnag_config| bugsnag_config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
132
137
|
|
133
138
|
# 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)
|
139
|
+
require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(::ActionCable)
|
140
|
+
require("rails_semantic_logger/extensions/action_controller/live") if defined?(::ActionController::Live)
|
141
|
+
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(::ActionDispatch::DebugExceptions)
|
142
|
+
if defined?(::ActionView::StreamingTemplateRenderer::Body)
|
138
143
|
require("rails_semantic_logger/extensions/action_view/streaming_template_renderer")
|
139
144
|
end
|
140
145
|
require("rails_semantic_logger/extensions/active_job/logging") if defined?(::ActiveJob)
|
141
|
-
require("rails_semantic_logger/extensions/active_model_serializers/logging") if defined?(ActiveModelSerializers)
|
146
|
+
require("rails_semantic_logger/extensions/active_model_serializers/logging") if defined?(::ActiveModelSerializers)
|
142
147
|
|
143
148
|
if config.rails_semantic_logger.semantic
|
144
149
|
# Active Job
|
@@ -174,7 +179,8 @@ module RailsSemanticLogger
|
|
174
179
|
|
175
180
|
# Silence asset logging by applying a filter to the Rails logger itself, not any of the appenders.
|
176
181
|
if config.rails_semantic_logger.quiet_assets && config.assets.prefix
|
177
|
-
|
182
|
+
assets_root = config.relative_url_root.to_s + config.assets.prefix
|
183
|
+
assets_regex = %r(\A/{0,2}#{assets_root})
|
178
184
|
RailsSemanticLogger::Rack::Logger.logger.filter = ->(log) { log.payload[:path] !~ assets_regex if log.payload }
|
179
185
|
end
|
180
186
|
|
@@ -211,6 +217,18 @@ module RailsSemanticLogger
|
|
211
217
|
|
212
218
|
# Re-open appenders after Spring has forked a process
|
213
219
|
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
220
|
+
|
221
|
+
console do |_app|
|
222
|
+
# Don't use a background thread for logging
|
223
|
+
SemanticLogger.sync!
|
224
|
+
# Add a stderr logger when running inside a Rails console unless one has already been added.
|
225
|
+
if config.rails_semantic_logger.console_logger && !SemanticLogger::Logger.processor.appenders.console_output?
|
226
|
+
SemanticLogger.add_appender(io: STDERR, formatter: :color)
|
227
|
+
end
|
228
|
+
|
229
|
+
# Include method names on log entries in the console
|
230
|
+
SemanticLogger.backtrace_level = SemanticLogger.default_level
|
231
|
+
end
|
214
232
|
end
|
215
233
|
end
|
216
234
|
end
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# Log actual exceptions, not a string representation
|
2
|
-
|
2
|
+
require "action_dispatch"
|
3
|
+
|
3
4
|
module ActionDispatch
|
4
5
|
class DebugExceptions
|
5
6
|
private
|
6
7
|
|
8
|
+
undef_method :log_error
|
7
9
|
def log_error(_request, wrapper)
|
8
10
|
ActiveSupport::Deprecation.silence do
|
9
11
|
ActionController::Base.logger.fatal(wrapper.exception)
|
@@ -1,11 +1,12 @@
|
|
1
1
|
# Log actual exceptions, not a string representation
|
2
|
-
|
2
|
+
require "action_view/renderer/streaming_template_renderer"
|
3
3
|
|
4
4
|
module ActionView
|
5
5
|
class StreamingTemplateRenderer
|
6
6
|
class Body
|
7
7
|
private
|
8
8
|
|
9
|
+
undef_method :log_error
|
9
10
|
def log_error(exception)
|
10
11
|
ActionView::Base.logger.fatal(exception)
|
11
12
|
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
|
@@ -1,10 +1,14 @@
|
|
1
1
|
# Patch the Rails::Server log_to_stdout so that it logs via SemanticLogger
|
2
|
-
|
2
|
+
require "rails"
|
3
|
+
|
3
4
|
module Rails
|
4
5
|
class Server
|
5
6
|
private
|
6
|
-
|
7
|
+
|
8
|
+
undef_method :log_to_stdout
|
7
9
|
def log_to_stdout
|
10
|
+
wrapped_app # touch the app so the logger is set up
|
11
|
+
|
8
12
|
SemanticLogger.add_appender(io: $stdout, formatter: :color)
|
9
13
|
end
|
10
14
|
end
|
@@ -48,6 +48,10 @@ module RailsSemanticLogger
|
|
48
48
|
#
|
49
49
|
# config.rails_semantic_logger.quiet_assets = false
|
50
50
|
#
|
51
|
+
# * Disable automatic logging to stderr when running a Rails console.
|
52
|
+
#
|
53
|
+
# config.rails_semantic_logger.console_logger = false
|
54
|
+
#
|
51
55
|
# * Override the output format for the primary Rails log file.
|
52
56
|
#
|
53
57
|
# Valid options:
|
@@ -98,7 +102,7 @@ module RailsSemanticLogger
|
|
98
102
|
# config.rails_semantic_logger.named_tags = nil
|
99
103
|
class Options
|
100
104
|
attr_accessor :semantic, :started, :processing, :rendered, :ap_options, :add_file_appender,
|
101
|
-
:quiet_assets, :format, :named_tags, :filter
|
105
|
+
:quiet_assets, :format, :named_tags, :filter, :console_logger
|
102
106
|
|
103
107
|
# Setup default values
|
104
108
|
def initialize
|
@@ -112,6 +116,7 @@ module RailsSemanticLogger
|
|
112
116
|
@format = :default
|
113
117
|
@named_tags = nil
|
114
118
|
@filter = nil
|
119
|
+
@console_logger = true
|
115
120
|
end
|
116
121
|
end
|
117
122
|
end
|
@@ -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)
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-27 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.2.
|
104
|
+
rubygems_version: 3.2.32
|
102
105
|
signing_key:
|
103
106
|
specification_version: 4
|
104
107
|
summary: Feature rich logging framework that replaces the Rails logger.
|