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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +66 -1
  3. data/lib/twiglet/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6970a1b98fbd77737c3742429691e3c03c7966e894e2f6a523824df785941858
4
- data.tar.gz: 3a878416f432a4c9e38b0299afb6204fd2202168646d028298d40ab2c6cc7746
3
+ metadata.gz: 64fa676db51b4a53f17a7f1ff578ba00b670c2df9100b6972f2cf4b6fb51c1fc
4
+ data.tar.gz: 014044c6cccb28d13d019a26715ad83a5532e38b5f4df7ecf9a9a211eaec6751
5
5
  SHA512:
6
- metadata.gz: 8a2e0c5bd321f495f4cf2c5d69a8caaff889e352305c5a900c1c7415e8637d0127729c91bd030353c1dd3b56e9c5623880f46849d3ff3eac1d502c3df8752c54
7
- data.tar.gz: 0076c02f4070de277e488278f9f858d529b0ab39d8f8c07bc59a9d583c40421f0231b769a7ffb6a6ad1b422ed17f22ee4cd2a7eb68e436dc3b2b6c70c0246c8e
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
- ## Use of dotted keys (DEPRECATED)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '3.2.0'
4
+ VERSION = '3.2.1'
5
5
  end
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.0
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-16 00:00:00.000000000 Z
11
+ date: 2021-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema