lograge 0.12.0 → 0.13.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: a8dc3fd38bfe24b9f1816ac75fa2d600037fd308b1b355de309d81deae032cd9
4
- data.tar.gz: f3627f7956278364545987b845a16011463592a78dbf9ae0a409b0c8640b63e4
3
+ metadata.gz: be4bab08b1374b1d249edf7c7d9bfc89f327349346ac8cfffaba22a57496548b
4
+ data.tar.gz: 380d3bc691fe9cecf723c4b62f528420d62eb7bc61bd0d880b154855a7c258e8
5
5
  SHA512:
6
- metadata.gz: 5787201d587cee662987f2aef1db3b971a60b7feec4dc630d509520713e2c746aee9a1249817f0d1bb8752d22eadcf5e79259c73213e75ce7127e49115795b95
7
- data.tar.gz: 055daf5493eb1a053a8b995d5037973587782c8edf9a48fd0d860f3d5e5c2bb419957c0df8610eda6e0cc26c54bdcf7bd900ba0113c780c4569fb22330e9b00e
6
+ metadata.gz: c16914bc5d1144d20e3aa81a28b175b9fa5a619b9dc0049ebf8f44c8bc08d365494a51d6e9a0af4d85b4ac5b9c4be6701aed32dfbd4510a5086fd4d2a4238f07
7
+ data.tar.gz: e07e2e6c4fb9f527faf75a7acad4e37ce491fdd4ebf40e41aa7f1dcef19c76ad036ac02b1d4c2a3eabf240331b3e67a96b9c3f13dc3e37c4a8dfc778f894ea64
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Mathias Meyer
3
+ Copyright (c) Mathias Meyer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lograge
4
+ module Formatters
5
+ class KeyValueDeep < KeyValue
6
+ def call(data)
7
+ super flatten_keys(data)
8
+ end
9
+
10
+ protected
11
+
12
+ def flatten_keys(data, prefix = '')
13
+ return flatten_object(data, prefix) if [Hash, Array].include? data.class
14
+
15
+ data
16
+ end
17
+
18
+ def flatten_object(data, prefix)
19
+ result = {}
20
+ loop_on_object(data) do |key, value|
21
+ key = "#{prefix}_#{key}" unless prefix.empty?
22
+ if [Hash, Array].include? value.class
23
+ result.merge!(flatten_keys(value, key))
24
+ else
25
+ result[key] = value
26
+ end
27
+ end
28
+ result
29
+ end
30
+
31
+ def loop_on_object(data, &block)
32
+ if data.instance_of? Array
33
+ data.each_with_index do |value, index|
34
+ yield index, value
35
+ end
36
+ return
37
+ end
38
+ data.each(&block)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -29,6 +29,7 @@ module Lograge
29
29
  def extract_request(event, payload)
30
30
  data = initial_data(payload)
31
31
  data.merge!(extract_status(payload))
32
+ data.merge!(extract_allocations(event))
32
33
  data.merge!(extract_runtimes(event, payload))
33
34
  data.merge!(extract_location)
34
35
  data.merge!(extract_unpermitted_params)
@@ -59,6 +60,14 @@ module Lograge
59
60
  ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
60
61
  end
61
62
 
63
+ def extract_allocations(event)
64
+ if (allocations = (event.respond_to?(:allocations) && event.allocations))
65
+ { allocations: allocations }
66
+ else
67
+ {}
68
+ end
69
+ end
70
+
62
71
  def custom_options(event)
63
72
  options = Lograge.custom_options(event) || {}
64
73
  options.merge event.payload[:custom_payload] || {}
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lograge
4
- VERSION = '0.12.0'
4
+ VERSION = '0.13.0'
5
5
  end
data/lib/lograge.rb CHANGED
@@ -6,6 +6,7 @@ require 'lograge/formatters/cee'
6
6
  require 'lograge/formatters/json'
7
7
  require 'lograge/formatters/graylog2'
8
8
  require 'lograge/formatters/key_value'
9
+ require 'lograge/formatters/key_value_deep'
9
10
  require 'lograge/formatters/l2met'
10
11
  require 'lograge/formatters/lines'
11
12
  require 'lograge/formatters/logstash'
@@ -119,7 +120,7 @@ module Lograge
119
120
  def unsubscribe(component, subscriber)
120
121
  events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
121
122
  events.each do |event|
122
- ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
123
+ Lograge.notification_listeners_for("#{event}.#{component}").each do |listener|
123
124
  ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate') == subscriber
124
125
  end
125
126
  end
@@ -223,6 +224,17 @@ module Lograge
223
224
  def lograge_config
224
225
  application.config.lograge
225
226
  end
227
+
228
+ if ::ActiveSupport::VERSION::MAJOR >= 8 ||
229
+ (::ActiveSupport::VERSION::MAJOR >= 7 && ::ActiveSupport::VERSION::MINOR >= 1)
230
+ def notification_listeners_for(name)
231
+ ActiveSupport::Notifications.notifier.all_listeners_for(name)
232
+ end
233
+ else
234
+ def notification_listeners_for(name)
235
+ ActiveSupport::Notifications.notifier.listeners_for(name)
236
+ end
237
+ end
226
238
  end
227
239
  # rubocop:enable Metrics/ModuleLength
228
240
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lograge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-03-30 00:00:00.000000000 Z
13
+ date: 2023-07-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -126,6 +126,7 @@ files:
126
126
  - lib/lograge/formatters/helpers/method_and_path.rb
127
127
  - lib/lograge/formatters/json.rb
128
128
  - lib/lograge/formatters/key_value.rb
129
+ - lib/lograge/formatters/key_value_deep.rb
129
130
  - lib/lograge/formatters/l2met.rb
130
131
  - lib/lograge/formatters/lines.rb
131
132
  - lib/lograge/formatters/logstash.rb
@@ -147,6 +148,7 @@ licenses:
147
148
  - MIT
148
149
  metadata:
149
150
  rubygems_mfa_required: 'true'
151
+ changelog_uri: https://github.com/roidrage/lograge/blob/master/CHANGELOG.md
150
152
  post_install_message:
151
153
  rdoc_options: []
152
154
  require_paths:
@@ -162,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  - !ruby/object:Gem::Version
163
165
  version: '0'
164
166
  requirements: []
165
- rubygems_version: 3.1.6
167
+ rubygems_version: 3.4.1
166
168
  signing_key:
167
169
  specification_version: 4
168
170
  summary: Tame Rails' multi-line logging into a single line per request