hatchet 0.0.18 → 0.0.19
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.
- data/RELEASE.md +6 -0
- data/lib/hatchet/plain_formatter.rb +20 -1
- data/lib/hatchet/simple_formatter.rb +20 -2
- data/lib/hatchet/standard_formatter.rb +15 -2
- data/lib/hatchet/version.rb +1 -1
- data/spec/plain_formatter_spec.rb +45 -4
- data/spec/simple_formatter_spec.rb +43 -4
- data/spec/standard_formatter_spec.rb +34 -1
- metadata +2 -2
data/RELEASE.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Release notes
|
2
2
|
|
3
|
+
## 0.0.19
|
4
|
+
|
5
|
+
* Changed core formatters to output an indented backtrace after a message when
|
6
|
+
an error is present, can be disabled via the formatter's `backtrace=`
|
7
|
+
attribute
|
8
|
+
|
3
9
|
## 0.0.18
|
4
10
|
|
5
11
|
* Made the presence of a `formatter=` method on appenders optional
|
@@ -9,6 +9,17 @@ module Hatchet
|
|
9
9
|
#
|
10
10
|
class PlainFormatter
|
11
11
|
|
12
|
+
# Public: Gets or sets whether backtraces should be output when messages
|
13
|
+
# contain an error with one.
|
14
|
+
#
|
15
|
+
attr_accessor :backtrace
|
16
|
+
|
17
|
+
# Public: Creates a new instance.
|
18
|
+
#
|
19
|
+
def initialize
|
20
|
+
self.backtrace = true
|
21
|
+
end
|
22
|
+
|
12
23
|
# Public: Returns the formatted message.
|
13
24
|
#
|
14
25
|
# level - The severity of the log message.
|
@@ -18,9 +29,17 @@ module Hatchet
|
|
18
29
|
# Returns messages in the format:
|
19
30
|
#
|
20
31
|
# MESSAGE
|
32
|
+
# BACKTRACE
|
33
|
+
#
|
34
|
+
# The backtrace is only present if the message contains an error.
|
21
35
|
#
|
22
36
|
def format(level, context, message)
|
23
|
-
message.
|
37
|
+
unless self.backtrace && message.error && message.error.respond_to?(:backtrace)
|
38
|
+
message.to_s
|
39
|
+
else
|
40
|
+
indented_backtrace = message.error.backtrace.map { |line| " #{line}" }.to_a
|
41
|
+
([message.to_s] + indented_backtrace).join "\n"
|
42
|
+
end
|
24
43
|
end
|
25
44
|
|
26
45
|
end
|
@@ -7,6 +7,17 @@ module Hatchet
|
|
7
7
|
#
|
8
8
|
class SimpleFormatter
|
9
9
|
|
10
|
+
# Public: Gets or sets whether backtraces should be output when messages
|
11
|
+
# contain an error with one.
|
12
|
+
#
|
13
|
+
attr_accessor :backtrace
|
14
|
+
|
15
|
+
# Public: Creates a new instance.
|
16
|
+
#
|
17
|
+
def initialize
|
18
|
+
self.backtrace = true
|
19
|
+
end
|
20
|
+
|
10
21
|
# Public: Returns the formatted message.
|
11
22
|
#
|
12
23
|
# level - The severity of the log message.
|
@@ -16,10 +27,17 @@ module Hatchet
|
|
16
27
|
# Returns messages in the format:
|
17
28
|
#
|
18
29
|
# LEVEL - CONTEXT - MESSAGE
|
30
|
+
# BACKTRACE
|
31
|
+
#
|
32
|
+
# The backtrace is only present if the message contains an error.
|
19
33
|
#
|
20
34
|
def format(level, context, message)
|
21
|
-
|
22
|
-
|
35
|
+
msg = message.to_s.strip
|
36
|
+
if self.backtrace && message.error && message.error.respond_to?(:backtrace)
|
37
|
+
indented_backtrace = message.error.backtrace.map { |line| " #{line}" }.to_a
|
38
|
+
msg = ([msg] + indented_backtrace).join("\n")
|
39
|
+
end
|
40
|
+
"#{level.to_s.upcase} - #{context} - #{msg}"
|
23
41
|
end
|
24
42
|
|
25
43
|
end
|
@@ -6,10 +6,16 @@ module Hatchet
|
|
6
6
|
#
|
7
7
|
class StandardFormatter
|
8
8
|
|
9
|
+
# Public: Gets or sets whether backtraces should be output when messages
|
10
|
+
# contain an error with one.
|
11
|
+
#
|
12
|
+
attr_accessor :backtrace
|
13
|
+
|
9
14
|
# Public: Creates a new instance.
|
10
15
|
#
|
11
16
|
def initialize
|
12
17
|
@secs = 0
|
18
|
+
self.backtrace = true
|
13
19
|
end
|
14
20
|
|
15
21
|
# Public: Returns the formatted message.
|
@@ -21,10 +27,17 @@ module Hatchet
|
|
21
27
|
# Returns messages in the format:
|
22
28
|
#
|
23
29
|
# %Y-%m-%d %H:%M:%S.%L [THREAD] LEVEL CONTEXT - MESSAGE
|
30
|
+
# BACKTRACE
|
31
|
+
#
|
32
|
+
# The backtrace is only present if the message contains an error.
|
24
33
|
#
|
25
34
|
def format(level, context, message)
|
26
|
-
|
27
|
-
|
35
|
+
msg = message.to_s.strip
|
36
|
+
if self.backtrace && message.error && message.error.respond_to?(:backtrace)
|
37
|
+
indented_backtrace = message.error.backtrace.map { |line| " #{line}" }.to_a
|
38
|
+
msg = ([msg] + indented_backtrace).join("\n")
|
39
|
+
end
|
40
|
+
"#{timestamp} [#{thread_name}] #{format_level level} #{context} - #{msg}"
|
28
41
|
end
|
29
42
|
|
30
43
|
private
|
data/lib/hatchet/version.rb
CHANGED
@@ -6,13 +6,54 @@ describe PlainFormatter do
|
|
6
6
|
let(:subject) { PlainFormatter.new }
|
7
7
|
|
8
8
|
describe 'when formatting a message' do
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
describe 'without an error' do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@message = Message.new(' Hello, World ')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'outputs the message in the MESSAGE format' do
|
17
|
+
message = subject.format(:info, 'Custom::Context', @message)
|
18
|
+
assert ' Hello, World ' == message, "got #{message}"
|
19
|
+
end
|
20
|
+
|
11
21
|
end
|
12
22
|
|
13
|
-
|
14
|
-
|
23
|
+
describe 'with an error' do
|
24
|
+
|
25
|
+
before do
|
26
|
+
error = OpenStruct.new(message: 'Boom!', backtrace: ['foo.rb:1:a', 'foo.rb:20:b'])
|
27
|
+
@message = Message.new(' Hello, World ', error)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with backtraces enabled' do
|
31
|
+
|
32
|
+
it 'outputs the message in the MESSAGE format' do
|
33
|
+
message = subject.format(:info, 'Custom::Context', @message)
|
34
|
+
assert_equal %q{ Hello, World
|
35
|
+
foo.rb:1:a
|
36
|
+
foo.rb:20:b}, message
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'with backtraces disabled' do
|
42
|
+
|
43
|
+
before do
|
44
|
+
subject.backtrace = false
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'outputs the message in the MESSAGE format' do
|
48
|
+
message = subject.format(:info, 'Custom::Context', @message)
|
49
|
+
assert ' Hello, World ' == message, "got #{message}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
15
54
|
end
|
55
|
+
|
16
56
|
end
|
57
|
+
|
17
58
|
end
|
18
59
|
|
@@ -6,12 +6,51 @@ describe SimpleFormatter do
|
|
6
6
|
let(:subject) { SimpleFormatter.new }
|
7
7
|
|
8
8
|
describe 'when formatting a message' do
|
9
|
-
|
10
|
-
|
9
|
+
|
10
|
+
describe 'without an error' do
|
11
|
+
|
12
|
+
before do
|
13
|
+
@message = Message.new(' Hello, World ')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'outputs the message in the LEVEL - CONTEXT - MESSAGE format' do
|
17
|
+
message = subject.format(:info, 'Custom::Context', @message)
|
18
|
+
assert 'INFO - Custom::Context - Hello, World' == message, "got #{message}"
|
19
|
+
end
|
20
|
+
|
11
21
|
end
|
12
22
|
|
13
|
-
|
14
|
-
|
23
|
+
describe 'with an error' do
|
24
|
+
|
25
|
+
before do
|
26
|
+
error = OpenStruct.new(message: 'Boom!', backtrace: ['foo.rb:1:a', 'foo.rb:20:b'])
|
27
|
+
@message = Message.new(' Hello, World ', error)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'with backtraces enabled' do
|
31
|
+
|
32
|
+
it 'outputs the message in the LEVEL - CONTEXT - MESSAGE format' do
|
33
|
+
message = subject.format(:info, 'Custom::Context', @message)
|
34
|
+
assert_equal %q{INFO - Custom::Context - Hello, World
|
35
|
+
foo.rb:1:a
|
36
|
+
foo.rb:20:b}, message
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'with backtraces disabled' do
|
42
|
+
|
43
|
+
before do
|
44
|
+
subject.backtrace = false
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'outputs the message in the LEVEL - CONTEXT - MESSAGE format' do
|
48
|
+
message = subject.format(:info, 'Custom::Context', @message)
|
49
|
+
assert 'INFO - Custom::Context - Hello, World' == message, "got #{message}"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
15
54
|
end
|
16
55
|
end
|
17
56
|
end
|
@@ -10,7 +10,7 @@ describe StandardFormatter do
|
|
10
10
|
|
11
11
|
describe 'when formatting a message' do
|
12
12
|
before do
|
13
|
-
@message = 'Hello, World'
|
13
|
+
@message = Message.new('Hello, World')
|
14
14
|
@context = 'Custom::Context'
|
15
15
|
@level = :info
|
16
16
|
@formatted_message = subject.format(@level, @context, @message)
|
@@ -54,6 +54,39 @@ describe StandardFormatter do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
describe 'with an error' do
|
58
|
+
|
59
|
+
before do
|
60
|
+
error = OpenStruct.new(message: 'Boom!', backtrace: ['foo.rb:1:a', 'foo.rb:20:b'])
|
61
|
+
@message = Message.new(' Hello, World ', error)
|
62
|
+
end
|
63
|
+
|
64
|
+
describe 'with backtraces enabled' do
|
65
|
+
|
66
|
+
it 'outputs the message in the LEVEL - CONTEXT - MESSAGE format' do
|
67
|
+
formatted_message = subject.format(@level, @context, @message)
|
68
|
+
backtrace = formatted_message.split("\n").drop(1)
|
69
|
+
assert_equal [' foo.rb:1:a', ' foo.rb:20:b'], backtrace
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
describe 'with backtraces disabled' do
|
75
|
+
|
76
|
+
before do
|
77
|
+
subject.backtrace = false
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'outputs the message in the LEVEL - CONTEXT - MESSAGE format' do
|
81
|
+
formatted_message = subject.format(@level, @context, @message)
|
82
|
+
backtrace = formatted_message.split("\n").drop(1)
|
83
|
+
assert_empty backtrace
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
57
90
|
if ENV["BENCH"] then
|
58
91
|
|
59
92
|
describe 'benchmarks' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hatchet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Logging library that provides the ability to add class/module specific
|
15
15
|
filters
|