rails_semantic_logger 4.4.3 → 4.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -9
- data/lib/rails_semantic_logger.rb +13 -9
- 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 +2 -2
- data/lib/rails_semantic_logger/delayed_job/plugin.rb +1 -1
- data/lib/rails_semantic_logger/engine.rb +68 -56
- data/lib/rails_semantic_logger/extensions/active_job/logging.rb +1 -122
- data/lib/rails_semantic_logger/extensions/active_model_serializers/logging.rb +1 -1
- data/lib/rails_semantic_logger/rack/logger.rb +9 -9
- data/lib/rails_semantic_logger/version.rb +1 -1
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4688d4d7a5bff26ad49c6cc6c44ee7995ae7b721d5d79c0dfb17d6a3d094568b
|
4
|
+
data.tar.gz: 3e68341e9623c93a936d52012916f7aad2f86406ab3e959f05ac949125e3f4c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff997d3efdbcf09809d25370dd99d8d7367303b814539f756551106b97f408709587faa9c2b0ea4815116fa19198c6ca5b67ce5c196e0b5f2480ef2a54cc480
|
7
|
+
data.tar.gz: eec1dbf2dca8daac64ed6a289021e8099177912486c3662c366d352a5bdfc0775920a2a0c7e549a19c2caa43da0fe57a87419bb41043b676cb4365a7943b0f55
|
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,28 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "semantic_logger"
|
2
|
+
require "rails_semantic_logger/extensions/rails/server" if defined?(Rails::Server)
|
3
|
+
require "rails_semantic_logger/engine"
|
4
4
|
|
5
5
|
module RailsSemanticLogger
|
6
6
|
module ActionController
|
7
|
-
autoload :LogSubscriber,
|
7
|
+
autoload :LogSubscriber, "rails_semantic_logger/action_controller/log_subscriber"
|
8
8
|
end
|
9
9
|
module ActionView
|
10
|
-
autoload :LogSubscriber,
|
10
|
+
autoload :LogSubscriber, "rails_semantic_logger/action_view/log_subscriber"
|
11
|
+
end
|
12
|
+
module ActiveJob
|
13
|
+
autoload :LogSubscriber, "rails_semantic_logger/active_job/log_subscriber"
|
11
14
|
end
|
12
15
|
module ActiveRecord
|
13
|
-
autoload :LogSubscriber,
|
16
|
+
autoload :LogSubscriber, "rails_semantic_logger/active_record/log_subscriber"
|
14
17
|
end
|
15
18
|
module Rack
|
16
|
-
autoload :Logger,
|
19
|
+
autoload :Logger, "rails_semantic_logger/rack/logger"
|
17
20
|
end
|
18
21
|
module DelayedJob
|
19
|
-
autoload :Plugin,
|
22
|
+
autoload :Plugin, "rails_semantic_logger/delayed_job/plugin"
|
20
23
|
end
|
21
24
|
|
22
|
-
autoload :Options,
|
25
|
+
autoload :Options, "rails_semantic_logger/options"
|
23
26
|
|
24
27
|
# Swap an existing subscriber with a new one
|
25
28
|
def self.swap_subscriber(old_class, new_class, notifier)
|
@@ -33,6 +36,7 @@ module RailsSemanticLogger
|
|
33
36
|
subscriber_patterns(subscriber).each do |pattern|
|
34
37
|
ActiveSupport::Notifications.notifier.listeners_for(pattern).each do |sub|
|
35
38
|
next unless sub.instance_variable_get(:@delegate) == subscriber
|
39
|
+
|
36
40
|
ActiveSupport::Notifications.unsubscribe(sub)
|
37
41
|
end
|
38
42
|
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]
|
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rails"
|
2
|
+
require "action_controller/log_subscriber"
|
3
|
+
require "rails_semantic_logger/options"
|
4
4
|
|
5
5
|
module RailsSemanticLogger
|
6
6
|
class Engine < ::Rails::Engine
|
@@ -41,53 +41,54 @@ module RailsSemanticLogger
|
|
41
41
|
|
42
42
|
# Existing loggers are ignored because servers like trinidad supply their
|
43
43
|
# own file loggers which would result in duplicate logging to the same log file
|
44
|
-
Rails.logger = config.logger =
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
44
|
+
Rails.logger = config.logger =
|
45
|
+
begin
|
46
|
+
if config.rails_semantic_logger.add_file_appender
|
47
|
+
path = config.paths["log"].first
|
48
|
+
FileUtils.mkdir_p(File.dirname(path)) unless File.exist?(File.dirname(path))
|
49
|
+
|
50
|
+
# Add the log file to the list of appenders
|
51
|
+
# Use the colorized formatter if Rails colorized logs are enabled
|
52
|
+
ap_options = config.rails_semantic_logger.ap_options
|
53
|
+
formatter = config.rails_semantic_logger.format
|
54
|
+
formatter = {color: {ap: ap_options}} if (formatter == :default) && (config.colorize_logging != false)
|
55
|
+
|
56
|
+
# Set internal logger to log to file only, in case another appender experiences errors during writes
|
57
|
+
appender = SemanticLogger::Appender::File.new(
|
58
|
+
file_name: path,
|
59
|
+
level: config.log_level,
|
60
|
+
formatter: formatter
|
61
|
+
)
|
62
|
+
appender.name = "SemanticLogger"
|
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)
|
68
|
+
end
|
69
|
+
|
70
|
+
SemanticLogger[Rails]
|
71
|
+
rescue StandardError => e
|
72
|
+
# If not able to log to file, log to standard error with warning level only
|
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
|
60
83
|
)
|
61
|
-
|
62
|
-
SemanticLogger::Processor.logger = appender
|
63
|
-
|
64
|
-
# Check for previous file or stdout loggers
|
65
|
-
SemanticLogger.appenders.each { |app| app.formatter = formatter if app.is_a?(SemanticLogger::Appender::File) }
|
66
|
-
SemanticLogger.add_appender(file_name: path, formatter: formatter, filter: config.rails_semantic_logger.filter)
|
84
|
+
logger
|
67
85
|
end
|
68
86
|
|
69
|
-
SemanticLogger[Rails]
|
70
|
-
rescue StandardError => exc
|
71
|
-
# If not able to log to file, log to standard error with warning level only
|
72
|
-
SemanticLogger.default_level = :warn
|
73
|
-
|
74
|
-
SemanticLogger::Processor.logger = SemanticLogger::Appender::File.new(io: STDERR)
|
75
|
-
SemanticLogger.add_appender(io: STDERR)
|
76
|
-
|
77
|
-
logger = SemanticLogger[Rails]
|
78
|
-
logger.warn(
|
79
|
-
"Rails Error: Unable to access log file. Please ensure that #{path} exists and is chmod 0666. " \
|
80
|
-
'The log level has been raised to WARN and the output directed to STDERR until the problem is fixed.',
|
81
|
-
exc
|
82
|
-
)
|
83
|
-
logger
|
84
|
-
end
|
85
|
-
|
86
87
|
# Replace Rails loggers
|
87
88
|
%i[active_record action_controller action_mailer action_view].each do |name|
|
88
89
|
ActiveSupport.on_load(name) { include SemanticLogger::Loggable }
|
89
90
|
end
|
90
|
-
ActiveSupport.on_load(:action_cable) { self.logger = SemanticLogger[
|
91
|
+
ActiveSupport.on_load(:action_cable) { self.logger = SemanticLogger["ActionCable"] }
|
91
92
|
end
|
92
93
|
|
93
94
|
# Before any initializers run, but after the gems have been loaded
|
@@ -100,18 +101,18 @@ module RailsSemanticLogger
|
|
100
101
|
end
|
101
102
|
|
102
103
|
# Replace the Mongo Loggers
|
103
|
-
Mongoid.logger
|
104
|
-
Moped.logger
|
105
|
-
Mongo::Logger.logger
|
104
|
+
Mongoid.logger = SemanticLogger[Mongoid] if defined?(Mongoid)
|
105
|
+
Moped.logger = SemanticLogger[Moped] if defined?(Moped)
|
106
|
+
Mongo::Logger.logger = SemanticLogger[Mongo] if defined?(Mongo::Logger)
|
106
107
|
|
107
108
|
# Replace the Resque Logger
|
108
|
-
Resque.logger
|
109
|
+
Resque.logger = SemanticLogger[Resque] if defined?(Resque) && Resque.respond_to?(:logger)
|
109
110
|
|
110
111
|
# Replace the Sidekiq logger
|
111
|
-
Sidekiq.logger
|
112
|
+
Sidekiq.logger = SemanticLogger[Sidekiq] if defined?(Sidekiq)
|
112
113
|
|
113
114
|
# Replace the Sidetiq logger
|
114
|
-
Sidetiq.logger
|
115
|
+
Sidetiq.logger = SemanticLogger[Sidetiq] if defined?(Sidetiq)
|
115
116
|
|
116
117
|
# Replace the DelayedJob logger
|
117
118
|
if defined?(Delayed::Worker)
|
@@ -129,17 +130,28 @@ module RailsSemanticLogger
|
|
129
130
|
Bugsnag.configure { |config| config.logger = SemanticLogger[Bugsnag] } if defined?(Bugsnag)
|
130
131
|
|
131
132
|
# Rails Patches
|
132
|
-
require(
|
133
|
-
require(
|
134
|
-
require(
|
135
|
-
|
136
|
-
|
137
|
-
|
133
|
+
require("rails_semantic_logger/extensions/action_cable/tagged_logger_proxy") if defined?(ActionCable)
|
134
|
+
require("rails_semantic_logger/extensions/action_controller/live") if defined?(ActionController::Live)
|
135
|
+
require("rails_semantic_logger/extensions/action_dispatch/debug_exceptions") if defined?(ActionDispatch::DebugExceptions)
|
136
|
+
if defined?(ActionView::StreamingTemplateRenderer::Body)
|
137
|
+
require("rails_semantic_logger/extensions/action_view/streaming_template_renderer")
|
138
|
+
end
|
139
|
+
require("rails_semantic_logger/extensions/active_job/logging") if defined?(ActiveJob)
|
140
|
+
require("rails_semantic_logger/extensions/active_model_serializers/logging") if defined?(ActiveModelSerializers)
|
138
141
|
|
139
142
|
if config.rails_semantic_logger.semantic
|
143
|
+
# Active Job
|
144
|
+
if defined?(::ActiveJob)
|
145
|
+
RailsSemanticLogger.swap_subscriber(
|
146
|
+
::ActiveJob::Logging::LogSubscriber,
|
147
|
+
RailsSemanticLogger::ActiveJob::LogSubscriber,
|
148
|
+
:active_job
|
149
|
+
)
|
150
|
+
end
|
151
|
+
|
140
152
|
# Active Record
|
141
153
|
if defined?(::ActiveRecord)
|
142
|
-
require
|
154
|
+
require "active_record/log_subscriber"
|
143
155
|
|
144
156
|
RailsSemanticLogger.swap_subscriber(
|
145
157
|
::ActiveRecord::LogSubscriber,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# Patch ActiveJob logger
|
2
|
-
require
|
2
|
+
require "active_job/logging"
|
3
3
|
|
4
4
|
module ActiveJob
|
5
5
|
module Logging
|
@@ -10,126 +10,5 @@ module ActiveJob
|
|
10
10
|
def tag_logger(*tags, &block)
|
11
11
|
logger.tagged(*tags, &block)
|
12
12
|
end
|
13
|
-
|
14
|
-
class LogSubscriber < ActiveSupport::LogSubscriber
|
15
|
-
def enqueue(event)
|
16
|
-
log_with_formatter event: event do |fmt|
|
17
|
-
"Enqueued #{fmt.job_info}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def enqueue_at(event)
|
22
|
-
log_with_formatter event: event do |fmt|
|
23
|
-
"Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def perform_start(event)
|
28
|
-
log_with_formatter event: event do |fmt|
|
29
|
-
"Performing #{fmt.job_info}"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def perform(event)
|
34
|
-
ex = event.payload[:exception_object]
|
35
|
-
if ex
|
36
|
-
logger.error ex
|
37
|
-
else
|
38
|
-
log_with_formatter event: event, log_duration: true do |fmt|
|
39
|
-
"Performed #{fmt.job_info} in #{event.duration.round(2)}ms"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
private
|
45
|
-
|
46
|
-
class EventFormatter
|
47
|
-
def initialize(event:, log_duration: false)
|
48
|
-
@event = event
|
49
|
-
@log_duration = log_duration
|
50
|
-
end
|
51
|
-
|
52
|
-
def job_info
|
53
|
-
"#{job.class.name} (Job ID: #{job.job_id}) to #{queue_name}"
|
54
|
-
end
|
55
|
-
|
56
|
-
def payload
|
57
|
-
{}.tap do |h|
|
58
|
-
h[:event_name] = event.name
|
59
|
-
h[:adapter] = adapter_name
|
60
|
-
h[:queue] = job.queue_name
|
61
|
-
h[:job_class] = job.class.name
|
62
|
-
h[:job_id] = job.job_id
|
63
|
-
h[:provider_job_id] = job.try(:provider_job_id) # Not available in Rails 4.2
|
64
|
-
h[:duration] = event.duration.round(2) if log_duration?
|
65
|
-
h[:arguments] = formatted_args
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def queue_name
|
70
|
-
adapter_name + "(#{job.queue_name})"
|
71
|
-
end
|
72
|
-
|
73
|
-
def scheduled_at
|
74
|
-
Time.at(event.payload[:job].scheduled_at).utc
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
attr_reader :event
|
80
|
-
|
81
|
-
def job
|
82
|
-
event.payload[:job]
|
83
|
-
end
|
84
|
-
|
85
|
-
def adapter_name
|
86
|
-
event.payload[:adapter].class.name.demodulize.remove('Adapter')
|
87
|
-
end
|
88
|
-
|
89
|
-
def formatted_args
|
90
|
-
JSON.pretty_generate(job.arguments.map { |arg| format(arg) })
|
91
|
-
end
|
92
|
-
|
93
|
-
def format(arg)
|
94
|
-
case arg
|
95
|
-
when Hash
|
96
|
-
arg.transform_values { |value| format(value) }
|
97
|
-
when Array
|
98
|
-
arg.map { |value| format(value) }
|
99
|
-
when GlobalID::Identification
|
100
|
-
begin
|
101
|
-
arg.to_global_id
|
102
|
-
rescue StandardError
|
103
|
-
arg
|
104
|
-
end
|
105
|
-
else
|
106
|
-
arg
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def log_duration?
|
111
|
-
@log_duration
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def log_with_formatter(**kw_args)
|
116
|
-
fmt = EventFormatter.new(**kw_args)
|
117
|
-
msg = yield fmt
|
118
|
-
logger.info msg, fmt.payload
|
119
|
-
end
|
120
|
-
|
121
|
-
def logger
|
122
|
-
ActiveJob::Base.logger
|
123
|
-
end
|
124
|
-
end
|
125
13
|
end
|
126
14
|
end
|
127
|
-
|
128
|
-
if defined?(ActiveSupport::Notifications)
|
129
|
-
ActiveSupport::Notifications.unsubscribe('perform_start.active_job')
|
130
|
-
ActiveSupport::Notifications.unsubscribe('perform.active_job')
|
131
|
-
ActiveSupport::Notifications.unsubscribe('enqueue_at.active_job')
|
132
|
-
ActiveSupport::Notifications.unsubscribe('enqueue.active_job')
|
133
|
-
|
134
|
-
ActiveJob::Logging::LogSubscriber.attach_to :active_job
|
135
|
-
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,43 +1,43 @@
|
|
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.4
|
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: 2020-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '3.2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '3.2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: semantic_logger
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/rails_semantic_logger.rb
|
66
66
|
- lib/rails_semantic_logger/action_controller/log_subscriber.rb
|
67
67
|
- lib/rails_semantic_logger/action_view/log_subscriber.rb
|
68
|
+
- lib/rails_semantic_logger/active_job/log_subscriber.rb
|
68
69
|
- lib/rails_semantic_logger/active_record/log_subscriber.rb
|
69
70
|
- lib/rails_semantic_logger/delayed_job/plugin.rb
|
70
71
|
- lib/rails_semantic_logger/engine.rb
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
- !ruby/object:Gem::Version
|
98
99
|
version: '0'
|
99
100
|
requirements: []
|
100
|
-
rubygems_version: 3.0.
|
101
|
+
rubygems_version: 3.0.8
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: Feature rich logging framework that replaces the Rails logger.
|