scout_apm_logging 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a99a84cd9f8dd023b8717c81e5d80b17c99f5afb8c7e7edb6152193ef7fecdf
4
- data.tar.gz: b9d2e44b40adcb5f9acc13f6ef6d2176e79ed6b056f6e6d1e8f9f0359857ebf6
3
+ metadata.gz: a55380380a6a30ccfe38b8a7b117e02e2aa8c3ffc09a679f194c0b93ed1f4062
4
+ data.tar.gz: 0131aa6a8d6ed072553996fe58b5a4e3d1f1170e656dda3b8283bbad301f56e8
5
5
  SHA512:
6
- metadata.gz: 1f73329ada6fde049cf1ffe18ad2d43c0fa09158cffcc10e51c58f897d9cd40f1aa2636ee645e2b26d7a36204e082ca318c5281e8e32759aaac2b685a4ff5f32
7
- data.tar.gz: 664471524c4802ad23cfeee6299a56259d07e7a9a9d2fb241393202b4116946052f695982ada22c3060a39fca25f351ce6a90487e329283bc264749e6ee56738
6
+ metadata.gz: ddada293aa30a8c806e6ca1e7d318b5a2f412f990d2bd5e2eeb81e5ddd10d661a7362571c105d776f7c5adbeecd4d6adf788ba505c6d6b811f8824f30485550e
7
+ data.tar.gz: 825aba7b09c6075bcb0230b18b582eb37daa08d0c2eff45c781c73efa8a058dbae4498e1702e14438320a3bf618aae52d738b81aabfa7e87b825a1efed827da8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.0.6
2
+ * Ensure logger level is set back to the original.
3
+
4
+ ## 0.0.5
5
+ * Remove `msg` attribute after it has been moved to the log body to prevent duplication.
6
+
1
7
  ## 0.0.4
2
8
  * Fix memoizing of log attributes, which could lead to persistent attributes.
3
9
 
@@ -25,7 +25,7 @@ module ScoutApm
25
25
 
26
26
  FileLogger.new(determine_file_path, LOG_AGE, log_size).tap do |logger|
27
27
  # Ruby's Logger handles a lot of the coercion itself.
28
- logger.level = context.config.value('logs_capture_level')
28
+ logger.level = determined_log_level
29
29
  # Add our custom formatter to the logger.
30
30
  logger.formatter = Formatter.new
31
31
  end
@@ -55,6 +55,16 @@ module ScoutApm
55
55
 
56
56
  private
57
57
 
58
+ # This makes the assumption that the logs we capture should be
59
+ # at least that of the original logger level, and not lower, but can be
60
+ # configured to be a higher cutoff.
61
+ def determined_log_level
62
+ capture_level = context.config.value('logs_capture_level')
63
+ capture_value = ::Logger::Severity.const_get(capture_level.upcase)
64
+
65
+ [capture_value, log_instance.level].max
66
+ end
67
+
58
68
  def find_log_destination(logdev)
59
69
  dev = try(logdev, :filename) || try(logdev, :dev)
60
70
  if dev.is_a?(String)
@@ -46,6 +46,7 @@ module ScoutApm
46
46
  original_logdevice = log_instance.instance_variable_get(:@logdev)
47
47
 
48
48
  ::Logger.new(original_logdevice).tap do |logger|
49
+ logger.level = log_instance.level
49
50
  logger.formatter = log_instance.formatter
50
51
  end
51
52
  end
@@ -41,6 +41,7 @@ module ScoutApm
41
41
  original_logdevice = log_instance.instance_variable_get(:@logdev)
42
42
 
43
43
  ::Logger.new(original_logdevice).tap do |logger|
44
+ logger.level = log_instance.level
44
45
  logger.formatter = log_instance.formatter
45
46
  end
46
47
  end
@@ -41,6 +41,7 @@ module ScoutApm
41
41
  original_logdevice = log_instance.instance_variable_get(:@logdev)
42
42
 
43
43
  ::Logger.new(original_logdevice).tap do |logger|
44
+ logger.level = log_instance.level
44
45
  logger.formatter = log_instance.formatter
45
46
  end
46
47
  end
@@ -95,6 +95,8 @@ module ScoutApm
95
95
  - 'set(attributes["raw_bytes"], body)'
96
96
  # Replace the body with the log message.
97
97
  - 'set(body, attributes["msg"])'
98
+ # Remove the msg attribute.
99
+ - 'delete_key(attributes, "msg")'
98
100
  # Move service.name attribute to resource attribute.
99
101
  - 'set(resource.attributes["service.name"], attributes["service.name"])'
100
102
  batch:
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ScoutApm
4
4
  module Logging
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.6'
6
6
  end
7
7
  end
@@ -47,6 +47,7 @@ describe ScoutApm::Logging do
47
47
  expect(messages.count('[TEST] Some log')).to eq(1)
48
48
  expect(messages.count('[YIELD] Yield Test')).to eq(1)
49
49
  expect(messages.count('Another Log')).to eq(1)
50
+ expect(messages.count('Should not be captured')).to eq(0)
50
51
 
51
52
  log_locations = lines.map { |item| item['log_location'] }.compact
52
53
 
data/spec/rails/app.rb CHANGED
@@ -12,6 +12,7 @@ Rails.logger = ActiveSupport::TaggedLogging.new(Logger.new($stdout))
12
12
 
13
13
  class App < ::Rails::Application
14
14
  config.eager_load = false
15
+ config.log_level = :info
15
16
 
16
17
  routes.append do
17
18
  root to: 'root#index'
@@ -24,6 +25,8 @@ class RootController < ActionController::Base
24
25
  Rails.logger.tagged('TEST').info('Some log')
25
26
  Rails.logger.tagged('YIELD') { logger.info('Yield Test') }
26
27
  Rails.logger.info('Another Log')
28
+ Rails.logger.debug('Should not be captured')
29
+
27
30
  render plain: Rails.version
28
31
  end
29
32
  end
@@ -19,6 +19,7 @@ describe ScoutApm::Logging::Loggers::Capture do
19
19
  ENV['SCOUT_MONITOR_INTERVAL'] = '10'
20
20
  ENV['SCOUT_MONITOR_INTERVAL_DELAY'] = '10'
21
21
  ENV['SCOUT_LOGS_MONITOR'] = 'true'
22
+ ENV['SCOUT_LOGS_CAPTURE_LEVEL'] = 'debug'
22
23
 
23
24
  output_from_log = capture_stdout do
24
25
  context = ScoutApm::Logging::Context.new
@@ -26,7 +27,10 @@ describe ScoutApm::Logging::Loggers::Capture do
26
27
  conf = ScoutApm::Logging::Config.with_file(context, conf_file)
27
28
  context.config = conf
28
29
 
29
- TestLoggerWrapper.logger = ScoutTestLogger.new($stdout)
30
+ test_logger = ScoutTestLogger.new($stdout)
31
+ test_logger.level = 'INFO'
32
+
33
+ TestLoggerWrapper.logger = test_logger
30
34
 
31
35
  capture = ScoutApm::Logging::Loggers::Capture.new(context)
32
36
  capture.setup!
@@ -34,16 +38,22 @@ describe ScoutApm::Logging::Loggers::Capture do
34
38
  expect(TestLoggerWrapper.logger.class).to eq(ScoutApm::Logging::Loggers::Proxy)
35
39
 
36
40
  TestLoggerWrapper.logger.info('TEST')
41
+ TestLoggerWrapper.logger.debug('SHOULD NOT CAPTURE')
37
42
 
38
43
  log_path = File.join(context.config.value('logs_proxy_log_dir'), 'test.log')
39
44
  content = File.read(log_path)
40
45
  expect(content).to include('TEST')
41
46
 
47
+ # Shouldn't capture. While the log_capture_level was set to debug,
48
+ # the original logger instance had a higher log level of info.
49
+ expect(content).not_to include('SHOULD NOT CAPTURE')
50
+
42
51
  state_file = File.read(context.config.value('monitor_state_file'))
43
52
  state_data = JSON.parse(state_file)
44
53
  expect(state_data['logs_monitored']).to eq([log_path])
45
54
  end
46
55
 
47
56
  expect(output_from_log).to include('TEST')
57
+ expect(output_from_log).not_to include('SHOULD NOT CAPTURE')
48
58
  end
49
59
  end
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
4
+ version: 0.0.6
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-08-09 00:00:00.000000000 Z
11
+ date: 2024-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: scout_apm