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 +4 -4
- data/lib/buffering_logger/rails_rack_log_request_id.rb +20 -0
- data/lib/buffering_logger/railtie.rb +30 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9b82663dc5ffc6178d13c3083c561de7586ce1c6e3d33e97265a1d29704ab4
|
4
|
+
data.tar.gz: ee87cca077521602967459410da53d0e067391ba6ee9d3f7e47179e0f2fe0208
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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 =
|
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
|
-
#
|
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,
|
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.
|
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
|