sapience 2.11 → 2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +28 -0
- data/lib/sapience/base.rb +6 -2
- data/lib/sapience/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 189ddb34ecc477adc2d44d235d2e8dac5bfad45f40539bdd6f842938e6b3cacb
|
4
|
+
data.tar.gz: 1f96bc549878bca58fb5122c983eb2e75f12e6d7c5715938bd82a6316b055072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5adb1b869eef53cde71734b7bacdbc11f31e188117d694863faeb49442f8bb0726394ad8f3e830b0da12d7ff193341f2b44db908aab13a7ddb0f2ec9b6a7388a
|
7
|
+
data.tar.gz: d786d35fd92de4268bcfe6d8bc946406f40cafcd2e7fd1f56d67f32733d60c3fefefc24f8b682ba2e9c5abc6dd854ef04af3df4910f31fb5b21e16f5dbc29ec7
|
data/CHANGELOG.md
CHANGED
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
|
data/lib/sapience/version.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2020-03-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: concurrent-ruby
|