sapience 2.11 → 2.12

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: 4dea67688e4da16e54b354ef95c3307c40b4c48a7a9c731b036a759301993bad
4
- data.tar.gz: e95f42b7e1b564b96436119394c5cf36bfe764e151edc27f3bdd71571d373ff3
3
+ metadata.gz: 189ddb34ecc477adc2d44d235d2e8dac5bfad45f40539bdd6f842938e6b3cacb
4
+ data.tar.gz: 1f96bc549878bca58fb5122c983eb2e75f12e6d7c5715938bd82a6316b055072
5
5
  SHA512:
6
- metadata.gz: 9d44242c65762e0696ff3b34256d2ee67cee441c1a957efb988ecebaa6abd340ba2e02e1fbd5168973262e689333b7bbc4e4fd5835bc9a5472b22fbb2990c15d
7
- data.tar.gz: b803898eee7e30eedfcf704d9befc942e518e53da773fe699888d6c4cdfe79402ce4bdb7f9bbfdb5f1a14b2b78cc0d7101e658c32fe1da01c181c50a80f24fc0
6
+ metadata.gz: 5adb1b869eef53cde71734b7bacdbc11f31e188117d694863faeb49442f8bb0726394ad8f3e830b0da12d7ff193341f2b44db908aab13a7ddb0f2ec9b6a7388a
7
+ data.tar.gz: d786d35fd92de4268bcfe6d8bc946406f40cafcd2e7fd1f56d67f32733d60c3fefefc24f8b682ba2e9c5abc6dd854ef04af3df4910f31fb5b21e16f5dbc29ec7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## v2.12
2
+ - feature: 'log hooks', a mechanism for modifying the log event just before it is added to the appender
3
+
1
4
  ## v2.11
2
5
  - Add config option to enable/disable metrics from ActionController
3
6
 
data/README.md CHANGED
@@ -249,6 +249,34 @@ For further details about "app_name", "filter_parameters", "appenders", "metrics
249
249
  - [logger](docs/logger.md)
250
250
 
251
251
 
252
+ ### Log hooks
253
+ *Log hooks* allow us to modify the log object **Sapience::Log** just before it is added to the appender. A 'log hook' can be an object that responds to #call. Multiple hooks can be used.
254
+ The following examples show how to use hooks to:
255
+
256
+ * inject Datadog APM tracing data in every log event.
257
+ * modify the logs event's **message** field.
258
+
259
+ ```ruby
260
+ my_logger = Sapience.logger
261
+
262
+ # inject Datadog tracing info in payload hash
263
+ my_logger.log_hooks << ->(log) do
264
+ trace_data = {
265
+ dd: {
266
+ span_id: ::Datadog.tracer.active_correlation.span_id.to_s,
267
+ trace_id: ::Datadog.tracer.active_correlation.trace_id.to_s
268
+ }
269
+ }
270
+ log.payload? ? log.payload.merge!(trace_data) : log.payload = trace_data
271
+ end
272
+
273
+ # append number of times a GC occurred since process started in field 'message'
274
+ my_logger.log_hooks << ->(log) do
275
+ log.message = "#{log.message} = GC count: #{GC.count}"
276
+ end
277
+ ```
278
+
279
+
252
280
  ## Running the tests
253
281
 
254
282
  You need to create the test postgres db, by running the command below:
data/lib/sapience/base.rb CHANGED
@@ -3,7 +3,7 @@ module Sapience
3
3
  # rubocop:disable ClassLength
4
4
  class Base
5
5
  # Class name to be logged
6
- attr_accessor :name, :filter
6
+ attr_accessor :name, :filter, :log_hooks
7
7
  include Sapience::LogMethods
8
8
 
9
9
  # Set the logging level for this logger
@@ -174,7 +174,7 @@ module Sapience
174
174
  # Proc: Only include log messages where the supplied Proc returns true
175
175
  # The Proc must return true or false
176
176
  # rubocop:disable AbcSize, PerceivedComplexity, CyclomaticComplexity, LineLength
177
- def initialize(klass, level = nil, filter = nil)
177
+ def initialize(klass, level = nil, filter = nil, log_hooks = [])
178
178
  # Support filtering all messages to this logger using a Regular Expression
179
179
  # or Proc
180
180
  fail ArgumentError, ":filter must be a Regexp or Proc" unless filter.nil? || filter.is_a?(Regexp) || filter.is_a?(Proc)
@@ -183,6 +183,7 @@ module Sapience
183
183
  @name = klass if klass.is_a?(String)
184
184
  @name ||= klass.name if klass.respond_to?(:name)
185
185
  @name ||= klass.class.name
186
+ @log_hooks = log_hooks
186
187
 
187
188
  if level.nil?
188
189
  # Allow the global default level to determine this loggers log level
@@ -271,6 +272,9 @@ module Sapience
271
272
  end
272
273
  log.payload = payload unless payload.empty?
273
274
  end
275
+
276
+ log_hooks.each { |h| h.call(log) }
277
+
274
278
  self.log(log) if include_message?(log)
275
279
  end
276
280
  # rubocop:enable AbcSize, PerceivedComplexity, CyclomaticComplexity, LineLength
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sapience
3
- VERSION = "2.11"
3
+ VERSION = "2.12"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapience
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.11'
4
+ version: '2.12'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-03-09 00:00:00.000000000 Z
12
+ date: 2020-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby