logjam_agent 0.35.0 → 0.36.0

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: c22b624762a595ee627fba548bc5e41a3ac3a0180fdc8fa067969138963dd116
4
- data.tar.gz: ee6d22ec9272fea8c786e16ca7088c7711b258bf1e6a7dd665270a5e5b9a5b62
3
+ metadata.gz: 238a6d18a9fdd1fdf660314a3e3de7706e658e08ab304aa4874d7e73985c787d
4
+ data.tar.gz: 208a910c0abadf9572d1e9f872eee8b90c8d3706e9a59bf8c550d64cb1144281
5
5
  SHA512:
6
- metadata.gz: aac5ad227a70fa16e232c01abb6cea2b4852d717a7b81dc681a137bbe91d71f3cf7fc23901fc280a6db65eece15ac6c1608bf22e140351a8436020ef80a7b1db
7
- data.tar.gz: d63f3d7758b328f01b2f4855c2dc9ef51cd1c1ed1152c900c46a942d389d38915d554ee732255c0ab946118209afbf528e47186a0d9825e1dfa351363615c3ab
6
+ metadata.gz: f1852e9eec5abceed5a8ddd8977188a1a86ae415c6883e01db30d5471e0d20def84c07ad1eadb947e1809860c61e72010ad8dbb2aaaf92c6c842f3f3029708e5
7
+ data.tar.gz: 5565c68259a98b4561240cc3f2a1bd1233598efa3aeca555db6c78183d0064376e5d3f1acfd13469bee5654e8565bee217843f7bd965b49d93a586662db4d1f3
data/README.md CHANGED
@@ -62,6 +62,12 @@ module LogjamAgent
62
62
  # to debug asset request handling.
63
63
  self.ignore_asset_requests = Rails.env.development?
64
64
 
65
+ # Configure a list of URL patterns for which no data should be sent
66
+ # to logjam and nothing should be sent to the log device. Please not
67
+ # that the log lines will still show up in dev mode on the console.
68
+ # Defaults to the empty list.
69
+ # self.ignored_request_urls = [%r{/_system/}]
70
+
65
71
  # Disable ActiveSupport::Notifications (and thereby logging) of ActionView
66
72
  # render events. Defaults to false.
67
73
  # self.ignore_render_events = Rails.env.production?
@@ -57,6 +57,7 @@ module LogjamAgent
57
57
  end
58
58
  end
59
59
  log_to_log_device = LogjamAgent.log_to_log_device?(severity, message)
60
+ log_to_log_device = false if request && request.ignored?
60
61
  attributes = formatter.render_attributes
61
62
  message = "[#{attributes}] #{message}" if attributes
62
63
  time = Time.now
@@ -11,6 +11,7 @@ module LogjamAgent
11
11
  @hostname = LogjamAgent.hostname
12
12
  @asset_prefix = Rails.application.config.assets.prefix rescue "---"
13
13
  @ignore_asset_requests = LogjamAgent.ignore_asset_requests
14
+ @ignored_request_urls = LogjamAgent.ignored_request_urls
14
15
  end
15
16
 
16
17
  def call(env)
@@ -88,6 +89,12 @@ module LogjamAgent
88
89
  false
89
90
  end
90
91
 
92
+ def ignored_request_url?(path)
93
+ @ignored_request_urls.any?{|url_pattern| path =~ url_pattern}
94
+ rescue
95
+ false
96
+ end
97
+
91
98
  def before_dispatch(request, env, start_time, wait_time_ms)
92
99
  logger.formatter.reset_attributes if logger.formatter.respond_to?(:reset_attributes)
93
100
  TimeBandits.reset
@@ -96,7 +103,8 @@ module LogjamAgent
96
103
  path = request.filtered_path
97
104
 
98
105
  logjam_request = LogjamAgent.request
99
- logjam_request.ignore! if ignored_asset_request?(path)
106
+ logjam_request.ignore!(:asset) if ignored_asset_request?(path)
107
+ logjam_request.ignore!(:url) if ignored_request_url?(path)
100
108
 
101
109
  logjam_request.start_time = start_time
102
110
  logjam_fields = logjam_request.fields
@@ -111,7 +119,7 @@ module LogjamAgent
111
119
  logjam_fields.merge!(:ip => ip, :host => @hostname)
112
120
  logjam_fields.merge!(extract_request_info(request))
113
121
 
114
- info "Started #{request.request_method} \"#{path}\" for #{ip} at #{start_time.to_default_s}" unless logjam_request.ignored?
122
+ info "Started #{request.request_method} \"#{path}\" for #{ip} at #{start_time.to_default_s}" unless logjam_request.ignored?(:asset)
115
123
  if spoofed
116
124
  error spoofed
117
125
  raise spoofed
@@ -140,7 +148,7 @@ module LogjamAgent
140
148
 
141
149
  message = "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in %.1fms" % run_time_ms
142
150
  message << " (#{additions.join(' | ')})" unless additions.blank?
143
- info message unless logjam_request.ignored?
151
+ info message unless logjam_request.ignored?(:asset)
144
152
 
145
153
  ActiveSupport::LogSubscriber.flush_all!
146
154
  request_info = { :total_time => run_time_ms, :code => status }
@@ -47,12 +47,12 @@ module LogjamAgent
47
47
  @fields[:started_ms] = start_time.tv_sec * 1000 + start_time.tv_usec / 1000
48
48
  end
49
49
 
50
- def ignore!
51
- @ignored = true
50
+ def ignore!(reason = nil)
51
+ @ignored = reason || :unknown
52
52
  end
53
53
 
54
- def ignored?
55
- @ignored
54
+ def ignored?(reason = nil)
55
+ reason ? @ignored == reason : @ignored
56
56
  end
57
57
 
58
58
  def id
@@ -2,9 +2,12 @@ module LogjamAgent
2
2
  module SelectiveLogging
3
3
  extend self
4
4
 
5
+ mattr_accessor :selective_logging_enabled
6
+ self.selective_logging_enabled = true
7
+
5
8
  def logjam_only
6
9
  old_selector = logjam_log_selector
7
- self.logjam_log_selector = :logjam_only
10
+ self.logjam_log_selector = :logjam_only if selective_logging_enabled
8
11
  yield
9
12
  ensure
10
13
  self.logjam_log_selector = old_selector
@@ -12,7 +15,7 @@ module LogjamAgent
12
15
 
13
16
  def logdevice_only
14
17
  old_selector = logjam_log_selector
15
- self.logjam_log_selector = :logdevice_only
18
+ self.logjam_log_selector = :logdevice_only if selective_logging_enabled
16
19
  yield
17
20
  ensure
18
21
  self.logjam_log_selector = old_selector
@@ -1,3 +1,3 @@
1
1
  module LogjamAgent
2
- VERSION = "0.35.0"
2
+ VERSION = "0.36.0"
3
3
  end
data/lib/logjam_agent.rb CHANGED
@@ -133,6 +133,9 @@ module LogjamAgent
133
133
  mattr_accessor :exception_matcher
134
134
  self.exception_matcher = nil
135
135
 
136
+ mattr_accessor :ignored_request_urls
137
+ self.ignored_request_urls = []
138
+
136
139
  mattr_accessor :ignore_asset_requests
137
140
  self.ignore_asset_requests = false
138
141
 
@@ -22,11 +22,12 @@ module LogjamAgent
22
22
 
23
23
  def teardown
24
24
  LogjamAgent.request = nil
25
+ LogjamAgent.selective_logging_enabled = true
25
26
  end
26
27
 
27
28
  def test_normal_logging_adds_line_to_request_and_logdevice
28
- assert !LogjamAgent.logjam_only?
29
- assert !LogjamAgent.logdevice_only?
29
+ refute LogjamAgent.logjam_only?
30
+ refute LogjamAgent.logdevice_only?
30
31
  @logger.info("normal")
31
32
  assert_equal 1, @lines.size
32
33
  assert_equal "normal", @lines.first.last
@@ -37,7 +38,7 @@ module LogjamAgent
37
38
  def test_logjam_only_logging_adds_line_to_request_but_not_to_logdevice
38
39
  LogjamAgent.logjam_only do
39
40
  assert LogjamAgent.logjam_only?
40
- assert !LogjamAgent.logdevice_only?
41
+ refute LogjamAgent.logdevice_only?
41
42
  @logger.info("logjam_only")
42
43
  end
43
44
  assert_equal 1, @lines.size
@@ -47,7 +48,7 @@ module LogjamAgent
47
48
 
48
49
  def test_logdevice_only_logging_adds_line_to_logdevice_but_not_to_request
49
50
  LogjamAgent.logdevice_only do
50
- assert !LogjamAgent.logjam_only?
51
+ refute LogjamAgent.logjam_only?
51
52
  assert LogjamAgent.logdevice_only?
52
53
  @logger.info("logdevice_only")
53
54
  end
@@ -55,5 +56,15 @@ module LogjamAgent
55
56
  assert_equal 1, @device.lines.size
56
57
  assert_match(/logdevice_only\n/, @device.lines.first)
57
58
  end
59
+
60
+ def test_select_logging_can_be_globally_disabled
61
+ LogjamAgent.selective_logging_enabled = false
62
+ LogjamAgent.logdevice_only do
63
+ refute LogjamAgent.logdevice_only?
64
+ end
65
+ LogjamAgent.logjam_only do
66
+ refute LogjamAgent.logjam_only?
67
+ end
68
+ end
58
69
  end
59
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logjam_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.0
4
+ version: 0.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Kaes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-17 00:00:00.000000000 Z
11
+ date: 2022-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake