twiglet 2.0.0.pre.alpha.1 → 2.0.0
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.
- checksums.yaml +4 -4
- data/.github/CODEOWNERS +0 -1
- data/README.md +8 -1
- data/lib/twiglet/logger.rb +6 -2
- data/lib/twiglet/version.rb +1 -1
- data/test/logger_test.rb +20 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f7e6901994e7715bab639be94853dbbcce697e16da26f2f8340404ebe4c0211
|
4
|
+
data.tar.gz: 1758572f62c689a68642cfb8887dc2ea380a3602332cf2321b06d51e80a7066d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808fb4ddbdaff2287331e022ec4a593469335a40476fa59cb0546facd126113c6b564f7538c3366984bb40ed178a131861b0a97e9ea571640caa68db0354a906
|
7
|
+
data.tar.gz: 83913e66900495ee39ba12d8f38e16e83fbc3621c4caf7bdaa128c6b44568f82face4498f1b2081e798ff6265b79a7758dd97eff08bd6224e8b0b7d077e8cb81
|
data/.github/CODEOWNERS
CHANGED
data/README.md
CHANGED
@@ -40,6 +40,13 @@ This will write to STDOUT a JSON string:
|
|
40
40
|
|
41
41
|
Obviously the timestamp will be different.
|
42
42
|
|
43
|
+
Errors can be logged as well, and this will log the error message and backtrace in the relevant ECS compliant fields:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
db_err = StandardError.new('Connection timed-out')
|
47
|
+
logger.error({ message: 'DB connection failed.' }, db_err)
|
48
|
+
```
|
49
|
+
|
43
50
|
Add log event specific information simply as attributes in a hash:
|
44
51
|
|
45
52
|
```ruby
|
@@ -126,7 +133,7 @@ First: Please read our project [Code of Conduct](../CODE_OF_CONDUCT.md).
|
|
126
133
|
Second: run the tests and make sure your changes don't break anything:
|
127
134
|
|
128
135
|
```bash
|
129
|
-
|
136
|
+
bundle exec rake test
|
130
137
|
```
|
131
138
|
|
132
139
|
Then please feel free to submit a PR.
|
data/lib/twiglet/logger.rb
CHANGED
@@ -36,11 +36,15 @@ module Twiglet
|
|
36
36
|
log(level: 'warning', message: message)
|
37
37
|
end
|
38
38
|
|
39
|
+
alias_method :warn, :warning
|
40
|
+
|
39
41
|
def error(message, error = nil)
|
40
42
|
if error
|
41
43
|
message = message.merge({
|
42
|
-
|
43
|
-
|
44
|
+
'error': {
|
45
|
+
'message': error.message,
|
46
|
+
'stack_trace': error.backtrace.join("\n")
|
47
|
+
}
|
44
48
|
})
|
45
49
|
end
|
46
50
|
|
data/lib/twiglet/version.rb
CHANGED
data/test/logger_test.rb
CHANGED
@@ -178,8 +178,26 @@ describe Twiglet::Logger do
|
|
178
178
|
actual_log = read_json(@buffer)
|
179
179
|
|
180
180
|
assert_equal 'Artificially raised exception', actual_log[:message]
|
181
|
-
assert_equal 'divided by 0', actual_log[:
|
182
|
-
assert_match 'logger_test.rb', actual_log[:
|
181
|
+
assert_equal 'divided by 0', actual_log[:error][:message]
|
182
|
+
assert_match 'logger_test.rb', actual_log[:error][:stack_trace].lines.first
|
183
|
+
end
|
184
|
+
|
185
|
+
levels = [
|
186
|
+
{ method: :debug, level: 'debug' },
|
187
|
+
{ method: :info, level: 'info' },
|
188
|
+
{ method: :warning, level: 'warning' },
|
189
|
+
{ method: :warn, level: 'warning' },
|
190
|
+
{ method: :error, level: 'error' }
|
191
|
+
]
|
192
|
+
|
193
|
+
levels.each do |attrs|
|
194
|
+
it "should correctly log level when calling #{attrs[:method]}" do
|
195
|
+
@logger.public_send(attrs[:method], {message: 'a log message'})
|
196
|
+
actual_log = read_json(@buffer)
|
197
|
+
|
198
|
+
assert_equal attrs[:level], actual_log[:log][:level]
|
199
|
+
assert_equal 'a log message', actual_log[:message]
|
200
|
+
end
|
183
201
|
end
|
184
202
|
|
185
203
|
private
|
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.0.0
|
4
|
+
version: 2.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-06-
|
11
|
+
date: 2020-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Like a log, only smaller.
|
14
14
|
email:
|
@@ -51,9 +51,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '2.6'
|
52
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
|
-
- - "
|
54
|
+
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: '0'
|
57
57
|
requirements: []
|
58
58
|
rubygems_version: 3.1.2
|
59
59
|
signing_key:
|