lumberjack_data_dog_device 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGE_LOG.md +5 -0
- data/README.md +2 -0
- data/VERSION +1 -1
- data/lib/lumberjack_data_dog_device.rb +24 -10
- 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: 5dc89bac640c1450fe612caa49767cc803423030e16cee302387c00466996a0f
|
4
|
+
data.tar.gz: 27947af281577cee4c4b0ca72d7aa033fd8ea13b79c076f2308baf19565b16a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2826f6ad6233b10c5ecc2578de5cf0968f86d749c1b3db03ba061c1848fbfa9c2c480126e024d50a24d1d293e895fcede3c61fc1f872570f23e177f6a84e161
|
7
|
+
data.tar.gz: 155ad680ada842234fcc9dad6dd5fa697022120586987fc0a7644c2cf6e1e49425783d1f75b6a133f28b358a771e88fc560c1e86fbabfba338c6217d8a593e92
|
data/CHANGE_LOG.md
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,8 @@ This gem provides a logging device that produces JSON output that matches the st
|
|
23
23
|
|
24
24
|
This device extends from [`Lumberjack::JsonDevice`](). It is not tied to Data Dog in any way other than that it is opinionated about how to map and format some log tags. It can be used with other services or pipelines without issue.
|
25
25
|
|
26
|
+
You can optionally specify a maximum message length with the `max_message_length` option on the device. Doing so will trucate the message payload to keep it under this number of characters. This option is provided because JSON payloads get messed up and cannot be parsed if they get too big.
|
27
|
+
|
26
28
|
## Example
|
27
29
|
|
28
30
|
You could log an HTTP request to some of the DataDog standard fields like this:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
@@ -10,9 +10,9 @@ module Lumberjack
|
|
10
10
|
class DataDogDevice < JsonDevice
|
11
11
|
|
12
12
|
module ExceptionHash
|
13
|
-
|
13
|
+
|
14
14
|
protected
|
15
|
-
|
15
|
+
|
16
16
|
def exception_hash(exception, device)
|
17
17
|
hash = {"kind" => exception.class.name}
|
18
18
|
hash["message"] = exception.message unless exception.message.nil?
|
@@ -24,23 +24,32 @@ module Lumberjack
|
|
24
24
|
hash
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
# Formatter to format a messge as an error if it is an exception.
|
29
29
|
class MessageExceptionFormatter
|
30
30
|
include ExceptionHash
|
31
|
-
|
31
|
+
|
32
32
|
def initialize(device = nil)
|
33
33
|
@device = device
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
def call(object)
|
37
37
|
if object.is_a?(Exception)
|
38
38
|
{
|
39
39
|
"message" => object.inspect,
|
40
40
|
"error" => exception_hash(object, @device)
|
41
41
|
}
|
42
|
-
|
42
|
+
elsif object.is_a?(Hash)
|
43
43
|
{ "message" => object }
|
44
|
+
elsif object.nil?
|
45
|
+
{ "message" => nil }
|
46
|
+
else
|
47
|
+
message = object.to_s
|
48
|
+
max_message_length = @device.max_message_length
|
49
|
+
if max_message_length && message.length > max_message_length
|
50
|
+
message = message[0, max_message_length]
|
51
|
+
end
|
52
|
+
{ "message" => message }
|
44
53
|
end
|
45
54
|
end
|
46
55
|
end
|
@@ -124,14 +133,19 @@ module Lumberjack
|
|
124
133
|
# One use for it is to keep stack traces clean and prevent them from overflowing the limit on
|
125
134
|
# the payload size for an individual log entry.
|
126
135
|
attr_accessor :backtrace_cleaner
|
127
|
-
|
128
|
-
|
136
|
+
|
137
|
+
# You can specify a limit on the message size. Messages over this size will be split into multiple
|
138
|
+
# log entries to prevent overflowing the limit on message size which makes the log entries unparseable.
|
139
|
+
attr_accessor :max_message_length
|
140
|
+
|
141
|
+
def initialize(stream_or_device, backtrace_cleaner: nil, max_message_length: nil)
|
129
142
|
super(stream_or_device, mapping: data_dog_mapping)
|
130
143
|
self.backtrace_cleaner = backtrace_cleaner
|
144
|
+
self.max_message_length = max_message_length
|
131
145
|
end
|
132
|
-
|
146
|
+
|
133
147
|
private
|
134
|
-
|
148
|
+
|
135
149
|
def data_dog_mapping
|
136
150
|
{
|
137
151
|
time: "timestamp",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumberjack_data_dog_device
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Durand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lumberjack_json_device
|