datadog-json_logger 0.1.8 → 0.1.9

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: d9a3bd99fbe42f4f151f466f1d4881ac2e402a56998a0b6a2b1b0bd543a79102
4
- data.tar.gz: 4987ddc088b69f67eead916c24200b0fc9370a7153a17acc9a2108748b6c87ae
3
+ metadata.gz: 836874a1c02962352440db10da65b626a68794a8ce7a6587bb5ab3158cebf1f5
4
+ data.tar.gz: a16b5252652d557495cf9a13ffbdd64ce6d412c2d581555c6e69c0d65e85eee7
5
5
  SHA512:
6
- metadata.gz: d63a90d6b53893695969dcf752823146d45f5c50e1b420b9d18bdb24150c58022dc531e9d615e35796a53f94debcd0b5ecad3862c64e4a3d3c359cc92fc6f08e
7
- data.tar.gz: 75216849fe27f732e4a00bd60e46cda2871df68bb2dd86c4c509a9cadae74f26c93bb1ac0a3adfdf3fc4eeaaedd664afd7147e08481eafd3263a5bd2550079bf
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,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.8"
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eth3rnit3