rails_semantic_logger 4.4.4 → 4.4.5
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.rb +0 -1
- data/lib/rails_semantic_logger/engine.rb +151 -135
- data/lib/rails_semantic_logger/options.rb +2 -1
- data/lib/rails_semantic_logger/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c899a97af82d65b03bee094d84f29ea78e62afb88b47bbf1dd9809805df998d3
|
4
|
+
data.tar.gz: a0feb72c5299a8ee795a9a797405d15732094bae04d2dab5a582d5197139b20c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7146775a00bbc077bb374a71f0dcd04c675bd9398f5169c2b22557a1f04072e3abd7aaf8ee606836f64d062033e12d5f01dd52390c988ef5be30c4e302d905e
|
7
|
+
data.tar.gz: cd7ce812d642c7afb72468941acafae6282ea749e655615e3441fafb6a221ad1a0c26625dd330a6278d058ded947bbc20afe6e206e9b0aab82bf1e5a7049cce8
|
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
|
-
|
24
|
+
For the complete list of supported Ruby and Rails versions, see the [Testing file](https://github.com/rocketjob/rails_semantic_logger/blob/master/.travis.yml).
|
25
25
|
|
26
26
|
## Author
|
27
27
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "rails"
|
2
2
|
require "action_controller/log_subscriber"
|
3
|
+
require "action_view/log_subscriber"
|
3
4
|
require "rails_semantic_logger/options"
|
4
5
|
|
5
6
|
module RailsSemanticLogger
|
@@ -32,176 +33,191 @@ module RailsSemanticLogger
|
|
32
33
|
initializer :initialize_logger, group: :all do
|
33
34
|
config = Rails.application.config
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
unless config.rails_semantic_logger.disabled
|
37
|
+
# Set the default log level based on the Rails config
|
38
|
+
SemanticLogger.default_level = config.log_level
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
if defined?(Rails::Rack::Logger) && config.rails_semantic_logger.semantic
|
41
|
+
config.middleware.swap(Rails::Rack::Logger, RailsSemanticLogger::Rack::Logger, config.log_tags)
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
44
|
+
# Existing loggers are ignored because servers like trinidad supply their
|
45
|
+
# own file loggers which would result in duplicate logging to the same log file
|
46
|
+
Rails.logger = config.logger =
|
47
|
+
begin
|
48
|
+
if config.rails_semantic_logger.add_file_appender
|
49
|
+
path = config.paths["log"].first
|
50
|
+
FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(File.dirname(path))
|
51
|
+
|
52
|
+
# Add the log file to the list of appenders
|
53
|
+
# Use the colorized formatter if Rails colorized logs are enabled
|
54
|
+
ap_options = config.rails_semantic_logger.ap_options
|
55
|
+
formatter = config.rails_semantic_logger.format
|
56
|
+
formatter = {color: {ap: ap_options}} if (formatter == :default) && (config.colorize_logging != false)
|
57
|
+
|
58
|
+
# Set internal logger to log to file only, in case another appender experiences errors during writes
|
59
|
+
appender = SemanticLogger::Appender::File.new(
|
60
|
+
file_name: path,
|
61
|
+
level: config.log_level,
|
62
|
+
formatter: formatter
|
63
|
+
)
|
64
|
+
appender.name = "SemanticLogger"
|
65
|
+
SemanticLogger::Processor.logger = appender
|
66
|
+
|
67
|
+
# Check for previous file or stdout loggers
|
68
|
+
SemanticLogger.appenders.each { |app| app.formatter = formatter if app.is_a?(SemanticLogger::Appender::File) }
|
69
|
+
SemanticLogger.add_appender(file_name: path, formatter: formatter, filter: config.rails_semantic_logger.filter)
|
70
|
+
end
|
71
|
+
|
72
|
+
SemanticLogger[Rails]
|
73
|
+
rescue StandardError => e
|
74
|
+
# If not able to log to file, log to standard error with warning level only
|
75
|
+
SemanticLogger.default_level = :warn
|
76
|
+
|
77
|
+
SemanticLogger::Processor.logger = SemanticLogger::Appender::File.new(io: STDERR)
|
78
|
+
SemanticLogger.add_appender(io: STDERR)
|
79
|
+
|
80
|
+
logger = SemanticLogger[Rails]
|
81
|
+
logger.warn(
|
82
|
+
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " \
|
83
|
+
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.",
|
84
|
+
e
|
61
85
|
)
|
62
|
-
|
63
|
-
SemanticLogger::Processor.logger = appender
|
64
|
-
|
65
|
-
# Check for previous file or stdout loggers
|
66
|
-
SemanticLogger.appenders.each { |app| app.formatter = formatter if app.is_a?(SemanticLogger::Appender::File) }
|
67
|
-
SemanticLogger.add_appender(file_name: path, formatter: formatter, filter: config.rails_semantic_logger.filter)
|
86
|
+
logger
|
68
87
|
end
|
69
88
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
SemanticLogger.default_level = :warn
|
74
|
-
|
75
|
-
SemanticLogger::Processor.logger = SemanticLogger::Appender::File.new(io: STDERR)
|
76
|
-
SemanticLogger.add_appender(io: STDERR)
|
77
|
-
|
78
|
-
logger = SemanticLogger[Rails]
|
79
|
-
logger.warn(
|
80
|
-
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " \
|
81
|
-
"The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.",
|
82
|
-
e
|
83
|
-
)
|
84
|
-
logger
|
89
|
+
# Replace Rails loggers
|
90
|
+
%i[active_record action_controller action_mailer action_view].each do |name|
|
91
|
+
ActiveSupport.on_load(name) { include SemanticLogger::Loggable }
|
85
92
|
end
|
86
|
-
|
87
|
-
# Replace Rails loggers
|
88
|
-
%i[active_record action_controller action_mailer action_view].each do |name|
|
89
|
-
ActiveSupport.on_load(name) { include SemanticLogger::Loggable }
|
93
|
+
ActiveSupport.on_load(:action_cable) { self.logger = SemanticLogger["ActionCable"] }
|
90
94
|
end
|
91
|
-
ActiveSupport.on_load(:action_cable) { self.logger = SemanticLogger["ActionCable"] }
|
92
95
|
end
|
93
96
|
|
94
97
|
# Before any initializers run, but after the gems have been loaded
|
95
98
|
config.before_initialize do
|
96
|
-
|
97
|
-
config.
|
99
|
+
unless config.rails_semantic_logger.disabled
|
100
|
+
if config.respond_to?(:assets) && defined?(Rails::Rack::Logger) && config.rails_semantic_logger.semantic
|
101
|
+
config.rails_semantic_logger.quiet_assets = true if config.assets.quiet
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
103
|
+
# Otherwise Sprockets can't find the Rails::Rack::Logger middleware
|
104
|
+
config.assets.quiet = false
|
105
|
+
end
|
102
106
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
+
# Replace the Mongo Loggers
|
108
|
+
Mongoid.logger = SemanticLogger[Mongoid] if defined?(Mongoid)
|
109
|
+
Moped.logger = SemanticLogger[Moped] if defined?(Moped)
|
110
|
+
Mongo::Logger.logger = SemanticLogger[Mongo] if defined?(Mongo::Logger)
|
107
111
|
|
108
|
-
|
109
|
-
|
112
|
+
# Replace the Resque Logger
|
113
|
+
Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger)
|
110
114
|
|
111
|
-
|
112
|
-
|
115
|
+
# Replace the Sidekiq logger
|
116
|
+
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
|
113
117
|
|
114
|
-
|
115
|
-
|
118
|
+
# Replace the Sidetiq logger
|
119
|
+
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq)
|
116
120
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
121
|
+
# Replace the DelayedJob logger
|
122
|
+
if defined?(Delayed::Worker)
|
123
|
+
Delayed::Worker.logger = SemanticLogger[Delayed::Worker]
|
124
|
+
Delayed::Worker.plugins << RailsSemanticLogger::DelayedJob::Plugin
|
125
|
+
end
|
122
126
|
|
123
|
-
|
124
|
-
|
127
|
+
# Replace the Bugsnag logger
|
128
|
+
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
129
|
+
end
|
125
130
|
end
|
126
131
|
|
127
132
|
# After any initializers run, but after the gems have been loaded
|
128
133
|
config.after_initialize do
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
134
|
+
unless config.rails_semantic_logger.disabled
|
135
|
+
# Replace the Bugsnag logger
|
136
|
+
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
137
|
+
|
138
|
+
# Rails Patches
|
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)
|
143
|
+
require("rails_semantic_logger/extensions/action_view/streaming_template_renderer")
|
144
|
+
end
|
145
|
+
require("rails_semantic_logger/extensions/active_job/logging") if defined?(::ActiveJob)
|
146
|
+
require("rails_semantic_logger/extensions/active_model_serializers/logging") if defined?(ActiveModelSerializers)
|
147
|
+
require("rails_semantic_logger/extensions/rails/server") if defined?(Rails::Server)
|
148
|
+
|
149
|
+
if config.rails_semantic_logger.semantic
|
150
|
+
# Active Job
|
151
|
+
if defined?(::ActiveJob) && defined?(::ActiveJob::Logging::LogSubscriber)
|
152
|
+
RailsSemanticLogger.swap_subscriber(
|
153
|
+
::ActiveJob::Logging::LogSubscriber,
|
154
|
+
RailsSemanticLogger::ActiveJob::LogSubscriber,
|
155
|
+
:active_job
|
156
|
+
)
|
157
|
+
end
|
158
|
+
|
159
|
+
if defined?(::ActiveJob) && defined?(::ActiveJob::LogSubscriber)
|
160
|
+
RailsSemanticLogger.swap_subscriber(
|
161
|
+
::ActiveJob::LogSubscriber,
|
162
|
+
RailsSemanticLogger::ActiveJob::LogSubscriber,
|
163
|
+
:active_job
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
# Active Record
|
168
|
+
if defined?(::ActiveRecord)
|
169
|
+
require "active_record/log_subscriber"
|
170
|
+
|
171
|
+
RailsSemanticLogger.swap_subscriber(
|
172
|
+
::ActiveRecord::LogSubscriber,
|
173
|
+
RailsSemanticLogger::ActiveRecord::LogSubscriber,
|
174
|
+
:active_record
|
175
|
+
)
|
176
|
+
end
|
177
|
+
|
178
|
+
# Rack
|
179
|
+
RailsSemanticLogger::Rack::Logger.started_request_log_level = :info if config.rails_semantic_logger.started
|
180
|
+
|
181
|
+
# Silence asset logging by applying a filter to the Rails logger itself, not any of the appenders.
|
182
|
+
if config.rails_semantic_logger.quiet_assets && config.assets.prefix
|
183
|
+
assets_regex = %r(\A/{0,2}#{config.assets.prefix})
|
184
|
+
RailsSemanticLogger::Rack::Logger.logger.filter = ->(log) { log.payload[:path] !~ assets_regex if log.payload }
|
185
|
+
end
|
141
186
|
|
142
|
-
|
143
|
-
|
144
|
-
if defined?(::ActiveJob)
|
187
|
+
# Action View
|
188
|
+
RailsSemanticLogger::ActionView::LogSubscriber.rendered_log_level = :info if config.rails_semantic_logger.rendered
|
145
189
|
RailsSemanticLogger.swap_subscriber(
|
146
|
-
::
|
147
|
-
RailsSemanticLogger::
|
148
|
-
:
|
190
|
+
::ActionView::LogSubscriber,
|
191
|
+
RailsSemanticLogger::ActionView::LogSubscriber,
|
192
|
+
:action_view
|
149
193
|
)
|
150
|
-
end
|
151
|
-
|
152
|
-
# Active Record
|
153
|
-
if defined?(::ActiveRecord)
|
154
|
-
require "active_record/log_subscriber"
|
155
194
|
|
195
|
+
# Action Controller
|
156
196
|
RailsSemanticLogger.swap_subscriber(
|
157
|
-
::
|
158
|
-
RailsSemanticLogger::
|
159
|
-
:
|
197
|
+
::ActionController::LogSubscriber,
|
198
|
+
RailsSemanticLogger::ActionController::LogSubscriber,
|
199
|
+
:action_controller
|
160
200
|
)
|
161
201
|
end
|
162
202
|
|
163
|
-
#
|
164
|
-
|
203
|
+
#
|
204
|
+
# Forking Frameworks
|
205
|
+
#
|
165
206
|
|
166
|
-
#
|
167
|
-
|
168
|
-
|
169
|
-
|
207
|
+
# Passenger provides the :starting_worker_process event for executing
|
208
|
+
# code after it has forked, so we use that and reconnect immediately.
|
209
|
+
if defined?(PhusionPassenger)
|
210
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
211
|
+
SemanticLogger.reopen if forked
|
212
|
+
end
|
170
213
|
end
|
171
214
|
|
172
|
-
#
|
173
|
-
|
174
|
-
RailsSemanticLogger.swap_subscriber(
|
175
|
-
::ActionView::LogSubscriber,
|
176
|
-
RailsSemanticLogger::ActionView::LogSubscriber,
|
177
|
-
:action_view
|
178
|
-
)
|
179
|
-
|
180
|
-
# Action Controller
|
181
|
-
RailsSemanticLogger.swap_subscriber(
|
182
|
-
::ActionController::LogSubscriber,
|
183
|
-
RailsSemanticLogger::ActionController::LogSubscriber,
|
184
|
-
:action_controller
|
185
|
-
)
|
186
|
-
end
|
187
|
-
|
188
|
-
#
|
189
|
-
# Forking Frameworks
|
190
|
-
#
|
215
|
+
# Re-open appenders after Resque has forked a worker
|
216
|
+
Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque)
|
191
217
|
|
192
|
-
|
193
|
-
|
194
|
-
if defined?(PhusionPassenger)
|
195
|
-
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
196
|
-
SemanticLogger.reopen if forked
|
197
|
-
end
|
218
|
+
# Re-open appenders after Spring has forked a process
|
219
|
+
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
198
220
|
end
|
199
|
-
|
200
|
-
# Re-open appenders after Resque has forked a worker
|
201
|
-
Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque)
|
202
|
-
|
203
|
-
# Re-open appenders after Spring has forked a process
|
204
|
-
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
205
221
|
end
|
206
222
|
end
|
207
223
|
end
|
@@ -98,7 +98,7 @@ module RailsSemanticLogger
|
|
98
98
|
# config.rails_semantic_logger.named_tags = nil
|
99
99
|
class Options
|
100
100
|
attr_accessor :semantic, :started, :processing, :rendered, :ap_options, :add_file_appender,
|
101
|
-
:quiet_assets, :format, :named_tags, :filter
|
101
|
+
:quiet_assets, :format, :named_tags, :filter, :disabled
|
102
102
|
|
103
103
|
# Setup default values
|
104
104
|
def initialize
|
@@ -112,6 +112,7 @@ module RailsSemanticLogger
|
|
112
112
|
@format = :default
|
113
113
|
@named_tags = nil
|
114
114
|
@filter = nil
|
115
|
+
@disabled = false
|
115
116
|
end
|
116
117
|
end
|
117
118
|
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.
|
4
|
+
version: 4.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.4'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- reidmo@gmail.com
|
58
58
|
executables: []
|
@@ -83,7 +83,7 @@ homepage: https://github.com/rocketjob/rails_semantic_logger
|
|
83
83
|
licenses:
|
84
84
|
- Apache-2.0
|
85
85
|
metadata: {}
|
86
|
-
post_install_message:
|
86
|
+
post_install_message:
|
87
87
|
rdoc_options: []
|
88
88
|
require_paths:
|
89
89
|
- lib
|
@@ -98,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
|
-
rubygems_version: 3.
|
102
|
-
signing_key:
|
101
|
+
rubygems_version: 3.1.4
|
102
|
+
signing_key:
|
103
103
|
specification_version: 4
|
104
104
|
summary: Feature rich logging framework that replaces the Rails logger.
|
105
105
|
test_files: []
|