logster 2.12.2 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +5 -0
  3. data/.streerc +2 -0
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +1 -1
  6. data/assets/javascript/{chunk.143.f61340b825c6a3bf6dbe.js → chunk.143.91d07e8cdd5c4b9e4731.js} +4 -4
  7. data/assets/javascript/{chunk.178.6d9ae01775c898e7b748.js → chunk.178.16d0c9057345120bdba1.js} +3 -3
  8. data/assets/javascript/client-app.js +1 -1
  9. data/client-app/package.json +1 -1
  10. data/client-app/preload-json-manager.rb +10 -17
  11. data/client-app/yarn.lock +22 -22
  12. data/lib/examples/sidekiq_logster_reporter.rb +5 -7
  13. data/lib/logster/base_store.rb +26 -22
  14. data/lib/logster/cache.rb +2 -1
  15. data/lib/logster/configuration.rb +3 -3
  16. data/lib/logster/defer_logger.rb +2 -4
  17. data/lib/logster/group.rb +17 -20
  18. data/lib/logster/ignore_pattern.rb +1 -2
  19. data/lib/logster/logger.rb +18 -16
  20. data/lib/logster/message.rb +53 -57
  21. data/lib/logster/middleware/debug_exceptions.rb +12 -10
  22. data/lib/logster/middleware/reporter.rb +17 -26
  23. data/lib/logster/middleware/viewer.rb +77 -97
  24. data/lib/logster/pattern.rb +4 -7
  25. data/lib/logster/rails/railtie.rb +10 -13
  26. data/lib/logster/redis_rate_limiter.rb +2 -7
  27. data/lib/logster/redis_store.rb +79 -99
  28. data/lib/logster/scheduler.rb +1 -5
  29. data/lib/logster/suppression_pattern.rb +7 -5
  30. data/lib/logster/version.rb +1 -1
  31. data/lib/logster/web.rb +1 -1
  32. data/lib/logster.rb +15 -17
  33. data/logster.gemspec +14 -14
  34. data/test/examples/test_sidekiq_reporter_example.rb +8 -9
  35. data/test/fake_data/generate.rb +14 -3
  36. data/test/logster/middleware/test_reporter.rb +9 -7
  37. data/test/logster/middleware/test_viewer.rb +117 -101
  38. data/test/logster/test_base_store.rb +79 -58
  39. data/test/logster/test_cache.rb +5 -11
  40. data/test/logster/test_defer_logger.rb +3 -3
  41. data/test/logster/test_group.rb +14 -18
  42. data/test/logster/test_ignore_pattern.rb +2 -3
  43. data/test/logster/test_logger.rb +14 -14
  44. data/test/logster/test_message.rb +29 -31
  45. data/test/logster/test_pattern.rb +7 -15
  46. data/test/logster/test_redis_rate_limiter.rb +35 -21
  47. data/test/logster/test_redis_store.rb +239 -151
  48. data/test/test_helper.rb +9 -9
  49. metadata +19 -4
@@ -1,12 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../test_helper'
4
- require 'rack'
5
- require 'logster/redis_store'
6
- require 'logster/middleware/viewer'
3
+ require_relative "../../test_helper"
4
+ require "rack"
5
+ require "logster/redis_store"
6
+ require "logster/middleware/viewer"
7
7
 
8
8
  class TestViewer < Minitest::Test
9
-
10
9
  class BrokenApp
11
10
  def call(env)
12
11
  [500, {}, ["broken"]]
@@ -43,21 +42,21 @@ class TestViewer < Minitest::Test
43
42
  end
44
43
 
45
44
  def test_search_raceguard_s
46
- response = request.post('/logsie/messages.json?search=searchkey')
45
+ response = request.post("/logsie/messages.json?search=searchkey")
47
46
  result = JSON.parse(response.body)
48
- assert_equal('searchkey', result['search'])
47
+ assert_equal("searchkey", result["search"])
49
48
  end
50
49
 
51
50
  def test_search_raceguard_sr
52
- response = request.post('/logsie/messages.json?search=/regex/&regex_search=true')
51
+ response = request.post("/logsie/messages.json?search=/regex/&regex_search=true")
53
52
  result = JSON.parse(response.body)
54
- assert_equal('/regex/', result['search'])
53
+ assert_equal("/regex/", result["search"])
55
54
  end
56
55
 
57
56
  def test_search_raceguard_f
58
57
  response = request.post("/logsie/messages.json?filter=0_1_2_3_4")
59
58
  result = JSON.parse(response.body)
60
- assert_equal([0, 1, 2, 3, 4], result['filter'])
59
+ assert_equal([0, 1, 2, 3, 4], result["filter"])
61
60
  end
62
61
 
63
62
  def test_search_does_not_respond_to_get_requests
@@ -67,7 +66,7 @@ class TestViewer < Minitest::Test
67
66
  end
68
67
 
69
68
  def test_regex_parse
70
- assert_equal(/hello/i, viewer.send(:parse_regex, '/hello/i'))
69
+ assert_equal(/hello/i, viewer.send(:parse_regex, "/hello/i"))
71
70
  end
72
71
 
73
72
  def test_settings_page_responds_with_json
@@ -108,9 +107,8 @@ class TestViewer < Minitest::Test
108
107
  def test_patterns_endpoint_doesnt_accept_GETs
109
108
  Logster.config.enable_custom_patterns_via_ui = true
110
109
 
111
- response = request.get("/logsie/patterns/suppression.json",
112
- params: { pattern: "patternfromuser" }
113
- )
110
+ response =
111
+ request.get("/logsie/patterns/suppression.json", params: { pattern: "patternfromuser" })
114
112
  assert_equal(405, response.status)
115
113
  assert_equal(0, Logster::SuppressionPattern.find_all.size)
116
114
  ensure
@@ -120,9 +118,8 @@ class TestViewer < Minitest::Test
120
118
  def test_patterns_endpoint_doesnt_work_when_its_disabled_from_config
121
119
  Logster.config.enable_custom_patterns_via_ui = false
122
120
 
123
- response = request.post("/logsie/patterns/suppression.json",
124
- params: { pattern: "patternfromuser" }
125
- )
121
+ response =
122
+ request.post("/logsie/patterns/suppression.json", params: { pattern: "patternfromuser" })
126
123
  assert_equal(403, response.status)
127
124
  assert_equal(0, Logster::SuppressionPattern.find_all.size)
128
125
  end
@@ -130,13 +127,10 @@ class TestViewer < Minitest::Test
130
127
  def test_patterns_endpoint_doesnt_work_with_undefined_set
131
128
  Logster.config.enable_custom_patterns_via_ui = true
132
129
 
133
- response = request.post("/logsie/patterns/weirdset.json",
134
- params: { pattern: "disallowedpattern" }
135
- )
130
+ response =
131
+ request.post("/logsie/patterns/weirdset.json", params: { pattern: "disallowedpattern" })
136
132
  assert_equal(404, response.status)
137
- Logster::Pattern.child_classes.each do |klass|
138
- assert_equal(0, klass.find_all.size)
139
- end
133
+ Logster::Pattern.child_classes.each { |klass| assert_equal(0, klass.find_all.size) }
140
134
  ensure
141
135
  Logster.config.enable_custom_patterns_via_ui = false
142
136
  end
@@ -144,9 +138,7 @@ class TestViewer < Minitest::Test
144
138
  def test_creating_patterns_works
145
139
  Logster.config.enable_custom_patterns_via_ui = true
146
140
 
147
- response = request.post("/logsie/patterns/suppression.json",
148
- params: { pattern: "newpattern" }
149
- )
141
+ response = request.post("/logsie/patterns/suppression.json", params: { pattern: "newpattern" })
150
142
  assert_equal(200, response.status)
151
143
  assert_equal(/newpattern/, Logster::SuppressionPattern.find_all.first)
152
144
 
@@ -163,24 +155,31 @@ class TestViewer < Minitest::Test
163
155
  Logster.store.report(Logger::INFO, "test", "apple orange")
164
156
  Logster.store.report(Logger::INFO, "test", "apples oranges")
165
157
 
166
- request.post("/logsie/patterns/suppression.json",
167
- params: { pattern: "apple" }
168
- )
158
+ request.post("/logsie/patterns/suppression.json", params: { pattern: "apple" })
169
159
  messages = Logster.store.latest
170
160
  assert_includes(messages.map(&:message), "apple orange")
171
161
  assert_includes(messages.map(&:message), "apples oranges")
172
162
  assert_includes(messages.map(&:message), "non-matching message")
173
163
 
174
- request.post("/logsie/patterns/suppression.json",
175
- params: { pattern: "orange", retroactive: true }
164
+ request.post(
165
+ "/logsie/patterns/suppression.json",
166
+ params: {
167
+ pattern: "orange",
168
+ retroactive: true,
169
+ },
176
170
  )
177
171
  messages = Logster.store.latest
178
172
  assert_equal(1, messages.size)
179
173
  assert_equal("non-matching message", messages.first.message)
180
174
 
181
- response = request.post("/logsie/patterns/suppression.json",
182
- params: { pattern: "doesntmatchanything", retroactive: true }
183
- )
175
+ response =
176
+ request.post(
177
+ "/logsie/patterns/suppression.json",
178
+ params: {
179
+ pattern: "doesntmatchanything",
180
+ retroactive: true,
181
+ },
182
+ )
184
183
  # assert no error occures if it doesn't delete anything retroactively
185
184
  assert_equal(200, response.status)
186
185
  ensure
@@ -190,9 +189,14 @@ class TestViewer < Minitest::Test
190
189
  def test_modifying_patterns_returns_404_for_non_existing_patterns
191
190
  Logster.config.enable_custom_patterns_via_ui = true
192
191
 
193
- response = request.put("/logsie/patterns/suppression.json",
194
- params: { new_pattern: "doesntexists", pattern: "doesntexisttoo" }
195
- )
192
+ response =
193
+ request.put(
194
+ "/logsie/patterns/suppression.json",
195
+ params: {
196
+ new_pattern: "doesntexists",
197
+ pattern: "doesntexisttoo",
198
+ },
199
+ )
196
200
 
197
201
  assert_equal(404, response.status)
198
202
  assert_equal(0, Logster::SuppressionPattern.find_all.size)
@@ -204,9 +208,14 @@ class TestViewer < Minitest::Test
204
208
  Logster.config.enable_custom_patterns_via_ui = true
205
209
  Logster::SuppressionPattern.new("goodcitizen").save
206
210
 
207
- response = request.put("/logsie/patterns/suppression.json",
208
- params: { new_pattern: "", pattern: "goodcitizen" }
209
- )
211
+ response =
212
+ request.put(
213
+ "/logsie/patterns/suppression.json",
214
+ params: {
215
+ new_pattern: "",
216
+ pattern: "goodcitizen",
217
+ },
218
+ )
210
219
 
211
220
  assert_equal(400, response.status)
212
221
  patterns = Logster::SuppressionPattern.find_all
@@ -221,9 +230,14 @@ class TestViewer < Minitest::Test
221
230
  Logster::SuppressionPattern.new("oldpattern").save
222
231
  Logster::SuppressionPattern.new("notgoinganywhere").save
223
232
 
224
- response = request.put("/logsie/patterns/suppression.json",
225
- params: { pattern: "oldpattern", new_pattern: "brandnewpattern" }
226
- )
233
+ response =
234
+ request.put(
235
+ "/logsie/patterns/suppression.json",
236
+ params: {
237
+ pattern: "oldpattern",
238
+ new_pattern: "brandnewpattern",
239
+ },
240
+ )
227
241
 
228
242
  assert_equal(200, response.status)
229
243
  patterns = Logster::SuppressionPattern.find_all
@@ -242,14 +256,12 @@ class TestViewer < Minitest::Test
242
256
  Logster::SuppressionPattern.new("tobedeleted").save
243
257
  Logster::SuppressionPattern.new("notgoinganywhere").save
244
258
 
245
- response = request.delete("/logsie/patterns/suppression.json",
246
- params: { pattern: "tobedeleted" }
247
- )
259
+ response =
260
+ request.delete("/logsie/patterns/suppression.json", params: { pattern: "tobedeleted" })
248
261
  assert_equal(200, response.status)
249
262
 
250
- response = request.delete("/logsie/patterns/suppression.json",
251
- params: { pattern: "doesntexistanymore" }
252
- )
263
+ response =
264
+ request.delete("/logsie/patterns/suppression.json", params: { pattern: "doesntexistanymore" })
253
265
  assert_equal(404, response.status)
254
266
 
255
267
  patterns = Logster::SuppressionPattern.find_all
@@ -289,14 +301,12 @@ class TestViewer < Minitest::Test
289
301
  assert_equal("1", suppression.find { |p| p["value"] == "/whatever store/" }["count"])
290
302
  assert_equal("1", suppression.find { |p| p["value"] == "/custom pattern/" }["count"])
291
303
 
292
- response = request.put("/logsie/reset-count.json",
293
- params: { pattern: "/whatever store/", hard: true }
294
- )
304
+ response =
305
+ request.put("/logsie/reset-count.json", params: { pattern: "/whatever store/", hard: true })
295
306
  assert_equal(200, response.status)
296
307
 
297
- response = request.put("/logsie/reset-count.json",
298
- params: { pattern: "/custom pattern/", hard: false }
299
- )
308
+ response =
309
+ request.put("/logsie/reset-count.json", params: { pattern: "/custom pattern/", hard: false })
300
310
  assert_equal(200, response.status)
301
311
 
302
312
  hash = Logster.store.get_all_ignore_count
@@ -304,34 +314,28 @@ class TestViewer < Minitest::Test
304
314
  end
305
315
 
306
316
  def test_linking_to_a_valid_js_files
307
- %w(
308
- /logsie/javascript/client-app.js
309
- /logsie/javascript/vendor.js
310
- ).each do |path|
317
+ %w[/logsie/javascript/client-app.js /logsie/javascript/vendor.js].each do |path|
311
318
  response = request.get(path)
312
319
  assert_equal(200, response.status)
313
- assert_equal('application/javascript', response.headers['content-type'])
320
+ assert_equal("application/javascript", response.headers["content-type"])
314
321
  end
315
322
  end
316
323
 
317
324
  def test_linking_to_a_valid_css_files
318
- %w(
319
- /logsie/stylesheets/client-app.css
320
- /logsie/stylesheets/vendor.css
321
- ).each do |path|
325
+ %w[/logsie/stylesheets/client-app.css /logsie/stylesheets/vendor.css].each do |path|
322
326
  response = request.get(path)
323
327
  assert_equal(200, response.status)
324
- assert_equal('text/css', response.headers['content-type'])
328
+ assert_equal("text/css", response.headers["content-type"])
325
329
  end
326
330
  end
327
331
 
328
332
  def test_linking_to_an_invalid_ember_component_or_template
329
- %w(
333
+ %w[
330
334
  /logsie/javascript/templates/application.hbs
331
335
  /logsie/javascript/templates/does_not_exist.js
332
336
  /logsie/javascript/components/does_not_exist.js
333
337
  /logsie/javascript/templates/../../app.js
334
- ).each do |path|
338
+ ].each do |path|
335
339
  response = request.get(path)
336
340
  assert_equal(404, response.status, "#{path} should have 404'ed")
337
341
  end
@@ -380,13 +384,16 @@ class TestViewer < Minitest::Test
380
384
  def test_solve_group_api_requires_post_request
381
385
  Logster.config.enable_custom_patterns_via_ui = true
382
386
  Logster::GroupingPattern.new(/gotta be post/).save
383
- msg = Logster.store.report(
384
- Logger::WARN,
385
- '',
386
- 'gotta be post 22',
387
- env: { "application_version" => "abc" },
388
- backtrace: "aa"
389
- )
387
+ msg =
388
+ Logster.store.report(
389
+ Logger::WARN,
390
+ "",
391
+ "gotta be post 22",
392
+ env: {
393
+ "application_version" => "abc",
394
+ },
395
+ backtrace: "aa",
396
+ )
390
397
  latest = Logster.store.latest
391
398
  assert_equal(1, latest.size)
392
399
  assert_equal(msg.key, latest.first["messages"].first.key)
@@ -405,13 +412,16 @@ class TestViewer < Minitest::Test
405
412
  def test_solve_group_returns_404_when_pattern_doesnt_exist
406
413
  Logster.config.enable_custom_patterns_via_ui = true
407
414
  Logster::GroupingPattern.new(/some pattern/).save
408
- msg = Logster.store.report(
409
- Logger::WARN,
410
- '',
411
- 'some pattern 22',
412
- env: { "application_version" => "abc" },
413
- backtrace: "aa"
414
- )
415
+ msg =
416
+ Logster.store.report(
417
+ Logger::WARN,
418
+ "",
419
+ "some pattern 22",
420
+ env: {
421
+ "application_version" => "abc",
422
+ },
423
+ backtrace: "aa",
424
+ )
415
425
  latest = Logster.store.latest
416
426
  assert_equal(1, latest.size)
417
427
  assert_equal(msg.key, latest.first["messages"].first.key)
@@ -428,21 +438,25 @@ class TestViewer < Minitest::Test
428
438
  Logster.config.enable_custom_patterns_via_ui = true
429
439
  backtrace = "a b c d"
430
440
  Logster::GroupingPattern.new(/test pattern/).save
431
- msg1 = Logster.store.report(Logger::WARN, '', 'test pattern 1', backtrace: backtrace)
432
- msg2 = Logster.store.report(
433
- Logger::WARN,
434
- '',
435
- 'test pattern 2',
436
- env: { "application_version" => "abc" },
437
- backtrace: backtrace
438
- )
439
- msg3 = Logster.store.report(
440
- Logger::WARN,
441
- '',
442
- 'test pattern 3',
443
- env: [{ "application_version" => "def" }, { "application_version" => "ghi" }],
444
- backtrace: backtrace
445
- )
441
+ msg1 = Logster.store.report(Logger::WARN, "", "test pattern 1", backtrace: backtrace)
442
+ msg2 =
443
+ Logster.store.report(
444
+ Logger::WARN,
445
+ "",
446
+ "test pattern 2",
447
+ env: {
448
+ "application_version" => "abc",
449
+ },
450
+ backtrace: backtrace,
451
+ )
452
+ msg3 =
453
+ Logster.store.report(
454
+ Logger::WARN,
455
+ "",
456
+ "test pattern 3",
457
+ env: [{ "application_version" => "def" }, { "application_version" => "ghi" }],
458
+ backtrace: backtrace,
459
+ )
446
460
  group = Logster.store.find_pattern_groups { |p| p == /test pattern/ }.first
447
461
  assert_equal([msg3, msg2, msg1].map(&:key), group.messages_keys)
448
462
 
@@ -460,14 +474,16 @@ class TestViewer < Minitest::Test
460
474
  assert_equal([msg1.key], latest.first["messages"].map(&:key))
461
475
  assert_equal(1, latest.size)
462
476
 
463
- msg4 = Logster.store.report(Logger::WARN, '', 'test pattern 4', backtrace: backtrace)
477
+ msg4 = Logster.store.report(Logger::WARN, "", "test pattern 4", backtrace: backtrace)
464
478
  %w[abc def ghi].each do |version|
465
479
  Logster.store.report(
466
480
  Logger::WARN,
467
- '',
468
- 'test pattern 5',
469
- env: { "application_version" => version },
470
- backtrace: backtrace
481
+ "",
482
+ "test pattern 5",
483
+ env: {
484
+ "application_version" => version,
485
+ },
486
+ backtrace: backtrace,
471
487
  )
472
488
  end
473
489
  latest = Logster.store.latest
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
4
- require 'logster/base_store'
5
- require 'logster/ignore_pattern'
3
+ require_relative "../test_helper"
4
+ require "logster/base_store"
5
+ require "logster/ignore_pattern"
6
6
 
7
7
  class TestBaseStore < Minitest::Test
8
-
9
8
  def setup
10
9
  @store = Logster::TestStore.new
11
10
  @store.clear_all
@@ -18,7 +17,7 @@ class TestBaseStore < Minitest::Test
18
17
  def test_report_skip_empty
19
18
  @store.skip_empty = true
20
19
  @store.report(Logger::WARN, "test", nil)
21
- @store.report(Logger::WARN, "test", '')
20
+ @store.report(Logger::WARN, "test", "")
22
21
  @store.report(Logger::WARN, "test", "foo") #
23
22
  @store.skip_empty = false
24
23
  @store.report(Logger::WARN, "test", nil) #
@@ -39,30 +38,40 @@ class TestBaseStore < Minitest::Test
39
38
 
40
39
  def test_report_skip_ignore
41
40
  @store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity")
42
- @store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)")
41
+ @store.report(
42
+ Logger::FATAL,
43
+ "test",
44
+ "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)",
45
+ )
43
46
  @store.report(Logger::WARN, "test", "B")
44
47
  @store.ignore = [
45
- /^ActiveRecord::RecordNotFound \(Couldn't find Upload/,
46
- /^Can't verify CSRF token authenticity/
48
+ /^ActiveRecord::RecordNotFound \(Couldn't find Upload/,
49
+ /^Can't verify CSRF token authenticity/,
47
50
  ]
48
51
  @store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity")
49
- @store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)")
50
- @store.report(Logger::FATAL, "test", "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9489+78946947)")
52
+ @store.report(
53
+ Logger::FATAL,
54
+ "test",
55
+ "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9947)",
56
+ )
57
+ @store.report(
58
+ Logger::FATAL,
59
+ "test",
60
+ "ActiveRecord::RecordNotFound (Couldn't find Upload with 'id'=9489+78946947)",
61
+ )
51
62
  @store.report(Logger::WARN, "test", "B")
52
63
 
53
64
  assert_equal(4, @store.count)
54
65
  end
55
66
 
56
67
  def test_ignore_pattern_basic
57
- @store.ignore = [
58
- Logster::IgnorePattern.new(nil, username: 'CausingErrors')
59
- ]
68
+ @store.ignore = [Logster::IgnorePattern.new(nil, username: "CausingErrors")]
60
69
  @store.report(Logger::WARN, "test", "Foobar") #
61
- @store.report(Logger::WARN, "test", "Foobar", env: { username: 'CausingErrors' })
70
+ @store.report(Logger::WARN, "test", "Foobar", env: { username: "CausingErrors" })
62
71
  @store.report(Logger::WARN, "test", "Foobar", env: nil)
63
- @store.report(Logger::WARN, "test", "Something Else", env: { username: 'CausingErrors' })
64
- @store.report(Logger::WARN, "test", "Something Else", env: { 'username' => 'CausingErrors' })
65
- @store.report(Logger::WARN, "test", "Something Else", env: { username: 'GoodPerson' }) #
72
+ @store.report(Logger::WARN, "test", "Something Else", env: { username: "CausingErrors" })
73
+ @store.report(Logger::WARN, "test", "Something Else", env: { "username" => "CausingErrors" })
74
+ @store.report(Logger::WARN, "test", "Something Else", env: { username: "GoodPerson" }) #
66
75
  @store.report(Logger::WARN, "test", "Can't verify CSRF token authenticity") #
67
76
 
68
77
  assert_equal(4, @store.count)
@@ -70,37 +79,47 @@ class TestBaseStore < Minitest::Test
70
79
 
71
80
  def test_ignore_pattern_real
72
81
  @store.ignore = [
73
- /^ActionController::RoutingError \(No route matches/,
74
- Logster::IgnorePattern.new("Can't verify CSRF token authenticity", REQUEST_URI: /\/trackback\/$/)
82
+ /^ActionController::RoutingError \(No route matches/,
83
+ Logster::IgnorePattern.new(
84
+ "Can't verify CSRF token authenticity",
85
+ REQUEST_URI: %r{/trackback/$},
86
+ ),
75
87
  ]
76
88
  # blocked
77
- @store.report(Logger::WARN, "whatever", "Can't verify CSRF token authenticity",
78
- env: {
79
- HTTP_HOST: 'meta.discourse.org',
80
- REQUEST_URI: '/t/use-more-standard-smiley-codes-instead-of-smile/1822/trackback/',
81
- REQUEST_METHOD: 'POST',
82
- HTTP_USER_AGENT: 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',
83
- params: {
84
- title: 'Something Spammy',
85
- url: 'http://spam.example.net/whatever/spam.html',
86
- excerpt: 'http://spam.example.com/pdf/blahblah.html free viagra',
87
- blog_name: 'get free spam for cheap'
88
- }
89
- }
89
+ @store.report(
90
+ Logger::WARN,
91
+ "whatever",
92
+ "Can't verify CSRF token authenticity",
93
+ env: {
94
+ HTTP_HOST: "meta.discourse.org",
95
+ REQUEST_URI: "/t/use-more-standard-smiley-codes-instead-of-smile/1822/trackback/",
96
+ REQUEST_METHOD: "POST",
97
+ HTTP_USER_AGENT: "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)",
98
+ params: {
99
+ title: "Something Spammy",
100
+ url: "http://spam.example.net/whatever/spam.html",
101
+ excerpt: "http://spam.example.com/pdf/blahblah.html free viagra",
102
+ blog_name: "get free spam for cheap",
103
+ },
104
+ },
90
105
  )
91
106
  # logged
92
- @store.report(Logger::WARN, "whatever", "Can't verify CSRF token authenticity",
93
- env: {
94
- HTTP_HOST: 'meta.discourse.org',
95
- REQUEST_URI: '/session',
96
- REQUEST_METHOD: 'POST',
97
- HTTP_USER_AGENT: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
98
- params: {
99
- username: 'user',
100
- password: 'password',
101
- form_authenticity_token: 'incorrect'
102
- }
103
- }
107
+ @store.report(
108
+ Logger::WARN,
109
+ "whatever",
110
+ "Can't verify CSRF token authenticity",
111
+ env: {
112
+ HTTP_HOST: "meta.discourse.org",
113
+ REQUEST_URI: "/session",
114
+ REQUEST_METHOD: "POST",
115
+ HTTP_USER_AGENT:
116
+ "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36",
117
+ params: {
118
+ username: "user",
119
+ password: "password",
120
+ form_authenticity_token: "incorrect",
121
+ },
122
+ },
104
123
  )
105
124
  assert_equal(1, @store.count)
106
125
  end
@@ -128,7 +147,16 @@ class TestBaseStore < Minitest::Test
128
147
  assert_equal(error.backtrace.join("\n"), message.backtrace)
129
148
 
130
149
  # Via env takes priority
131
- message = @store.report(Logger::WARN, "test", "C", backtrace: "Garbage", env: { backtrace: error.backtrace })
150
+ message =
151
+ @store.report(
152
+ Logger::WARN,
153
+ "test",
154
+ "C",
155
+ backtrace: "Garbage",
156
+ env: {
157
+ backtrace: error.backtrace,
158
+ },
159
+ )
132
160
  assert_equal(error.backtrace.join("\n"), message.backtrace)
133
161
 
134
162
  # Backtrace is always a string
@@ -143,7 +171,7 @@ class TestBaseStore < Minitest::Test
143
171
  assert_kind_of(String, message.backtrace)
144
172
 
145
173
  # Arrays are turned into strings via join \n
146
- message = @store.report(Logger::WARN, "test", "H", backtrace: ["Foo", "Bar"])
174
+ message = @store.report(Logger::WARN, "test", "H", backtrace: %w[Foo Bar])
147
175
  assert_equal("Foo\nBar", message.backtrace)
148
176
  end
149
177
 
@@ -166,12 +194,12 @@ class TestBaseStore < Minitest::Test
166
194
  def test_log_message_is_truncated_when_above_maximum_message_length
167
195
  orig = Logster.config.maximum_message_length
168
196
  Logster.config.maximum_message_length = 300
169
- msg = @store.report(Logger::WARN, '', 'a' * 400)
197
+ msg = @store.report(Logger::WARN, "", "a" * 400)
170
198
  # 3 is the ... at the end to indicate truncated message
171
199
  assert_equal(300 + 3, msg.message.size)
172
200
 
173
201
  Logster.config.maximum_message_length = 100
174
- msg = @store.report(Logger::WARN, '', 'a' * 200)
202
+ msg = @store.report(Logger::WARN, "", "a" * 200)
175
203
  assert_equal(100 + 3, msg.message.size)
176
204
  ensure
177
205
  Logster.config.maximum_message_length = orig
@@ -182,22 +210,15 @@ class TestBaseStore < Minitest::Test
182
210
  other_store = Logster::TestStore.new
183
211
  other_logger = Logster::Logger.new(other_store)
184
212
  logger.chain(other_logger)
185
- logger.add(Logger::WARN, "this is warning", '', { env: { backtrace: '11' } })
213
+ logger.add(Logger::WARN, "this is warning", "", { env: { backtrace: "11" } })
186
214
  [@store, other_store].each do |store|
187
- assert_equal('11', store.reported.first.backtrace)
215
+ assert_equal("11", store.reported.first.backtrace)
188
216
  refute_includes(store.reported.first.env.keys.map(&:to_sym), :backtrace)
189
217
  end
190
218
  end
191
219
 
192
220
  def test_envs_with_invalid_encoding_dont_raise_errors
193
- msg = @store.report(
194
- Logger::WARN,
195
- '',
196
- 'me have invalid encoding',
197
- env: {
198
- axe: "a\xF1xasa"
199
- }
200
- )
221
+ msg = @store.report(Logger::WARN, "", "me have invalid encoding", env: { axe: "a\xF1xasa" })
201
222
  assert_equal("a�xasa", msg.env[:axe])
202
223
  end
203
224
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
4
- require 'logster/cache'
3
+ require_relative "../test_helper"
4
+ require "logster/cache"
5
5
 
6
6
  class TestCache < Minitest::Test
7
7
  def setup
@@ -9,11 +9,7 @@ class TestCache < Minitest::Test
9
9
  end
10
10
 
11
11
  def test_cache_works
12
- prc = Proc.new do |key, value|
13
- @cache.fetch(key) do
14
- value
15
- end
16
- end
12
+ prc = Proc.new { |key, value| @cache.fetch(key) { value } }
17
13
  value = "I should be retured"
18
14
  assert_equal(value, prc.call(:key1, value))
19
15
  cached_value = value
@@ -23,7 +19,7 @@ class TestCache < Minitest::Test
23
19
  assert_equal(value2, prc.call(:key2, value2))
24
20
 
25
21
  value = value2 = "Now I should be returned"
26
- Process.stub :clock_gettime, Process.clock_gettime(Process::CLOCK_MONOTONIC) + 6 do
22
+ Process.stub :clock_gettime, Process.clock_gettime(Process::CLOCK_MONOTONIC) + 6 do
27
23
  assert_equal(value, prc.call(:key1, value))
28
24
  assert_equal(value2, prc.call(:key2, value2))
29
25
  end
@@ -31,9 +27,7 @@ class TestCache < Minitest::Test
31
27
 
32
28
  def test_cache_can_be_cleared
33
29
  value = "cached"
34
- prc = Proc.new do |key, val|
35
- @cache.fetch(key) { val }
36
- end
30
+ prc = Proc.new { |key, val| @cache.fetch(key) { val } }
37
31
  assert_equal(value, prc.call(:key1, value))
38
32
  assert_equal("v2", prc.call(:key2, "v2"))
39
33
 
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../test_helper'
4
- require 'logster/defer_logger'
5
- require 'logster/logger'
3
+ require_relative "../test_helper"
4
+ require "logster/defer_logger"
5
+ require "logster/logger"
6
6
 
7
7
  class TestDeferLogger < Minitest::Test
8
8
  def setup