buffering_logger 3.0.0 → 3.1.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: f49590098cb33d87ab8d0114a978908743fe30357604b07dad8e11f5ec999fc2
4
- data.tar.gz: fab5895b8c82b7b08f7b50229eb6f6672afe07ea0ee832982e2637230c7f2b5c
3
+ metadata.gz: dc9b82663dc5ffc6178d13c3083c561de7586ce1c6e3d33e97265a1d29704ab4
4
+ data.tar.gz: ee87cca077521602967459410da53d0e067391ba6ee9d3f7e47179e0f2fe0208
5
5
  SHA512:
6
- metadata.gz: 2e6e3304cacc56982a8c1348f8d6911013c6192230ed1e2b8fda53f668bdf76d526b206102877f1b33daa3e369a734f3d413d802f074f05e6e2a6e76f011c6fb
7
- data.tar.gz: 3ab02da9c65ff13366f77f1b5935d5d4249357cc0110a71480c3041715f3b7d57454ac0de0009d4b49d1662445bc70bc18711a3e145901c4c1cdca5df12f8529
6
+ metadata.gz: bbc41e536016932cc8c5b1e5e2c814eb6089d0605d1843335ce63e403250b3a09c49168d7e2e52570db41766c079284f4b5fa961924a161df9c3e4a521fcd52d
7
+ data.tar.gz: 4cbddf5dce7fe3d1413c9487f3a3b6f56d6de8d578dab6dd8aca79a591a0018586987cd100202967179b41eaab962b54c0838c5b7ddd519820c350b39a5702bf
@@ -0,0 +1,20 @@
1
+ #
2
+ # With buffered logs we don't need to log the request_id on every line.
3
+ # Instead we log it once near the start of the request.
4
+ # We do this via a Rack middleware to ensure that it's logged even for things
5
+ # like a `RoutingError` or other exceptional cases.
6
+ #
7
+ class BufferingLogger::RailsRackLogRequestId
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ request = ActionDispatch::Request.new(env)
15
+ Rails.logger.info("request_id=#{request.request_id.inspect}")
16
+
17
+ @app.call(env)
18
+ end
19
+
20
+ end
@@ -1,10 +1,14 @@
1
1
  require 'buffering_logger'
2
2
  require 'buffering_logger/rack_buffer'
3
+ require 'buffering_logger/rails_rack_log_request_id'
3
4
  require 'rails/railtie'
4
5
 
5
6
  class BufferingLogger::Railtie < Rails::Railtie
6
7
 
7
- def self.install(transform: nil, device: nil, sync: true)
8
+ def self.install(
9
+ transform: nil, device: nil, sync: true, request_id: true,
10
+ warn_log_tags: true, simple_formatter: true
11
+ )
8
12
  initializer :buffering_logger, :before => :initialize_logger do |app|
9
13
  device ||= begin
10
14
  # Does mostly the same things that Rails does. See http://git.io/2v9FxQ
@@ -23,17 +27,39 @@ class BufferingLogger::Railtie < Rails::Railtie
23
27
  device.sync = true if sync && device.respond_to?(:sync=)
24
28
 
25
29
  logger = BufferingLogger::Logger.new(device)
26
- logger.formatter = app.config.log_formatter
30
+ logger.formatter = if simple_formatter
31
+ ActiveSupport::Logger::SimpleFormatter.new
32
+ else
33
+ app.config.log_formatter
34
+ end
27
35
  logger = ActiveSupport::TaggedLogging.new(logger)
28
36
 
29
37
  app.config.logger = logger
30
38
 
31
- # Inserts at the very beginning so that all logs, even from other
39
+ # We insert this at the very beginning so that all logs, even from other
32
40
  # middleware, get buffered together.
33
41
  app.config.middleware.insert(
34
42
  0,
35
- BufferingLogger::RackBuffer, logger, transform: transform,
43
+ BufferingLogger::RackBuffer,
44
+ logger,
45
+ transform: transform,
36
46
  )
47
+
48
+ # Log the request_id
49
+ if request_id
50
+ app.config.middleware.insert_after(
51
+ Rails::Rack::Logger,
52
+ BufferingLogger::RailsRackLogRequestId,
53
+ )
54
+ end
55
+
56
+ if warn_log_tags && app.config.log_tags.present?
57
+ puts(<<~TEXT.squish)
58
+ NOTE: You're using `Rails.application.config.log_tags` with
59
+ BufferingLogger. We recommend disabling these when using
60
+ BufferingLogger. See the README for more info.
61
+ TEXT
62
+ end
37
63
  end
38
64
  end
39
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buffering_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Brough
@@ -22,6 +22,7 @@ files:
22
22
  - lib/buffering_logger/logger.rb
23
23
  - lib/buffering_logger/rack_buffer.rb
24
24
  - lib/buffering_logger/rails.rb
25
+ - lib/buffering_logger/rails_rack_log_request_id.rb
25
26
  - lib/buffering_logger/railtie.rb
26
27
  - lib/buffering_logger/single_line_transform.rb
27
28
  homepage: https://github.com/jordan-brough/buffering_logger