ama_logger 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +1 -1
- data/README.md +20 -1
- data/lib/ama/logger.rb +6 -0
- data/lib/ama/logger/base.rb +1 -0
- data/lib/ama/logger/formatter/json.rb +57 -0
- data/lib/ama/logger/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 82c2fc23eb3fb3b209ca6a0e5a4227f73adc9e694a4a48f20b9d830a83fe9834
|
4
|
+
data.tar.gz: 967b8acb04279d9d1abc42ef289a76dd7e9ca4681746c7be43d9615c9189540f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a0fdb20f027e387375528eae35f4275f9f8a2ae022e15e3e56f940236b752b8984982d5b88c07b2928ac09d8124251ad5c6a1c16661fa33a723ab6f472b0a96
|
7
|
+
data.tar.gz: 1f9ddad15968aafcb468789469cb1296374203e79c290941ef51ae305ac95d3b1ba87105a5f0d8449a0ee2bc83850ecb894e0f389675596ab957e251825b4233
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,7 @@ This library includes the following custom log formatters:
|
|
32
32
|
|
33
33
|
### Ama::Logger::Formatter::Lambda
|
34
34
|
|
35
|
-
This formatter accepts a Ruby hash as a message and outputs a JSON string.
|
35
|
+
This formatter accepts a Ruby hash as a message, an AWS Lambda context instance and outputs a JSON string.
|
36
36
|
|
37
37
|
The input hash must look like:
|
38
38
|
|
@@ -48,6 +48,25 @@ Ama.logger.info(
|
|
48
48
|
)
|
49
49
|
```
|
50
50
|
|
51
|
+
### Ama::Logger::Formatter::Json
|
52
|
+
|
53
|
+
This formatter accepts a Ruby hash as a message and outputs a JSON string.
|
54
|
+
|
55
|
+
The input hash must look like:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
Ama.logger.info(
|
59
|
+
event_name: 'log.info', # required
|
60
|
+
event_id: '1234', # required - indexed
|
61
|
+
event_source: 'my_source', # required - indexed
|
62
|
+
exception: 'ArgumentError - something broke', # optional - indexed
|
63
|
+
metric_name: 'error:count', # optional - indexed
|
64
|
+
metric_value: 1, # optional - indexed, coerced to integer
|
65
|
+
metric_content: 'error', # optional - indexed, coerced to string
|
66
|
+
details: { message: 'test' } # optional - non-indexed, Hash coerced to string
|
67
|
+
)
|
68
|
+
```
|
69
|
+
|
51
70
|
### Ama::Logger::Formatter::StringifiedHash
|
52
71
|
|
53
72
|
This formatter accepts string message and outputs a JSON string. The formatter is able to filter sensitive data based on the input provided.
|
data/lib/ama/logger.rb
CHANGED
@@ -29,6 +29,12 @@ module Ama
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def json(io = STDOUT, *args)
|
33
|
+
::Logger.new(io, *args).tap do |instance|
|
34
|
+
instance.formatter = Ama::Logger::Formatter::Json.new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
32
38
|
def stringified_hash(base, opts = {})
|
33
39
|
base.dup.tap do |instance|
|
34
40
|
instance.formatter = Ama::Logger::Formatter::StringifiedHash.new(opts)
|
data/lib/ama/logger/base.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ama
|
4
|
+
module Logger
|
5
|
+
module Formatter
|
6
|
+
class Json
|
7
|
+
def call(severity, time, _progname, msg = {})
|
8
|
+
invalid_argument!(:msg, Hash, msg) unless msg.is_a?(Hash)
|
9
|
+
|
10
|
+
event_name = msg.fetch(:event_name) { missing_argument!(:event_name) }
|
11
|
+
event_source = msg.fetch(:event_source) { missing_argument!(:event_source) }
|
12
|
+
event_id = msg.fetch(:event_id) { missing_argument!(:event_id) }
|
13
|
+
|
14
|
+
{
|
15
|
+
exception: msg[:exception],
|
16
|
+
eventName: event_name,
|
17
|
+
eventSource: event_source.to_s,
|
18
|
+
eventId: event_id.to_s,
|
19
|
+
eventAgent: Ama::Logger::AGENT_VERSION,
|
20
|
+
details: details(msg),
|
21
|
+
indexed: indexed(msg),
|
22
|
+
severity: severity,
|
23
|
+
timestamp: time.utc.iso8601
|
24
|
+
}
|
25
|
+
.compact
|
26
|
+
.to_json
|
27
|
+
.concat("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def details(data = {})
|
33
|
+
data.fetch(:details) { {} }.to_json
|
34
|
+
end
|
35
|
+
|
36
|
+
def indexed(opts = {})
|
37
|
+
data = opts.slice(:metric_name, :metric_value, :metric_content)
|
38
|
+
|
39
|
+
{
|
40
|
+
metricName: data[:metric_name]&.to_s,
|
41
|
+
metricValue: data[:metric_value]&.to_i,
|
42
|
+
metricContent: data[:metric_content]&.to_s
|
43
|
+
}
|
44
|
+
.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
def missing_argument!(name)
|
48
|
+
raise ArgumentError, "must pass the `#{name}` argument"
|
49
|
+
end
|
50
|
+
|
51
|
+
def invalid_argument!(name, klass, value)
|
52
|
+
raise ArgumentError, "expected type `#{klass.inspect}` for argument `#{name}` - got `#{value.inspect}`"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/ama/logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ama_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Doyle
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2019-
|
15
|
+
date: 2019-12-30 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bundler
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- bin/setup
|
140
140
|
- lib/ama/logger.rb
|
141
141
|
- lib/ama/logger/base.rb
|
142
|
+
- lib/ama/logger/formatter/json.rb
|
142
143
|
- lib/ama/logger/formatter/lambda.rb
|
143
144
|
- lib/ama/logger/formatter/stringified_hash.rb
|
144
145
|
- lib/ama/logger/version.rb
|
@@ -162,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
162
163
|
- !ruby/object:Gem::Version
|
163
164
|
version: '0'
|
164
165
|
requirements: []
|
165
|
-
|
166
|
-
rubygems_version: 2.5.2.3
|
166
|
+
rubygems_version: 3.1.2
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: Implementation of AMA's standard logging format
|