twiglet 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -4
- data/lib/twiglet/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65c3f0028e0ac918736f63a2475fb45231586d51256a8778d4730ebd7792675c
|
4
|
+
data.tar.gz: 98d3607d5e1aad68f00d0ced7ccce24f0dba0c8b3eede84620a4a37a102a9849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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:
|
data/lib/twiglet/version.rb
CHANGED