datadog-json_logger 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 868149fa27f3bc6c4900011c73346154d535609f63fd8d897b25fca9f22253ce
4
- data.tar.gz: 1cc23b123383d43bee6ad7e786be0091877f4a663bbf36a9f5947bd258a8f796
3
+ metadata.gz: 836874a1c02962352440db10da65b626a68794a8ce7a6587bb5ab3158cebf1f5
4
+ data.tar.gz: a16b5252652d557495cf9a13ffbdd64ce6d412c2d581555c6e69c0d65e85eee7
5
5
  SHA512:
6
- metadata.gz: 82e4528f5fd85701d6bf6527df76548968949df48c677a05d9c6178534159248b99044e6f730a93602886e3f21c001c8c4212f2d0578f9df8cef98e32eaec195
7
- data.tar.gz: 4ec4aee5f7e99ec413e36c0adbfc3b73ac026571305704b93757744fc6aa25cc708672d6f92693a17ea3bcb24920d4f561ff579f0f3935484ce20e50c30ee375
6
+ metadata.gz: 862e0ec3099f4fa33e0fb331beaedd778cfdfcb07e04bb4e3d6e79ec98c1b50fc3255e453c182d20db48ea1abef0e316661ae8feb678bd067bd24fca69153929
7
+ data.tar.gz: 715af0cff7b051bad08cf37ba75a52f23f42de62b1d97720ae367a2d218d3bc2d2a57dbb4cdcb1887ddd669eed430c5f4f4477c4c4ca63e39f3032438d4c4143
@@ -2,14 +2,20 @@
2
2
 
3
3
  module Datadog
4
4
  class Configuration
5
- attr_accessor :current_user, :controller_key, :resource_key, :action_key
5
+ attr_accessor :current_user, :custom_context, :controller_key, :resource_key, :action_key
6
6
 
7
- # @param current_user [Lambda] A lambda that returns the current user
8
- # e.g. ->(env) { env["current_user"] }
7
+ # @param current_user [Proc] A proc that returns the current user
8
+ # e.g. ->(env) { env["current_user"] } # Current user is logged on each rack log if set
9
+
10
+ # @param custom_context [Proc] A proc that returns a hash of custom context
11
+ # @param controller_key [String] The key to use for the controller name in the log
12
+ # @param resource_key [String] The key to use for the resource name in the log
13
+ # @param action_key [String] The key to use for the action name in the log
9
14
 
10
15
  # @return [Datadog::Configuration]
11
16
  def initialize
12
17
  @current_user = nil
18
+ @custom_context = -> { {} }
13
19
  @controller_key = "sinatra.controller_name"
14
20
  @resource_key = "sinatra.resource_name"
15
21
  @action_key = "sinatra.action_name"
@@ -22,6 +22,10 @@ module Datadog
22
22
  yield(config)
23
23
  end
24
24
 
25
+ def config
26
+ self.class.config
27
+ end
28
+
25
29
  private
26
30
 
27
31
  def default_output
@@ -22,15 +22,24 @@ module Datadog
22
22
  dd: correlation_hash,
23
23
  timestamp: datetime.to_s,
24
24
  severity: severity.ljust(5).to_s,
25
- progname: progname.to_s
25
+ progname: progname.to_s,
26
+ **custom_context
26
27
  }
27
28
  end
28
29
 
30
+ def self.custom_context
31
+ context = Datadog::JSONLogger.config.custom_context
32
+ return {} unless context.respond_to?(:call)
33
+
34
+ context.call
35
+ end
36
+
29
37
  def self.formatter_for(msg)
30
38
  case msg
31
39
  when Hash then HashFormatter
32
40
  when Exception then ExceptionFormatter
33
41
  when String then StringFormatter
42
+ when Proc then ProcFormatter
34
43
  else DefaultFormatter
35
44
  end
36
45
  end
@@ -77,6 +86,14 @@ module Datadog
77
86
  end
78
87
  end
79
88
 
89
+ module ProcFormatter
90
+ module_function
91
+
92
+ def format(log_hash, msg)
93
+ log_hash[:message] = msg.call
94
+ end
95
+ end
96
+
80
97
  module DefaultFormatter
81
98
  module_function
82
99
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Datadog
4
4
  module Loggers
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.9"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datadog-json_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eth3rnit3