twiglet 3.0.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +15 -4
  3. data/lib/twiglet/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3d278f5c152781abb779db8f28f7297f52c4d76db5358a78f13e784475f4851
4
- data.tar.gz: bd8e3ae4b640ade3cb57489216cbdc7aec383f5535946c328352cc350057474c
3
+ metadata.gz: 65c3f0028e0ac918736f63a2475fb45231586d51256a8778d4730ebd7792675c
4
+ data.tar.gz: 98d3607d5e1aad68f00d0ced7ccce24f0dba0c8b3eede84620a4a37a102a9849
5
5
  SHA512:
6
- metadata.gz: ef689b0df5314da2ddb0e5ed95a724d25f0f5c93f2f9647478d7f9eb60acb60b7b712c731b4118087d28f32685cc91bdb032f73e7438a822ad8fc7be7e742dd4
7
- data.tar.gz: 2bc88df6d4f6a7cd4c0304eeafa199384054c58cc6f39629daec456605c72397302a49380f8bf681645654b030bc59b7d458ac45ca42091558711ea9980b6580
6
+ metadata.gz: '0418346dbb4f5d486062caa13b7d1859a96309d00061b3e818563c9c399601f73035e2c89c64888e168d2a040fbb96c18a47e150c505859a58c067cfe46fe76f'
7
+ data.tar.gz: 9437cae3f2662746cd059a660f9e0884c5c0edd7e56de77771d81678c01f6e55006e048b50bd44f7a99d240b9a5d3527b70a15528d0f4e8711ca2e0954c73235
data/README.md CHANGED
@@ -11,13 +11,13 @@ gem install twiglet
11
11
 
12
12
  ## How to use
13
13
 
14
- Create a new logger like so:
14
+ ### Instantiate the logger
15
15
 
16
16
  ```ruby
17
17
  require 'twiglet/logger'
18
18
  logger = Twiglet::Logger.new('service name')
19
19
  ```
20
-
20
+ #### Optional initialization parameters
21
21
  A hash can optionally be passed in as a keyword argument for `default_properties`. This hash must be in the Elastic Common Schema format and will be present in every log message created by this Twiglet logger object.
22
22
 
23
23
  You may also provide an optional `output` keyword argument which should be an object with a `puts` method - like `$stdout`.
@@ -28,7 +28,7 @@ Lastly, you may provide the optional keyword argument `level` to initialize the
28
28
 
29
29
  The defaults for both `output` and `now` should serve for most uses, though you may want to override them for testing as we have done [here](test/logger_test.rb).
30
30
 
31
- To use, simply invoke like most other loggers:
31
+ ### Invoke the Logger
32
32
 
33
33
  ```ruby
34
34
  logger.error({ event: { action: 'startup' }, message: "Emergency! There's an Emergency going on" })
@@ -56,6 +56,7 @@ This will write to STDOUT a JSON string:
56
56
 
57
57
  A message is always required unless a block is provided. The message can be an object or a string.
58
58
 
59
+ #### Error logging
59
60
  An optional error can also be provided, in which case the error message and backtrace will be logged in the relevant ECS compliant fields:
60
61
 
61
62
  ```ruby
@@ -72,7 +73,8 @@ These will both result in the same JSON string written to STDOUT:
72
73
  {"ecs":{"version":"1.5.0"},"@timestamp":"2020-08-21T15:44:37.890Z","service":{"name":"service name"},"log":{"level":"error"},"message":"DB connection failed.","error":{"message":"Connection timed-out"}}
73
74
  ```
74
75
 
75
- Add log event specific information simply as attributes in a hash:
76
+ #### Custom fields
77
+ Log custom event-specific information simply as attributes in a hash:
76
78
 
77
79
  ```ruby
78
80
  logger.info({
@@ -129,6 +131,15 @@ which will print:
129
131
  {"service":{"name":"service name"},"@timestamp":"2020-05-14T10:58:30.780+01:00","log":{"level":"error"},"event":{"action":"HTTP request"},"trace":{"id":"126bb6fa-28a2-470f-b013-eefbf9182b2d"},"message":"Error 500 in /pets/buy","http":{"request":{"method":"post","url.path":"/pet/buy"},"response":{"status_code":500}}}
130
132
  ```
131
133
 
134
+ ### Log formatting
135
+ Some third party applications will allow you to optionally specify a [log formatter](https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger/Formatter.html).
136
+ Supplying a Twiglet log formatter will format those third party logs so that they are ECS compliant and have the same default parameters as your application's internal logs.
137
+
138
+ To access the formatter:
139
+ ```ruby
140
+ logger.formatter
141
+ ```
142
+
132
143
  ## Use of dotted keys (DEPRECATED)
133
144
 
134
145
  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:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '3.0.0'
4
+ VERSION = '3.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twiglet
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business