scout_apm_logging 0.0.12 → 0.0.13
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/CHANGELOG.md +5 -0
- data/lib/scout_apm/logging/loggers/capture.rb +5 -4
- data/lib/scout_apm/logging/loggers/patches/rails_logger.rb +17 -0
- data/lib/scout_apm/logging/loggers/proxy.rb +22 -5
- data/lib/scout_apm/logging/loggers/swaps/rails.rb +4 -12
- data/lib/scout_apm/logging/loggers/swaps/scout.rb +2 -10
- data/lib/scout_apm/logging/loggers/swaps/sidekiq.rb +2 -6
- data/lib/scout_apm/logging/version.rb +1 -1
- data/lib/scout_apm_logging.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd453a461cde33d8b0dd69cf25180bd88aa1c29d7576001ac2605fd6e2eab95b
|
4
|
+
data.tar.gz: 86fcb8e29e7506ba5abc0a0961c0260c8a3c5695a04761c4f33bda002efaa201
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43ce974c35e2544f4870bebfdaa580dcb535f96d9905954df47be5afb75d3471ab12ef6bbda4c79605e83daa777fe15e8604d763ac99db616841b0acc82ab244
|
7
|
+
data.tar.gz: '09f7492dc86c28b91e38f340b2aad44b3fbe0cb1689f0e50bc814aa4dee78257f96417377c59b884ad147035576ed80dcaea73d9ee3a97e7429d5d94b114ed10'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 0.0.13
|
2
|
+
* Add ability to handle other libraries setting the Rails logger.
|
3
|
+
* Overwrite comparability methods on the proxy class. Have proxy class inherit from Object again.
|
4
|
+
* Clone original log instances.
|
5
|
+
|
1
6
|
## 0.0.12
|
2
7
|
* Prevent certain attributes from being changed on created FileLogger.
|
3
8
|
* Update proxy class to inherit from BasicObject to relay class comparison methods
|
@@ -42,10 +42,11 @@ module ScoutApm
|
|
42
42
|
Utils.ensure_directory_exists(context.config.value('logs_proxy_log_dir'))
|
43
43
|
end
|
44
44
|
|
45
|
-
def add_logging_patches!
|
45
|
+
def add_logging_patches! # rubocop:disable Metrics/AbcSize
|
46
|
+
require_relative './patches/rails_logger' unless ::Rails.logger.respond_to?(:broadcasts)
|
46
47
|
# We can't swap out the logger similar to that of Rails and Sidekiq, as
|
47
48
|
# the TaggedLogging logger is dynamically generated.
|
48
|
-
return unless Rails.logger.respond_to?(:tagged)
|
49
|
+
return unless ::Rails.logger.respond_to?(:tagged)
|
49
50
|
|
50
51
|
::ActiveSupport::TaggedLogging.prepend(Patches::TaggedLogging)
|
51
52
|
|
@@ -53,9 +54,9 @@ module ScoutApm
|
|
53
54
|
# This appears to be an issue in Ruby 2.7 with the broadcast logger.
|
54
55
|
ruby_version = Gem::Version.new(RUBY_VERSION)
|
55
56
|
isruby27 = (ruby_version >= Gem::Version.new('2.7') && ruby_version < Gem::Version.new('3.0'))
|
56
|
-
return unless isruby27 && Rails.logger.respond_to?(:broadcasts)
|
57
|
+
return unless isruby27 && ::Rails.logger.respond_to?(:broadcasts)
|
57
58
|
|
58
|
-
Rails.logger.broadcasts.each do |logger|
|
59
|
+
::Rails.logger.broadcasts.each do |logger|
|
59
60
|
logger.extend ::ActiveSupport::TaggedLogging
|
60
61
|
end
|
61
62
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# A patch to Rails to allow swapping out the logger for the held logger in the proxy.
|
4
|
+
module Rails
|
5
|
+
class << self
|
6
|
+
def logger=(new_logger)
|
7
|
+
@logger.tap do |rails_logger|
|
8
|
+
if rails_logger.respond_to?(:is_scout_proxy_logger?)
|
9
|
+
old_logger = rails_logger.instance_variable_get(:@loggers).first
|
10
|
+
rails_logger.swap_scout_loggers!(old_logger, new_logger)
|
11
|
+
else
|
12
|
+
@logger = new_logger
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -4,9 +4,7 @@ module ScoutApm
|
|
4
4
|
module Logging
|
5
5
|
module Loggers
|
6
6
|
# Holds both the original application logger and the new one. Relays commands to both.
|
7
|
-
class Proxy
|
8
|
-
include ::Kernel
|
9
|
-
|
7
|
+
class Proxy
|
10
8
|
def self.create_with_loggers(*loggers)
|
11
9
|
new.tap do |proxy_logger|
|
12
10
|
loggers.each { |logger| proxy_logger.add_scout_loggers(logger) }
|
@@ -21,12 +19,19 @@ module ScoutApm
|
|
21
19
|
@loggers << logger
|
22
20
|
end
|
23
21
|
|
24
|
-
def remove_scout_loggers(logger)
|
22
|
+
def remove_scout_loggers!(logger)
|
25
23
|
@loggers.reject! { |inst_log| inst_log == logger }
|
26
24
|
|
27
25
|
@loggers
|
28
26
|
end
|
29
27
|
|
28
|
+
def swap_scout_loggers!(old_logger, new_logger)
|
29
|
+
logger_index = @loggers.index(old_logger)
|
30
|
+
return unless logger_index
|
31
|
+
|
32
|
+
@loggers[logger_index] = new_logger
|
33
|
+
end
|
34
|
+
|
30
35
|
# We don't want other libraries to change the formatter of the logger we create.
|
31
36
|
def formatter=(formatter)
|
32
37
|
@loggers.first.formatter = formatter
|
@@ -38,8 +43,20 @@ module ScoutApm
|
|
38
43
|
@loggers.first.level = level
|
39
44
|
end
|
40
45
|
|
46
|
+
def is_a?(klass)
|
47
|
+
@loggers.first.is_a?(klass)
|
48
|
+
end
|
49
|
+
|
50
|
+
def kind_of?(klass)
|
51
|
+
@loggers.first.is_a?(klass)
|
52
|
+
end
|
53
|
+
|
54
|
+
def instance_of?(klass)
|
55
|
+
@loggers.first.instance_of?(klass)
|
56
|
+
end
|
57
|
+
|
41
58
|
def class
|
42
|
-
|
59
|
+
@loggers.first.class
|
43
60
|
end
|
44
61
|
|
45
62
|
def is_scout_proxy_logger?
|
@@ -19,8 +19,10 @@ module ScoutApm
|
|
19
19
|
def update_logger!
|
20
20
|
# In Rails 7.1, broadcast logger was added which allows sinking to multiple IO devices.
|
21
21
|
if defined?(::ActiveSupport::BroadcastLogger) && log_instance.is_a?(::ActiveSupport::BroadcastLogger)
|
22
|
+
context.logger.debug('Rails Broadcast logger detected. Adding new logger to broadcast.')
|
22
23
|
add_logger_to_broadcast!
|
23
24
|
else
|
25
|
+
context.logger.debug("Swapping in Proxy for current Rails logger: #{log_instance.class}.")
|
24
26
|
swap_in_proxy_logger!
|
25
27
|
end
|
26
28
|
|
@@ -37,18 +39,8 @@ module ScoutApm
|
|
37
39
|
@new_file_logger ||= Loggers::Logger.new(context, log_instance).create_logger!
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
# We can use the previous logdev. log_device will continuously call write
|
43
|
-
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
44
|
-
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
45
|
-
# Log device holds the configurations around shifting too.
|
46
|
-
original_logdevice = log_instance.instance_variable_get(:@logdev)
|
47
|
-
|
48
|
-
::Logger.new(original_logdevice).tap do |logger|
|
49
|
-
logger.level = log_instance.level
|
50
|
-
logger.formatter = log_instance.formatter
|
51
|
-
|
42
|
+
def original_logger
|
43
|
+
@original_logger = log_instance.clone.tap do |logger|
|
52
44
|
if ::Rails.env.development? && $stdout.tty? && $stderr.tty?
|
53
45
|
next if ::ActiveSupport::Logger.respond_to?(:logger_outputs_to?) && ::ActiveSupport::Logger.logger_outputs_to?(
|
54
46
|
logger, $stdout, $stderr
|
@@ -17,6 +17,7 @@ module ScoutApm
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def update_logger!
|
20
|
+
context.logger.debug('Swapping in Proxy for Test logger.')
|
20
21
|
swap_in_proxy_logger!
|
21
22
|
|
22
23
|
new_log_location
|
@@ -34,16 +35,7 @@ module ScoutApm
|
|
34
35
|
|
35
36
|
# Eseentially creates the original logger.
|
36
37
|
def original_logger
|
37
|
-
|
38
|
-
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
39
|
-
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
40
|
-
# Log device holds the configurations around shifting too.
|
41
|
-
original_logdevice = log_instance.instance_variable_get(:@logdev)
|
42
|
-
|
43
|
-
::Logger.new(original_logdevice).tap do |logger|
|
44
|
-
logger.level = log_instance.level
|
45
|
-
logger.formatter = log_instance.formatter
|
46
|
-
end
|
38
|
+
@original_logger = log_instance.clone
|
47
39
|
end
|
48
40
|
|
49
41
|
def new_log_location
|
@@ -17,6 +17,7 @@ module ScoutApm
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def update_logger!
|
20
|
+
context.logger.debug("Swapping in Proxy for current Sidekiq logger: #{log_instance.class}.")
|
20
21
|
swap_in_proxy_logger!
|
21
22
|
|
22
23
|
new_log_location
|
@@ -38,12 +39,7 @@ module ScoutApm
|
|
38
39
|
# through the devices until the logdev (@dev) is an IO device other than logdev:
|
39
40
|
# https://github.com/ruby/ruby/blob/master/lib/logger/log_device.rb#L42
|
40
41
|
# Log device holds the configurations around shifting too.
|
41
|
-
|
42
|
-
|
43
|
-
::Logger.new(original_logdevice).tap do |logger|
|
44
|
-
logger.level = log_instance.level
|
45
|
-
logger.formatter = log_instance.formatter
|
46
|
-
end
|
42
|
+
@original_logger = log_instance.clone
|
47
43
|
end
|
48
44
|
|
49
45
|
def new_log_location
|
data/lib/scout_apm_logging.rb
CHANGED
@@ -18,7 +18,7 @@ module ScoutApm
|
|
18
18
|
if defined?(Rails) && defined?(Rails::Railtie)
|
19
19
|
# If we are in a Rails environment, setup the monitor daemon manager.
|
20
20
|
class RailTie < ::Rails::Railtie
|
21
|
-
initializer 'scout_apm_logging.monitor' do
|
21
|
+
initializer 'scout_apm_logging.monitor', after: :initialize_logger, before: :initialize_cache do
|
22
22
|
context = ScoutApm::Logging::MonitorManager.instance.context
|
23
23
|
|
24
24
|
Loggers::Capture.new(context).setup!
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scout_apm_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scout APM
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: scout_apm
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/scout_apm/logging/loggers/capture.rb
|
90
90
|
- lib/scout_apm/logging/loggers/formatter.rb
|
91
91
|
- lib/scout_apm/logging/loggers/logger.rb
|
92
|
+
- lib/scout_apm/logging/loggers/patches/rails_logger.rb
|
92
93
|
- lib/scout_apm/logging/loggers/patches/tagged_logging.rb
|
93
94
|
- lib/scout_apm/logging/loggers/proxy.rb
|
94
95
|
- lib/scout_apm/logging/loggers/swaps/rails.rb
|