twiglet 2.3.8 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/.github/workflows/version-forget-me-not.yml +2 -13
- data/.rubocop.yml +1 -1
- data/Gemfile +1 -1
- data/Makefile +15 -3
- data/README.md +17 -5
- data/example_app.rb +25 -25
- data/lib/hash_extensions.rb +3 -3
- data/lib/twiglet/formatter.rb +2 -27
- data/lib/twiglet/logger.rb +4 -2
- data/lib/twiglet/message.rb +24 -0
- data/lib/twiglet/version.rb +1 -1
- data/test/logger_test.rb +74 -57
- data/test/message_test.rb +31 -0
- data/twiglet.gemspec +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3d278f5c152781abb779db8f28f7297f52c4d76db5358a78f13e784475f4851
|
4
|
+
data.tar.gz: bd8e3ae4b640ade3cb57489216cbdc7aec383f5535946c328352cc350057474c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef689b0df5314da2ddb0e5ed95a724d25f0f5c93f2f9647478d7f9eb60acb60b7b712c731b4118087d28f32685cc91bdb032f73e7438a822ad8fc7be7e742dd4
|
7
|
+
data.tar.gz: 2bc88df6d4f6a7cd4c0304eeafa199384054c58cc6f39629daec456605c72397302a49380f8bf681645654b030bc59b7d458ac45ca42091558711ea9980b6580
|
data/.github/workflows/ruby.yml
CHANGED
@@ -3,25 +3,14 @@ name: Check version
|
|
3
3
|
on:
|
4
4
|
pull_request:
|
5
5
|
branches:
|
6
|
-
- master
|
6
|
+
- master
|
7
7
|
types: [opened, synchronize]
|
8
8
|
jobs:
|
9
9
|
build:
|
10
10
|
runs-on: ubuntu-18.04
|
11
11
|
|
12
12
|
steps:
|
13
|
-
|
14
|
-
# We can remove this once we make the action public.
|
15
|
-
- uses: actions/checkout@v1
|
16
|
-
with:
|
17
|
-
repository: simplybusiness/version-forget-me-not
|
18
|
-
ref: refs/tags/v1.0
|
19
|
-
# Do not put the actual secret here- only the name of the secret in your repo
|
20
|
-
token: ${{ secrets.BOT_TOKEN }}
|
21
|
-
path: './twiglet-ruby'
|
22
|
-
- uses: ./
|
13
|
+
- uses: simplybusiness/version-forget-me-not@v1
|
23
14
|
env:
|
24
15
|
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
25
|
-
# It is the file path where you keep the version of gem.
|
26
|
-
# It usually in the `lib/<gem name>/version.rb` or in the gemspec file.
|
27
16
|
VERSION_FILE_PATH: "lib/twiglet/version.rb"
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Makefile
CHANGED
@@ -1,9 +1,21 @@
|
|
1
|
-
.PHONY: all build test
|
1
|
+
.PHONY: all build clean shell test
|
2
2
|
|
3
|
-
all: build test
|
3
|
+
all: clean build test
|
4
4
|
|
5
5
|
build:
|
6
6
|
docker build -t simplybusiness/ruby-dev:2.6.5 .
|
7
7
|
|
8
|
+
clean:
|
9
|
+
rm -f *~
|
10
|
+
|
11
|
+
shell:
|
12
|
+
docker run -it \
|
13
|
+
-v `pwd`:/var/app \
|
14
|
+
simplybusiness/ruby-dev:2.6.5 \
|
15
|
+
bash
|
16
|
+
|
8
17
|
test:
|
9
|
-
docker run -it
|
18
|
+
docker run -it \
|
19
|
+
-v `pwd`:/var/app \
|
20
|
+
simplybusiness/ruby-dev:2.6.5 \
|
21
|
+
bundle exec rake test
|
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
|
45
|
+
Alternatively, if you just want to log some error string:
|
46
|
+
|
46
47
|
```ruby
|
47
|
-
logger.error(
|
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
|
-
|
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
|
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
|
data/example_app.rb
CHANGED
@@ -8,27 +8,27 @@ logger = Twiglet::Logger.new('petshop')
|
|
8
8
|
|
9
9
|
# Start our petshop
|
10
10
|
logger.info({
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
event: {
|
12
|
+
action: 'startup'
|
13
|
+
},
|
14
|
+
message: "Ready to go, listening on port #{PORT}",
|
15
|
+
server: {
|
16
|
+
port: PORT
|
17
|
+
}
|
18
|
+
})
|
19
19
|
|
20
20
|
# Use text logging
|
21
21
|
logger.info("Ready to go, listening on port #{PORT}")
|
22
22
|
#
|
23
23
|
# We get a request
|
24
24
|
request_logger = logger.with({
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
event: {
|
26
|
+
action: 'HTTP request'
|
27
|
+
},
|
28
|
+
trace: {
|
29
|
+
id: '126bb6fa-28a2-470f-b013-eefbf9182b2d'
|
30
|
+
}
|
31
|
+
})
|
32
32
|
|
33
33
|
# Oh noes!
|
34
34
|
db_err = StandardError.new('Connection timed-out')
|
@@ -37,16 +37,16 @@ request_logger.error({ message: 'DB connection failed.' }, db_err) if db_err
|
|
37
37
|
|
38
38
|
# We return an error to the requester
|
39
39
|
request_logger.info({
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
40
|
+
message: 'Internal Server Error',
|
41
|
+
http: {
|
42
|
+
request: {
|
43
|
+
method: 'get'
|
44
|
+
},
|
45
|
+
response: {
|
46
|
+
status_code: 500
|
47
|
+
}
|
48
|
+
}
|
49
|
+
})
|
50
50
|
|
51
51
|
# Logging with an empty message is an anti-pattern and is therefore forbidden
|
52
52
|
# Both of the following lines would throw an error
|
data/lib/hash_extensions.rb
CHANGED
@@ -22,8 +22,8 @@ module HashExtensions
|
|
22
22
|
|
23
23
|
def build_nested_object(key, val)
|
24
24
|
key.to_s
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
.split('.')
|
26
|
+
.reverse
|
27
|
+
.reduce(val) { |nested, key_part| Hash[key_part.to_sym, nested] }
|
28
28
|
end
|
29
29
|
end
|
data/lib/twiglet/formatter.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require_relative '../hash_extensions'
|
3
|
+
require_relative 'message'
|
3
4
|
|
4
5
|
module Twiglet
|
5
6
|
class Formatter < ::Logger::Formatter
|
@@ -17,38 +18,12 @@ module Twiglet
|
|
17
18
|
|
18
19
|
def call(severity, _time, _progname, msg)
|
19
20
|
level = severity.downcase
|
20
|
-
log(level: level, message: msg)
|
21
|
+
log(level: level, message: Message.new(msg))
|
21
22
|
end
|
22
23
|
|
23
24
|
private
|
24
25
|
|
25
26
|
def log(level:, message:)
|
26
|
-
case message
|
27
|
-
when String
|
28
|
-
log_text(level, message: message)
|
29
|
-
when Hash
|
30
|
-
log_object(level, message: message)
|
31
|
-
else
|
32
|
-
raise('Message must be String or Hash')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def log_text(level, message:)
|
37
|
-
raise('The \'message\' property of log object must not be empty') if message.strip.empty?
|
38
|
-
|
39
|
-
message = { message: message }
|
40
|
-
log_message(level, message: message)
|
41
|
-
end
|
42
|
-
|
43
|
-
def log_object(level, message:)
|
44
|
-
message = message.transform_keys(&:to_sym)
|
45
|
-
message.key?(:message) || raise('Log object must have a \'message\' property')
|
46
|
-
message[:message].strip.empty? && raise('The \'message\' property of log object must not be empty')
|
47
|
-
|
48
|
-
log_message(level, message: message)
|
49
|
-
end
|
50
|
-
|
51
|
-
def log_message(level, message:)
|
52
27
|
base_message = {
|
53
28
|
ecs: {
|
54
29
|
version: '1.5.0'
|
data/lib/twiglet/logger.rb
CHANGED
@@ -5,6 +5,7 @@ require 'time'
|
|
5
5
|
require 'json'
|
6
6
|
require_relative 'formatter'
|
7
7
|
require_relative '../hash_extensions'
|
8
|
+
require_relative 'message'
|
8
9
|
|
9
10
|
module Twiglet
|
10
11
|
class Logger < ::Logger
|
@@ -29,15 +30,16 @@ module Twiglet
|
|
29
30
|
super(output, formatter: formatter, level: level)
|
30
31
|
end
|
31
32
|
|
32
|
-
def error(message =
|
33
|
+
def error(message = nil, error = nil, &block)
|
33
34
|
if error
|
34
35
|
error_fields = {
|
35
36
|
'error': {
|
37
|
+
'type': error.class,
|
36
38
|
'message': error.message
|
37
39
|
}
|
38
40
|
}
|
39
41
|
add_stack_trace(error_fields, error)
|
40
|
-
message
|
42
|
+
message = Message.new(message).merge(error_fields)
|
41
43
|
end
|
42
44
|
|
43
45
|
super(message, &block)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Twiglet
|
2
|
+
class Message < Hash
|
3
|
+
def initialize(msg)
|
4
|
+
case msg
|
5
|
+
when String
|
6
|
+
self[:message] = msg
|
7
|
+
when Hash
|
8
|
+
replace(msg.transform_keys!(&:to_sym))
|
9
|
+
end
|
10
|
+
|
11
|
+
validate!
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def validate!
|
17
|
+
raise 'Message must be initialized with a String or a non-empty Hash' if empty?
|
18
|
+
|
19
|
+
raise 'Log object must have a \'message\' property' unless self[:message]
|
20
|
+
|
21
|
+
raise 'The \'message\' property of the log object must not be empty' if self[:message].strip.empty?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/twiglet/version.rb
CHANGED
data/test/logger_test.rb
CHANGED
@@ -3,6 +3,16 @@
|
|
3
3
|
require 'minitest/autorun'
|
4
4
|
require_relative '../lib/twiglet/logger'
|
5
5
|
|
6
|
+
LEVELS = [
|
7
|
+
{ method: :debug, level: 'debug' },
|
8
|
+
{ method: :info, level: 'info' },
|
9
|
+
{ method: :warning, level: 'warn' },
|
10
|
+
{ method: :warn, level: 'warn' },
|
11
|
+
{ method: :critical, level: 'fatal' },
|
12
|
+
{ method: :fatal, level: 'fatal' },
|
13
|
+
{ method: :error, level: 'error' }
|
14
|
+
].freeze
|
15
|
+
|
6
16
|
# rubocop:disable Metrics/BlockLength
|
7
17
|
describe Twiglet::Logger do
|
8
18
|
before do
|
@@ -13,16 +23,6 @@ describe Twiglet::Logger do
|
|
13
23
|
output: @buffer)
|
14
24
|
end
|
15
25
|
|
16
|
-
LEVELS = [
|
17
|
-
{ method: :debug, level: 'debug' },
|
18
|
-
{ method: :info, level: 'info' },
|
19
|
-
{ method: :warning, level: 'warn' },
|
20
|
-
{ method: :warn, level: 'warn' },
|
21
|
-
{ method: :critical, level: 'fatal' },
|
22
|
-
{ method: :fatal, level: 'fatal' },
|
23
|
-
{ method: :error, level: 'error' }
|
24
|
-
].freeze
|
25
|
-
|
26
26
|
it 'should throw an error with an empty service name' do
|
27
27
|
assert_raises RuntimeError do
|
28
28
|
Twiglet::Logger.new(' ')
|
@@ -105,16 +105,16 @@ describe Twiglet::Logger do
|
|
105
105
|
it "should be able to add properties with '.with'" do
|
106
106
|
# Let's add some context to this customer journey
|
107
107
|
purchase_logger = @logger.with({
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
trace: {id: '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb'},
|
109
|
+
customer: {full_name: 'Freda Bloggs'},
|
110
|
+
event: {action: 'pet purchase'}
|
111
|
+
})
|
112
112
|
|
113
113
|
# do stuff
|
114
114
|
purchase_logger.info({
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
message: 'customer bought a dog',
|
116
|
+
pet: {name: 'Barker', species: 'dog', breed: 'Bitsa'}
|
117
|
+
})
|
118
118
|
|
119
119
|
log = read_json @buffer
|
120
120
|
|
@@ -149,39 +149,6 @@ describe Twiglet::Logger do
|
|
149
149
|
assert_equal expected_output, @buffer.string
|
150
150
|
end
|
151
151
|
|
152
|
-
it 'should be able to convert dotted keys to nested objects' do
|
153
|
-
@logger.debug({
|
154
|
-
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
155
|
-
message: 'customer bought a dog',
|
156
|
-
"pet.name": 'Barker',
|
157
|
-
"pet.species": 'dog',
|
158
|
-
"pet.breed": 'Bitsa'
|
159
|
-
})
|
160
|
-
log = read_json(@buffer)
|
161
|
-
|
162
|
-
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
163
|
-
assert_equal 'customer bought a dog', log[:message]
|
164
|
-
assert_equal 'Barker', log[:pet][:name]
|
165
|
-
assert_equal 'dog', log[:pet][:species]
|
166
|
-
assert_equal 'Bitsa', log[:pet][:breed]
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'should be able to mix dotted keys and nested objects' do
|
170
|
-
@logger.debug({
|
171
|
-
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
172
|
-
message: 'customer bought a dog',
|
173
|
-
pet: {name: 'Barker', breed: 'Bitsa'},
|
174
|
-
"pet.species": 'dog'
|
175
|
-
})
|
176
|
-
log = read_json(@buffer)
|
177
|
-
|
178
|
-
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
179
|
-
assert_equal 'customer bought a dog', log[:message]
|
180
|
-
assert_equal 'Barker', log[:pet][:name]
|
181
|
-
assert_equal 'dog', log[:pet][:species]
|
182
|
-
assert_equal 'Bitsa', log[:pet][:breed]
|
183
|
-
end
|
184
|
-
|
185
152
|
it 'should work with mixed string and symbol properties' do
|
186
153
|
log = {
|
187
154
|
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb'
|
@@ -205,6 +172,18 @@ describe Twiglet::Logger do
|
|
205
172
|
assert_equal 'Bitsa', actual_log[:pet][:breed]
|
206
173
|
end
|
207
174
|
|
175
|
+
LEVELS.each do |attrs|
|
176
|
+
it "should correctly log level when calling #{attrs[:method]}" do
|
177
|
+
@logger.public_send(attrs[:method], {message: 'a log message'})
|
178
|
+
actual_log = read_json(@buffer)
|
179
|
+
|
180
|
+
assert_equal attrs[:level], actual_log[:log][:level]
|
181
|
+
assert_equal 'a log message', actual_log[:message]
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
describe 'logging an exception' do
|
208
187
|
it 'should log an error with backtrace' do
|
209
188
|
begin
|
210
189
|
1 / 0
|
@@ -216,6 +195,7 @@ describe Twiglet::Logger do
|
|
216
195
|
|
217
196
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
218
197
|
assert_equal 'divided by 0', actual_log[:error][:message]
|
198
|
+
assert_equal 'ZeroDivisionError', actual_log[:error][:type]
|
219
199
|
assert_match 'logger_test.rb', actual_log[:error][:stack_trace].lines.first
|
220
200
|
end
|
221
201
|
|
@@ -226,18 +206,20 @@ describe Twiglet::Logger do
|
|
226
206
|
actual_log = read_json(@buffer)
|
227
207
|
|
228
208
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
209
|
+
assert_equal 'StandardError', actual_log[:error][:type]
|
229
210
|
assert_equal 'Connection timed-out', actual_log[:error][:message]
|
230
211
|
refute actual_log[:error].key?(:stack_trace)
|
231
212
|
end
|
232
213
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
actual_log = read_json(@buffer)
|
214
|
+
it 'should log an error with string message' do
|
215
|
+
e = StandardError.new('Unknown error')
|
216
|
+
@logger.error('Artificially raised exception with string message', e)
|
237
217
|
|
238
|
-
|
239
|
-
|
240
|
-
|
218
|
+
actual_log = read_json(@buffer)
|
219
|
+
|
220
|
+
assert_equal 'Artificially raised exception with string message', actual_log[:message]
|
221
|
+
assert_equal 'StandardError', actual_log[:error][:type]
|
222
|
+
assert_equal 'Unknown error', actual_log[:error][:message]
|
241
223
|
end
|
242
224
|
end
|
243
225
|
|
@@ -300,6 +282,41 @@ describe Twiglet::Logger do
|
|
300
282
|
end
|
301
283
|
end
|
302
284
|
|
285
|
+
describe 'dotted keys' do
|
286
|
+
it 'should be able to convert dotted keys to nested objects' do
|
287
|
+
@logger.debug({
|
288
|
+
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
289
|
+
message: 'customer bought a dog',
|
290
|
+
"pet.name": 'Barker',
|
291
|
+
"pet.species": 'dog',
|
292
|
+
"pet.breed": 'Bitsa'
|
293
|
+
})
|
294
|
+
log = read_json(@buffer)
|
295
|
+
|
296
|
+
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
297
|
+
assert_equal 'customer bought a dog', log[:message]
|
298
|
+
assert_equal 'Barker', log[:pet][:name]
|
299
|
+
assert_equal 'dog', log[:pet][:species]
|
300
|
+
assert_equal 'Bitsa', log[:pet][:breed]
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'should be able to mix dotted keys and nested objects' do
|
304
|
+
@logger.debug({
|
305
|
+
"trace.id": '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb',
|
306
|
+
message: 'customer bought a dog',
|
307
|
+
pet: {name: 'Barker', breed: 'Bitsa'},
|
308
|
+
"pet.species": 'dog'
|
309
|
+
})
|
310
|
+
log = read_json(@buffer)
|
311
|
+
|
312
|
+
assert_equal '1c8a5fb2-fecd-44d8-92a4-449eb2ce4dcb', log[:trace][:id]
|
313
|
+
assert_equal 'customer bought a dog', log[:message]
|
314
|
+
assert_equal 'Barker', log[:pet][:name]
|
315
|
+
assert_equal 'dog', log[:pet][:species]
|
316
|
+
assert_equal 'Bitsa', log[:pet][:breed]
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
303
320
|
describe 'logger level' do
|
304
321
|
[
|
305
322
|
{ expression: :info, level: 1 },
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require_relative '../lib/twiglet/message'
|
3
|
+
|
4
|
+
describe Twiglet::Message do
|
5
|
+
it 'raises if message is empty' do
|
6
|
+
assert_raises RuntimeError do
|
7
|
+
Twiglet::Message.new(' ')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'raises if message is not provided' do
|
12
|
+
assert_raises RuntimeError do
|
13
|
+
Twiglet::Message.new(foo: 'bar')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'raises on unrecognized inputs' do
|
18
|
+
assert_raises RuntimeError do
|
19
|
+
Twiglet::Message.new(OpenStruct.new(message: 'hello'))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns a message hash from a string' do
|
24
|
+
assert_equal Twiglet::Message.new('hello, world'), { message: 'hello, world' }
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns a message hash with symbolized keys' do
|
28
|
+
input_message = { 'key' => 'value', 'message' => 'hello, world' }
|
29
|
+
assert_equal Twiglet::Message.new(input_message), { key: 'value', message: 'hello, world' }
|
30
|
+
end
|
31
|
+
end
|
data/twiglet.gemspec
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:
|
4
|
+
version: 3.0.0
|
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-
|
11
|
+
date: 2020-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Like a log, only smaller.
|
14
14
|
email:
|
@@ -39,10 +39,12 @@ files:
|
|
39
39
|
- lib/hash_extensions.rb
|
40
40
|
- lib/twiglet/formatter.rb
|
41
41
|
- lib/twiglet/logger.rb
|
42
|
+
- lib/twiglet/message.rb
|
42
43
|
- lib/twiglet/version.rb
|
43
44
|
- test/formatter_test.rb
|
44
45
|
- test/hash_extensions_test.rb
|
45
46
|
- test/logger_test.rb
|
47
|
+
- test/message_test.rb
|
46
48
|
- test/test_coverage.rb
|
47
49
|
- twiglet.gemspec
|
48
50
|
homepage: https://github.com/simplybusiness/twiglet-ruby
|
@@ -57,14 +59,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
57
59
|
requirements:
|
58
60
|
- - ">="
|
59
61
|
- !ruby/object:Gem::Version
|
60
|
-
version: '2.
|
62
|
+
version: '2.6'
|
61
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
64
|
requirements:
|
63
65
|
- - ">="
|
64
66
|
- !ruby/object:Gem::Version
|
65
67
|
version: '0'
|
66
68
|
requirements: []
|
67
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.1.4
|
68
70
|
signing_key:
|
69
71
|
specification_version: 4
|
70
72
|
summary: Twiglet
|