rails_semantic_logger 4.4.0 → 4.4.5
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/README.md +1 -1
- data/Rakefile +9 -9
- data/lib/rails_semantic_logger.rb +22 -12
- data/lib/rails_semantic_logger/action_controller/log_subscriber.rb +5 -5
- data/lib/rails_semantic_logger/action_view/log_subscriber.rb +13 -13
- data/lib/rails_semantic_logger/active_job/log_subscriber.rb +117 -0
- data/lib/rails_semantic_logger/active_record/log_subscriber.rb +4 -4
- data/lib/rails_semantic_logger/delayed_job/plugin.rb +1 -1
- data/lib/rails_semantic_logger/engine.rb +160 -131
- data/lib/rails_semantic_logger/extensions/active_job/logging.rb +1 -1
- data/lib/rails_semantic_logger/extensions/active_model_serializers/logging.rb +1 -1
- data/lib/rails_semantic_logger/options.rb +2 -1
- data/lib/rails_semantic_logger/rack/logger.rb +9 -9
- data/lib/rails_semantic_logger/version.rb +1 -1
- metadata +23 -8
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
|
|
data/Rakefile
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# Setup bundler to avoid having to run bundle exec all the time.
|
2
|
-
require
|
3
|
-
require
|
2
|
+
require "rubygems"
|
3
|
+
require "bundler/setup"
|
4
4
|
|
5
|
-
require
|
6
|
-
require_relative
|
5
|
+
require "rake/testtask"
|
6
|
+
require_relative "lib/rails_semantic_logger/version"
|
7
7
|
|
8
8
|
task :gem do
|
9
|
-
system
|
9
|
+
system "gem build rails_semantic_logger.gemspec"
|
10
10
|
end
|
11
11
|
|
12
12
|
task publish: :gem do
|
13
13
|
system "git tag -a v#{RailsSemanticLogger::VERSION} -m 'Tagging #{RailsSemanticLogger::VERSION}'"
|
14
|
-
system
|
14
|
+
system "git push --tags"
|
15
15
|
system "gem push rails_semantic_logger-#{RailsSemanticLogger::VERSION}.gem"
|
16
16
|
system "rm rails_semantic_logger-#{RailsSemanticLogger::VERSION}.gem"
|
17
17
|
end
|
18
18
|
|
19
19
|
Rake::TestTask.new(:test) do |t|
|
20
|
-
t.pattern =
|
20
|
+
t.pattern = "test/**/*_test.rb"
|
21
21
|
t.verbose = true
|
22
22
|
t.warning = false
|
23
23
|
end
|
24
24
|
|
25
25
|
# By default run tests against all appraisals
|
26
|
-
if !ENV[
|
27
|
-
require
|
26
|
+
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
|
27
|
+
require "appraisal"
|
28
28
|
task default: :appraisal
|
29
29
|
else
|
30
30
|
task default: :test
|
@@ -1,25 +1,27 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'rails_semantic_logger/engine'
|
1
|
+
require "semantic_logger"
|
2
|
+
require "rails_semantic_logger/engine"
|
4
3
|
|
5
4
|
module RailsSemanticLogger
|
6
5
|
module ActionController
|
7
|
-
autoload :LogSubscriber,
|
6
|
+
autoload :LogSubscriber, "rails_semantic_logger/action_controller/log_subscriber"
|
8
7
|
end
|
9
8
|
module ActionView
|
10
|
-
autoload :LogSubscriber,
|
9
|
+
autoload :LogSubscriber, "rails_semantic_logger/action_view/log_subscriber"
|
10
|
+
end
|
11
|
+
module ActiveJob
|
12
|
+
autoload :LogSubscriber, "rails_semantic_logger/active_job/log_subscriber"
|
11
13
|
end
|
12
14
|
module ActiveRecord
|
13
|
-
autoload :LogSubscriber,
|
15
|
+
autoload :LogSubscriber, "rails_semantic_logger/active_record/log_subscriber"
|
14
16
|
end
|
15
17
|
module Rack
|
16
|
-
autoload :Logger,
|
18
|
+
autoload :Logger, "rails_semantic_logger/rack/logger"
|
17
19
|
end
|
18
20
|
module DelayedJob
|
19
|
-
autoload :Plugin,
|
21
|
+
autoload :Plugin, "rails_semantic_logger/delayed_job/plugin"
|
20
22
|
end
|
21
23
|
|
22
|
-
autoload :Options,
|
24
|
+
autoload :Options, "rails_semantic_logger/options"
|
23
25
|
|
24
26
|
# Swap an existing subscriber with a new one
|
25
27
|
def self.swap_subscriber(old_class, new_class, notifier)
|
@@ -30,14 +32,22 @@ module RailsSemanticLogger
|
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.unattach(subscriber)
|
33
|
-
subscriber.
|
34
|
-
ActiveSupport::Notifications.notifier.listeners_for(
|
35
|
+
subscriber_patterns(subscriber).each do |pattern|
|
36
|
+
ActiveSupport::Notifications.notifier.listeners_for(pattern).each do |sub|
|
35
37
|
next unless sub.instance_variable_get(:@delegate) == subscriber
|
38
|
+
|
36
39
|
ActiveSupport::Notifications.unsubscribe(sub)
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
43
|
ActiveSupport::LogSubscriber.subscribers.delete(subscriber)
|
41
44
|
end
|
42
|
-
|
45
|
+
|
46
|
+
def self.subscriber_patterns(subscriber)
|
47
|
+
subscriber.patterns.respond_to?(:keys) ?
|
48
|
+
subscriber.patterns.keys :
|
49
|
+
subscriber.patterns
|
50
|
+
end
|
51
|
+
|
52
|
+
private_class_method :subscriber_patterns, :unattach
|
43
53
|
end
|
@@ -44,7 +44,7 @@ module RailsSemanticLogger
|
|
44
44
|
params = payload[:params]
|
45
45
|
if params
|
46
46
|
# When logging to JSON the entire tempfile is logged, so convert it to a string.
|
47
|
-
params[
|
47
|
+
params["file"] = params["file"].inspect if params["file"]
|
48
48
|
end
|
49
49
|
|
50
50
|
{
|
@@ -60,15 +60,15 @@ module RailsSemanticLogger
|
|
60
60
|
end
|
61
61
|
|
62
62
|
def send_file(event)
|
63
|
-
controller_logger(event).info(message:
|
63
|
+
controller_logger(event).info(message: "Sent file", payload: {path: event.payload[:path]}, duration: event.duration)
|
64
64
|
end
|
65
65
|
|
66
66
|
def redirect_to(event)
|
67
|
-
controller_logger(event).info(message:
|
67
|
+
controller_logger(event).info(message: "Redirected to", payload: {location: event.payload[:location]})
|
68
68
|
end
|
69
69
|
|
70
70
|
def send_data(event)
|
71
|
-
controller_logger(event).info(message:
|
71
|
+
controller_logger(event).info(message: "Sent data", payload: {file_name: event.payload[:filename]}, duration: event.duration)
|
72
72
|
end
|
73
73
|
|
74
74
|
def unpermitted_parameters(event)
|
@@ -106,7 +106,7 @@ module RailsSemanticLogger
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def extract_path(path)
|
109
|
-
index = path.index(
|
109
|
+
index = path.index("?")
|
110
110
|
index ? path[0, index] : path
|
111
111
|
end
|
112
112
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/log_subscriber"
|
2
2
|
|
3
3
|
module RailsSemanticLogger
|
4
4
|
module ActionView
|
5
5
|
# Output Semantic logs from Action View.
|
6
6
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
7
|
-
VIEWS_PATTERN =
|
7
|
+
VIEWS_PATTERN = %r{^app/views/}.freeze
|
8
8
|
|
9
9
|
class << self
|
10
10
|
attr_reader :logger
|
@@ -19,14 +19,14 @@ module RailsSemanticLogger
|
|
19
19
|
def render_template(event)
|
20
20
|
return unless should_log?
|
21
21
|
|
22
|
-
payload
|
22
|
+
payload = {
|
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
26
|
|
27
27
|
logger.measure(
|
28
28
|
self.class.rendered_log_level,
|
29
|
-
|
29
|
+
"Rendered",
|
30
30
|
payload: payload,
|
31
31
|
duration: event.duration
|
32
32
|
)
|
@@ -35,7 +35,7 @@ module RailsSemanticLogger
|
|
35
35
|
def render_partial(event)
|
36
36
|
return unless should_log?
|
37
37
|
|
38
|
-
payload
|
38
|
+
payload = {
|
39
39
|
partial: from_rails_root(event.payload[:identifier])
|
40
40
|
}
|
41
41
|
payload[:within] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
|
@@ -43,7 +43,7 @@ module RailsSemanticLogger
|
|
43
43
|
|
44
44
|
logger.measure(
|
45
45
|
self.class.rendered_log_level,
|
46
|
-
|
46
|
+
"Rendered",
|
47
47
|
payload: payload,
|
48
48
|
duration: event.duration
|
49
49
|
)
|
@@ -52,9 +52,9 @@ module RailsSemanticLogger
|
|
52
52
|
def render_collection(event)
|
53
53
|
return unless should_log?
|
54
54
|
|
55
|
-
identifier = event.payload[:identifier] ||
|
55
|
+
identifier = event.payload[:identifier] || "templates"
|
56
56
|
|
57
|
-
payload
|
57
|
+
payload = {
|
58
58
|
template: from_rails_root(identifier),
|
59
59
|
count: event.payload[:count]
|
60
60
|
}
|
@@ -62,18 +62,18 @@ module RailsSemanticLogger
|
|
62
62
|
|
63
63
|
logger.measure(
|
64
64
|
self.class.rendered_log_level,
|
65
|
-
|
65
|
+
"Rendered",
|
66
66
|
payload: payload,
|
67
67
|
duration: event.duration
|
68
68
|
)
|
69
69
|
end
|
70
70
|
|
71
71
|
def start(name, id, payload)
|
72
|
-
if (name ==
|
72
|
+
if (name == "render_template.action_view") && should_log?
|
73
73
|
payload = {template: from_rails_root(payload[:identifier])}
|
74
74
|
payload[:within] = from_rails_root(payload[:layout]) if payload[:layout]
|
75
75
|
|
76
|
-
logger.send(self.class.rendered_log_level, message:
|
76
|
+
logger.send(self.class.rendered_log_level, message: "Rendering", payload: payload)
|
77
77
|
end
|
78
78
|
|
79
79
|
super
|
@@ -81,10 +81,10 @@ module RailsSemanticLogger
|
|
81
81
|
|
82
82
|
private
|
83
83
|
|
84
|
-
@logger = SemanticLogger[
|
84
|
+
@logger = SemanticLogger["ActionView"]
|
85
85
|
@rendered_log_level = :debug
|
86
86
|
|
87
|
-
EMPTY =
|
87
|
+
EMPTY = "".freeze
|
88
88
|
|
89
89
|
def should_log?
|
90
90
|
logger.send("#{self.class.rendered_log_level}?")
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require "active_job"
|
2
|
+
|
3
|
+
module RailsSemanticLogger
|
4
|
+
module ActiveJob
|
5
|
+
class LogSubscriber < ::ActiveSupport::LogSubscriber
|
6
|
+
def enqueue(event)
|
7
|
+
log_with_formatter event: event do |fmt|
|
8
|
+
"Enqueued #{fmt.job_info}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def enqueue_at(event)
|
13
|
+
log_with_formatter event: event do |fmt|
|
14
|
+
"Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def perform_start(event)
|
19
|
+
log_with_formatter event: event do |fmt|
|
20
|
+
"Performing #{fmt.job_info}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform(event)
|
25
|
+
ex = event.payload[:exception_object]
|
26
|
+
if ex
|
27
|
+
logger.error ex
|
28
|
+
else
|
29
|
+
log_with_formatter event: event, log_duration: true do |fmt|
|
30
|
+
"Performed #{fmt.job_info} in #{event.duration.round(2)}ms"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
class EventFormatter
|
38
|
+
def initialize(event:, log_duration: false)
|
39
|
+
@event = event
|
40
|
+
@log_duration = log_duration
|
41
|
+
end
|
42
|
+
|
43
|
+
def job_info
|
44
|
+
"#{job.class.name} (Job ID: #{job.job_id}) to #{queue_name}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def payload
|
48
|
+
{}.tap do |h|
|
49
|
+
h[:event_name] = event.name
|
50
|
+
h[:adapter] = adapter_name
|
51
|
+
h[:queue] = job.queue_name
|
52
|
+
h[:job_class] = job.class.name
|
53
|
+
h[:job_id] = job.job_id
|
54
|
+
h[:provider_job_id] = job.try(:provider_job_id) # Not available in Rails 4.2
|
55
|
+
h[:duration] = event.duration.round(2) if log_duration?
|
56
|
+
h[:arguments] = formatted_args
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def queue_name
|
61
|
+
adapter_name + "(#{job.queue_name})"
|
62
|
+
end
|
63
|
+
|
64
|
+
def scheduled_at
|
65
|
+
Time.at(event.payload[:job].scheduled_at).utc
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
attr_reader :event
|
71
|
+
|
72
|
+
def job
|
73
|
+
event.payload[:job]
|
74
|
+
end
|
75
|
+
|
76
|
+
def adapter_name
|
77
|
+
event.payload[:adapter].class.name.demodulize.remove("Adapter")
|
78
|
+
end
|
79
|
+
|
80
|
+
def formatted_args
|
81
|
+
JSON.pretty_generate(job.arguments.map { |arg| format(arg) })
|
82
|
+
end
|
83
|
+
|
84
|
+
def format(arg)
|
85
|
+
case arg
|
86
|
+
when Hash
|
87
|
+
arg.transform_values { |value| format(value) }
|
88
|
+
when Array
|
89
|
+
arg.map { |value| format(value) }
|
90
|
+
when GlobalID::Identification
|
91
|
+
begin
|
92
|
+
arg.to_global_id
|
93
|
+
rescue StandardError
|
94
|
+
arg
|
95
|
+
end
|
96
|
+
else
|
97
|
+
arg
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def log_duration?
|
102
|
+
@log_duration
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def log_with_formatter(**kw_args)
|
107
|
+
fmt = EventFormatter.new(**kw_args)
|
108
|
+
msg = yield fmt
|
109
|
+
logger.info msg, fmt.payload
|
110
|
+
end
|
111
|
+
|
112
|
+
def logger
|
113
|
+
::ActiveJob::Base.logger
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -48,7 +48,7 @@ module RailsSemanticLogger
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
@logger = SemanticLogger[
|
51
|
+
@logger = SemanticLogger["ActiveRecord"]
|
52
52
|
|
53
53
|
# When multiple values are received for a single bound field, it is converted into an array
|
54
54
|
def add_bind_value(binds, key, value)
|
@@ -120,7 +120,7 @@ module RailsSemanticLogger
|
|
120
120
|
if column.binary?
|
121
121
|
# This specifically deals with the PG adapter that casts bytea columns into a Hash.
|
122
122
|
value = value[:value] if value.is_a?(Hash)
|
123
|
-
value = value ? "<#{value.bytesize} bytes of binary data>" :
|
123
|
+
value = value ? "<#{value.bytesize} bytes of binary data>" : "<NULL binary data>"
|
124
124
|
end
|
125
125
|
|
126
126
|
[column.name, value]
|
@@ -165,13 +165,13 @@ module RailsSemanticLogger
|
|
165
165
|
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR.zero? && Rails::VERSION::TINY <= 2 # 5.0.0 - 5.0.2
|
166
166
|
alias bind_values bind_values_v5_0_0
|
167
167
|
alias render_bind render_bind_v5_0_0
|
168
|
-
elsif Rails::VERSION::MAJOR
|
168
|
+
elsif Rails::VERSION::MAJOR == 5 &&
|
169
169
|
((Rails::VERSION::MINOR.zero? && Rails::VERSION::TINY <= 6) ||
|
170
170
|
(Rails::VERSION::MINOR == 1 && Rails::VERSION::TINY <= 4)) # 5.0.3 - 5.0.6 && 5.1.0 - 5.1.4
|
171
171
|
alias bind_values bind_values_v5_0_3
|
172
172
|
alias render_bind render_bind_v5_0_3
|
173
173
|
alias type_casted_binds type_casted_binds_v5_0_3
|
174
|
-
elsif Rails::VERSION::MAJOR >= 5 # ~> 5.1.5 && ~> 5.0.7
|
174
|
+
elsif Rails::VERSION::MAJOR >= 5 # ~> 5.1.5 && ~> 5.0.7 && 6.x.x
|
175
175
|
alias bind_values bind_values_v5_1_5
|
176
176
|
alias render_bind render_bind_v5_0_3
|
177
177
|
alias type_casted_binds type_casted_binds_v5_1_5
|
@@ -1,5 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rails"
|
2
|
+
require "action_controller/log_subscriber"
|
3
|
+
require "action_view/log_subscriber"
|
4
|
+
require "rails_semantic_logger/options"
|
3
5
|
|
4
6
|
module RailsSemanticLogger
|
5
7
|
class Engine < ::Rails::Engine
|
@@ -31,164 +33,191 @@ module RailsSemanticLogger
|
|
31
33
|
initializer :initialize_logger, group: :all do
|
32
34
|
config = Rails.application.config
|
33
35
|
|
34
|
-
|
35
|
-
|
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
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
# Existing loggers are ignored because servers like trinidad supply their
|
42
|
-
# own file loggers which would result in duplicate logging to the same log file
|
43
|
-
Rails.logger = config.logger = begin
|
44
|
-
if config.rails_semantic_logger.add_file_appender
|
45
|
-
path = config.paths['log'].first
|
46
|
-
FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(File.dirname(path))
|
47
|
-
|
48
|
-
# Add the log file to the list of appenders
|
49
|
-
# Use the colorized formatter if Rails colorized logs are enabled
|
50
|
-
ap_options = config.rails_semantic_logger.ap_options
|
51
|
-
formatter = config.rails_semantic_logger.format
|
52
|
-
formatter = {color: {ap: ap_options}} if (formatter == :default) && (config.colorize_logging != false)
|
53
|
-
|
54
|
-
# Set internal logger to log to file only, in case another appender experiences errors during writes
|
55
|
-
appender = SemanticLogger::Appender::File.new(
|
56
|
-
file_name: path,
|
57
|
-
level: config.log_level,
|
58
|
-
formatter: formatter
|
59
|
-
)
|
60
|
-
appender.name = 'SemanticLogger'
|
61
|
-
SemanticLogger::Processor.logger = appender
|
62
|
-
|
63
|
-
# Check for previous file or stdout loggers
|
64
|
-
SemanticLogger.appenders.each { |app| app.formatter = formatter if app.is_a?(SemanticLogger::Appender::File) }
|
65
|
-
SemanticLogger.add_appender(file_name: path, formatter: formatter, filter: config.rails_semantic_logger.filter)
|
40
|
+
if defined?(Rails::Rack::Logger) && config.rails_semantic_logger.semantic
|
41
|
+
config.middleware.swap(Rails::Rack::Logger, RailsSemanticLogger::Rack::Logger, config.log_tags)
|
66
42
|
end
|
67
43
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
85
|
+
)
|
86
|
+
logger
|
87
|
+
end
|
88
|
+
|
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 }
|
92
|
+
end
|
93
|
+
ActiveSupport.on_load(:action_cable) { self.logger = SemanticLogger["ActionCable"] }
|
88
94
|
end
|
89
|
-
ActiveSupport.on_load(:action_cable) { self.logger = SemanticLogger['ActionCable'] }
|
90
95
|
end
|
91
96
|
|
92
97
|
# Before any initializers run, but after the gems have been loaded
|
93
98
|
config.before_initialize do
|
94
|
-
|
95
|
-
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
|
96
102
|
|
97
|
-
|
98
|
-
|
99
|
-
|
103
|
+
# Otherwise Sprockets can't find the Rails::Rack::Logger middleware
|
104
|
+
config.assets.quiet = false
|
105
|
+
end
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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)
|
105
111
|
|
106
|
-
|
107
|
-
|
112
|
+
# Replace the Resque Logger
|
113
|
+
Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger)
|
108
114
|
|
109
|
-
|
110
|
-
|
115
|
+
# Replace the Sidekiq logger
|
116
|
+
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
|
111
117
|
|
112
|
-
|
113
|
-
|
118
|
+
# Replace the Sidetiq logger
|
119
|
+
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq)
|
114
120
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
120
126
|
|
121
|
-
|
122
|
-
|
127
|
+
# Replace the Bugsnag logger
|
128
|
+
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
129
|
+
end
|
123
130
|
end
|
124
131
|
|
125
132
|
# After any initializers run, but after the gems have been loaded
|
126
133
|
config.after_initialize do
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
if defined?(::
|
141
|
-
|
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
|
186
|
+
|
187
|
+
# Action View
|
188
|
+
RailsSemanticLogger::ActionView::LogSubscriber.rendered_log_level = :info if config.rails_semantic_logger.rendered
|
189
|
+
RailsSemanticLogger.swap_subscriber(
|
190
|
+
::ActionView::LogSubscriber,
|
191
|
+
RailsSemanticLogger::ActionView::LogSubscriber,
|
192
|
+
:action_view
|
193
|
+
)
|
142
194
|
|
195
|
+
# Action Controller
|
143
196
|
RailsSemanticLogger.swap_subscriber(
|
144
|
-
::
|
145
|
-
RailsSemanticLogger::
|
146
|
-
:
|
197
|
+
::ActionController::LogSubscriber,
|
198
|
+
RailsSemanticLogger::ActionController::LogSubscriber,
|
199
|
+
:action_controller
|
147
200
|
)
|
148
201
|
end
|
149
202
|
|
150
|
-
#
|
151
|
-
|
203
|
+
#
|
204
|
+
# Forking Frameworks
|
205
|
+
#
|
152
206
|
|
153
|
-
#
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
157
213
|
end
|
158
214
|
|
159
|
-
#
|
160
|
-
|
161
|
-
RailsSemanticLogger.swap_subscriber(
|
162
|
-
::ActionView::LogSubscriber,
|
163
|
-
RailsSemanticLogger::ActionView::LogSubscriber,
|
164
|
-
:action_view
|
165
|
-
)
|
166
|
-
|
167
|
-
# Action Controller
|
168
|
-
RailsSemanticLogger.swap_subscriber(
|
169
|
-
::ActionController::LogSubscriber,
|
170
|
-
RailsSemanticLogger::ActionController::LogSubscriber,
|
171
|
-
:action_controller
|
172
|
-
)
|
173
|
-
end
|
174
|
-
|
175
|
-
#
|
176
|
-
# Forking Frameworks
|
177
|
-
#
|
215
|
+
# Re-open appenders after Resque has forked a worker
|
216
|
+
Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque)
|
178
217
|
|
179
|
-
|
180
|
-
|
181
|
-
if defined?(PhusionPassenger)
|
182
|
-
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
183
|
-
SemanticLogger.reopen if forked
|
184
|
-
end
|
218
|
+
# Re-open appenders after Spring has forked a process
|
219
|
+
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring.after_fork)
|
185
220
|
end
|
186
|
-
|
187
|
-
# Re-open appenders after Resque has forked a worker
|
188
|
-
Resque.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Resque)
|
189
|
-
|
190
|
-
# Re-open appenders after Spring has forked a process
|
191
|
-
Spring.after_fork { |_job| ::SemanticLogger.reopen } if defined?(Spring)
|
192
221
|
end
|
193
222
|
end
|
194
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
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "active_support/core_ext/time/conversions"
|
2
|
+
require "active_support/core_ext/object/blank"
|
3
|
+
require "active_support/log_subscriber"
|
4
|
+
require "action_dispatch/http/request"
|
5
|
+
require "rack/body_proxy"
|
6
6
|
|
7
7
|
module RailsSemanticLogger
|
8
8
|
module Rack
|
@@ -31,12 +31,12 @@ module RailsSemanticLogger
|
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
@logger = SemanticLogger[
|
34
|
+
@logger = SemanticLogger["Rack"]
|
35
35
|
@started_request_log_level = :debug
|
36
36
|
|
37
37
|
def call_app(request, env)
|
38
38
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
39
|
-
instrumenter.start
|
39
|
+
instrumenter.start "request.action_dispatch", request: request
|
40
40
|
|
41
41
|
logger.send(self.class.started_request_log_level) { started_request_message(request) }
|
42
42
|
|
@@ -50,7 +50,7 @@ module RailsSemanticLogger
|
|
50
50
|
|
51
51
|
def started_request_message(request)
|
52
52
|
{
|
53
|
-
message:
|
53
|
+
message: "Started",
|
54
54
|
payload: {
|
55
55
|
method: request.request_method,
|
56
56
|
path: request.filtered_path,
|
@@ -92,7 +92,7 @@ module RailsSemanticLogger
|
|
92
92
|
|
93
93
|
def finish(request)
|
94
94
|
instrumenter = ActiveSupport::Notifications.instrumenter
|
95
|
-
instrumenter.finish
|
95
|
+
instrumenter.finish "request.action_dispatch", request: request
|
96
96
|
end
|
97
97
|
|
98
98
|
def logger
|
metadata
CHANGED
@@ -1,17 +1,31 @@
|
|
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:
|
11
|
+
date: 2020-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
@@ -38,7 +52,7 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '4.4'
|
41
|
-
description:
|
55
|
+
description:
|
42
56
|
email:
|
43
57
|
- reidmo@gmail.com
|
44
58
|
executables: []
|
@@ -51,6 +65,7 @@ files:
|
|
51
65
|
- lib/rails_semantic_logger.rb
|
52
66
|
- lib/rails_semantic_logger/action_controller/log_subscriber.rb
|
53
67
|
- lib/rails_semantic_logger/action_view/log_subscriber.rb
|
68
|
+
- lib/rails_semantic_logger/active_job/log_subscriber.rb
|
54
69
|
- lib/rails_semantic_logger/active_record/log_subscriber.rb
|
55
70
|
- lib/rails_semantic_logger/delayed_job/plugin.rb
|
56
71
|
- lib/rails_semantic_logger/engine.rb
|
@@ -68,7 +83,7 @@ homepage: https://github.com/rocketjob/rails_semantic_logger
|
|
68
83
|
licenses:
|
69
84
|
- Apache-2.0
|
70
85
|
metadata: {}
|
71
|
-
post_install_message:
|
86
|
+
post_install_message:
|
72
87
|
rdoc_options: []
|
73
88
|
require_paths:
|
74
89
|
- lib
|
@@ -83,8 +98,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
98
|
- !ruby/object:Gem::Version
|
84
99
|
version: '0'
|
85
100
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
101
|
+
rubygems_version: 3.1.4
|
102
|
+
signing_key:
|
88
103
|
specification_version: 4
|
89
104
|
summary: Feature rich logging framework that replaces the Rails logger.
|
90
105
|
test_files: []
|