twiglet 3.2.0 → 3.2.1
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 +4 -4
- data/README.md +66 -1
- data/lib/twiglet/version.rb +1 -1
- 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: 64fa676db51b4a53f17a7f1ff578ba00b670c2df9100b6972f2cf4b6fb51c1fc
|
4
|
+
data.tar.gz: 014044c6cccb28d13d019a26715ad83a5532e38b5f4df7ecf9a9a211eaec6751
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d771c2182011b62d5d5af36a55fb04069a2f19805733df475b2f8d0e93e9ccdffdbac81c24eda8ba2081950812b94f87673c931776b65a125fb973106ce1210
|
7
|
+
data.tar.gz: 01c66f316cabc1b1169d35ca224d2c35f5e79efab580df3c530deaddcf30f8b23a46549ffc46140540408fc8c60c916ea72cb1c67122d32233b633786c8289c8
|
data/README.md
CHANGED
@@ -144,7 +144,72 @@ logger.formatter
|
|
144
144
|
Take a look at this sample [Rack application](examples/rack/example_rack_app.rb#L15) with an ECS compliant
|
145
145
|
[request logger](/examples/rack/request_logger.rb) as a template when configuring your own request logging middleware with Twiglet.
|
146
146
|
|
147
|
-
|
147
|
+
### Log format validation
|
148
|
+
Twiglet allows for the configuration of a custom validation schema. The validation schema must be [JSON Schema](https://json-schema.org/) compliant. Any fields not explicitly included in the provided schema are permitted by default.
|
149
|
+
|
150
|
+
For example, given the following JSON Schema:
|
151
|
+
```ruby
|
152
|
+
validation_schema = <<-JSON
|
153
|
+
{
|
154
|
+
"type": "object",
|
155
|
+
"required": ["pet"],
|
156
|
+
"properties": {
|
157
|
+
"pet": {
|
158
|
+
"type": "object",
|
159
|
+
"required": ["name", "best_boy_or_girl?"],
|
160
|
+
"properties": {
|
161
|
+
"name": {
|
162
|
+
"type": "string",
|
163
|
+
"minLength": 1
|
164
|
+
},
|
165
|
+
"good_boy?": {
|
166
|
+
"type": "boolean"
|
167
|
+
}
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
JSON
|
173
|
+
```
|
174
|
+
|
175
|
+
The logger can be instantiated with the custom schema
|
176
|
+
```ruby
|
177
|
+
custom_logger = Twiglet::Logger.new('service name', validation_schema: validation_schema)
|
178
|
+
```
|
179
|
+
|
180
|
+
Compliant log messages will log as normal.
|
181
|
+
```ruby
|
182
|
+
# this is compliant
|
183
|
+
custom_logger.debug(pet: { name: 'Davis', good_boy?: true })
|
184
|
+
|
185
|
+
# the result
|
186
|
+
{:ecs=>{:version=>"1.5.0"}, :@timestamp=>"2020-05-11T15:01:01.000Z", :service=>{:name=>"petshop"}, :log=>{:level=>"debug"}, :pet=>{:name=>"Davis", :good_boy?=>true}}
|
187
|
+
```
|
188
|
+
|
189
|
+
Non compliant messages will raise an error.
|
190
|
+
```ruby
|
191
|
+
begin
|
192
|
+
custom_logger.debug(pet: { name: 'Davis' })
|
193
|
+
rescue JSON::Schema::ValidationError
|
194
|
+
# we forgot to specify that he's a good boy!
|
195
|
+
puts 'uh-oh'
|
196
|
+
end
|
197
|
+
```
|
198
|
+
|
199
|
+
#### Customizing error responses
|
200
|
+
Depending on the application, it may not be desirable for the logger to raise Runtime errors. Twiglet allows you to configure a custom response for handling validation errors.
|
201
|
+
|
202
|
+
Configure error handling by writing a block
|
203
|
+
```ruby
|
204
|
+
logger.configure_validation_error_response do |error|
|
205
|
+
# validation error handling goes here
|
206
|
+
# for example:
|
207
|
+
{YOUR APPLICATION BUG TRACKING SERVICE}.notify_error(error)
|
208
|
+
end
|
209
|
+
|
210
|
+
```
|
211
|
+
|
212
|
+
### Use of dotted keys (DEPRECATED)
|
148
213
|
|
149
214
|
Writing nested json objects could be confusing. This library has a built-in feature to convert dotted keys into nested objects, so if you log like this:
|
150
215
|
|
data/lib/twiglet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twiglet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.2.
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simply Business
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|