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 +4 -4
- data/lib/datadog/configuration.rb +9 -3
- data/lib/datadog/loggers/json_formatter.rb +18 -1
- data/lib/datadog/loggers/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 836874a1c02962352440db10da65b626a68794a8ce7a6587bb5ab3158cebf1f5
|
4
|
+
data.tar.gz: a16b5252652d557495cf9a13ffbdd64ce6d412c2d581555c6e69c0d65e85eee7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 [
|
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
|
|