twiglet 2.3.9 → 2.3.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd37b7e4eb03587c77c448d986a57dea2db5c119208c9588d400614785c9ab00
4
- data.tar.gz: 2087e6acf11a7944083c81a493f8dc1608f8789ea5e5fb09cdbe8fbad7391456
3
+ metadata.gz: 113edbe5053c76bc7490f90c4e3d85e68077547d26d9dc4e6e98ea474cc5beea
4
+ data.tar.gz: 94b8925876c5cc095db0f5a8380701ebd9e85d22dbca3bf2aa91cd46012920db
5
5
  SHA512:
6
- metadata.gz: 15599c765672e0bcbdbd03f717dde89ccb99ac2142bbb9aad56337466f31c0e9355aa18cd07b4f6cbe9cf53768d9e8efc59042c98aa66aacf82a3ce4e1296993
7
- data.tar.gz: 67c1dae018c5fa57e4bffc0144b58ae5e9316faf4a1190d919d5828a44240955d246a12e6dde07b34b459694eb4808ac81d02fe2b08bc0187dce3562c8d94e6f
6
+ metadata.gz: 38f61f947ee52bfd29a0990d9dd2624ae68f628e66ecb2e67569499e3d7a81459f66d0316c9edd4ec45b2d514707474a91c0d6bd2c7661646d21ad0322a40f33
7
+ data.tar.gz: 20afdfefcd5b37363eca9797472bf1fb9f0947af68b53e994786671a69c2d26acce667351794c2e5540de786115c95cec34b8d8a52d16a206128a88382d71ff2
data/README.md CHANGED
@@ -42,9 +42,10 @@ This will write to STDOUT a JSON string:
42
42
 
43
43
  Obviously the timestamp will be different.
44
44
 
45
- Alternatively, if you just want to log some error message in text format
45
+ Alternatively, if you just want to log some error string:
46
+
46
47
  ```ruby
47
- logger.error( "Emergency! There's an Emergency going on")
48
+ logger.error("Emergency! There's an Emergency going on")
48
49
  ```
49
50
 
50
51
  This will write to STDOUT a JSON string:
@@ -53,11 +54,22 @@ This will write to STDOUT a JSON string:
53
54
  {"service":{"name":"service name"},"@timestamp":"2020-05-14T10:54:59.164+01:00","log":{"level":"error"}, "message":"Emergency! There's an Emergency going on"}
54
55
  ```
55
56
 
56
- Errors can be logged as well, and this will log the error message and backtrace in the relevant ECS compliant fields:
57
+ A message is always required unless a block is provided. The message can be an object or a string.
58
+
59
+ An optional error can also be provided, in which case the error message and backtrace will be logged in the relevant ECS compliant fields:
57
60
 
58
61
  ```ruby
59
62
  db_err = StandardError.new('Connection timed-out')
60
63
  logger.error({ message: 'DB connection failed.' }, db_err)
64
+
65
+ # this is also valid
66
+ logger.error('DB connection failed.', db_err)
67
+ ```
68
+
69
+ These will both result in the same JSON string written to STDOUT:
70
+
71
+ ```json
72
+ {"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"}}
61
73
  ```
62
74
 
63
75
  Add log event specific information simply as attributes in a hash:
@@ -81,18 +93,18 @@ This writes:
81
93
  {"service":{"name":"service name"},"@timestamp":"2020-05-14T10:56:49.527+01:00","log":{"level":"info"},"event":{"action":"HTTP request"},"message":"GET /pets success","trace":{"id":"1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb"},"http":{"request":{"method":"get"},"response":{"status_code":200}},"url":{"path":"/pets"}}
82
94
  ```
83
95
 
84
- Similar to error you can use text logging here as:
96
+ Similar to error you can use string logging here as:
85
97
 
86
98
  ```
87
99
  logger.info('GET /pets success')
88
100
  ```
101
+
89
102
  This writes:
90
103
 
91
104
  ```json
92
105
  {"service":{"name":"service name"},"@timestamp":"2020-05-14T10:56:49.527+01:00","log":{"level":"info"}}
93
106
  ```
94
107
 
95
-
96
108
  It may be that when making a series of logs that write information about a single event, you may want to avoid duplication by creating an event specific logger that includes the context:
97
109
 
98
110
  ```ruby
@@ -29,7 +29,7 @@ module Twiglet
29
29
  super(output, formatter: formatter, level: level)
30
30
  end
31
31
 
32
- def error(message = {}, error = nil, &block)
32
+ def error(message = nil, error = nil, &block)
33
33
  if error
34
34
  error_fields = {
35
35
  'error': {
@@ -37,7 +37,7 @@ module Twiglet
37
37
  }
38
38
  }
39
39
  add_stack_trace(error_fields, error)
40
- message.is_a?(Hash) ? message.merge!(error_fields) : error_fields.merge!(message: message)
40
+ message = message.is_a?(Hash) ? message.merge(error_fields) : error_fields.merge(message: message)
41
41
  end
42
42
 
43
43
  super(message, &block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Twiglet
4
- VERSION = '2.3.9'
4
+ VERSION = '2.3.10'
5
5
  end
@@ -230,6 +230,16 @@ describe Twiglet::Logger do
230
230
  refute actual_log[:error].key?(:stack_trace)
231
231
  end
232
232
 
233
+ it 'should log an error with string message' do
234
+ e = StandardError.new('Unknown error')
235
+ @logger.error('Artificially raised exception with string message', e)
236
+
237
+ actual_log = read_json(@buffer)
238
+
239
+ assert_equal 'Artificially raised exception with string message', actual_log[:message]
240
+ assert_equal 'Unknown error', actual_log[:error][:message]
241
+ end
242
+
233
243
  LEVELS.each do |attrs|
234
244
  it "should correctly log level when calling #{attrs[:method]}" do
235
245
  @logger.public_send(attrs[:method], {message: 'a log message'})
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: 2.3.9
4
+ version: 2.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simply Business
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-13 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Like a log, only smaller.
14
14
  email: