hatchet 0.2.9 → 0.2.10
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/RELEASE.md +18 -0
- data/lib/hatchet.rb +0 -1
- data/lib/hatchet/configuration.rb +29 -0
- data/lib/hatchet/hatchet_logger.rb +3 -3
- data/lib/hatchet/message.rb +28 -3
- data/lib/hatchet/version.rb +1 -1
- data/spec/logger_spec.rb +2 -1
- data/spec/message_spec.rb +52 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 813a27c38ca53b1f1e669f206c7ba049473b4896
|
4
|
+
data.tar.gz: f805a3480f1075f27109d9063ab37bc6f277b77d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfe4975156aa901ce3fca6a9664b8cc105d2a7ad104c73da53bf60acc9ded2fa567d989f9ec42d91f78d9796ae574efd6b0946c55eca179364df17930f1f2d5
|
7
|
+
data.tar.gz: b2bfbabbd0073e546894474efeff7d7aec1d0c9e0c2e30078870be7fb345fbc49b301539a44f0f505f898732847ef4036fc664a1a2b882bf46f4ee9be09567bb
|
data/RELEASE.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Release notes
|
2
2
|
|
3
|
+
## 0.2.10
|
4
|
+
|
5
|
+
* Introduced the ability to filter backtraces
|
6
|
+
|
7
|
+
Example:
|
8
|
+
|
9
|
+
configuration.configure do |config|
|
10
|
+
config.backtrace_filter '/applications/my_app/releases/current' => '[ROOT]'
|
11
|
+
end
|
12
|
+
|
13
|
+
Will filter a backtrace line like:
|
14
|
+
|
15
|
+
/applications/my_app/releases/current/lib/example.rb:42:in `main'
|
16
|
+
|
17
|
+
Into:
|
18
|
+
|
19
|
+
[ROOT]/lib/example.rb:42:in `main'
|
20
|
+
|
3
21
|
## 0.2.9
|
4
22
|
|
5
23
|
* Fixed a bug where if you specified appender-specific log levels without
|
data/lib/hatchet.rb
CHANGED
@@ -20,6 +20,34 @@ module Hatchet
|
|
20
20
|
reset!
|
21
21
|
end
|
22
22
|
|
23
|
+
# Public: Adds backtrace filters provided in the form of a Hash.
|
24
|
+
#
|
25
|
+
# Each line of the backtrace starting with a key is replaced by its
|
26
|
+
# corresponding value.
|
27
|
+
#
|
28
|
+
# Example
|
29
|
+
#
|
30
|
+
# configuration.configure do |config|
|
31
|
+
# config.backtrace_filter '/applications/my_app/releases/current' => '$ROOT'
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Will filter a backtrace line like:
|
35
|
+
#
|
36
|
+
# /applications/my_app/releases/current/lib/example.rb:42:in `main'
|
37
|
+
#
|
38
|
+
# Into:
|
39
|
+
#
|
40
|
+
# $ROOT/lib/example.rb:42:in `main'
|
41
|
+
#
|
42
|
+
# Returns nothing.
|
43
|
+
#
|
44
|
+
def backtrace_filter(filters = nil)
|
45
|
+
@backtrace_filters.merge!(filters) if filters
|
46
|
+
@backtrace_filters
|
47
|
+
end
|
48
|
+
|
49
|
+
alias_method :backtrace_filters, :backtrace_filter
|
50
|
+
|
23
51
|
# Public: Returns the default formatter given to the appenders that have not
|
24
52
|
# had their formatter explicitly set.
|
25
53
|
#
|
@@ -39,6 +67,7 @@ module Hatchet
|
|
39
67
|
# Public: Resets the configuration's internal state to the defaults.
|
40
68
|
#
|
41
69
|
def reset!
|
70
|
+
@backtrace_filters = {}
|
42
71
|
@levels = { nil => :info }
|
43
72
|
@appenders = []
|
44
73
|
|
@@ -388,15 +388,15 @@ module Hatchet
|
|
388
388
|
@configuration ||= Hatchet.configuration
|
389
389
|
@ndc ||= Hatchet::NestedDiagnosticContext.current
|
390
390
|
|
391
|
-
msg = Message.new(ndc: @ndc.context.clone, message: message, error: error, &block)
|
391
|
+
msg = Message.new(ndc: @ndc.context.clone, message: message, error: error, backtrace_filters: @configuration.backtrace_filters, &block)
|
392
392
|
|
393
393
|
@configuration.appenders.each do |appender|
|
394
394
|
if appender.enabled?(level, @context)
|
395
395
|
begin
|
396
396
|
appender.add(level, @context, msg)
|
397
397
|
rescue => e
|
398
|
-
puts "Failed to log message for #{@context} with appender #{appender} - #{level} - #{msg}\n"
|
399
|
-
puts "#{e}\n"
|
398
|
+
STDERR.puts "Failed to log message for #{@context} with appender #{appender} - #{level} - #{msg}\n"
|
399
|
+
STDERR.puts "#{e}\n"
|
400
400
|
end
|
401
401
|
end
|
402
402
|
end
|
data/lib/hatchet/message.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'delegate'
|
4
|
+
|
3
5
|
module Hatchet
|
4
6
|
|
5
7
|
# Public: Class for wrapping message strings and blocks in a way that means
|
@@ -15,6 +17,28 @@ module Hatchet
|
|
15
17
|
#
|
16
18
|
class Message
|
17
19
|
|
20
|
+
class ErrorDecorator < SimpleDelegator
|
21
|
+
def initialize(error, backtrace_filters)
|
22
|
+
super(error)
|
23
|
+
@error = error
|
24
|
+
@backtrace_filters = backtrace_filters
|
25
|
+
end
|
26
|
+
|
27
|
+
def backtrace
|
28
|
+
@backtrace ||= @error.backtrace.map { |line| __filtered_line(line) }
|
29
|
+
end
|
30
|
+
|
31
|
+
def __filtered_line(line)
|
32
|
+
@backtrace_filters.each do |prefixes, replacement|
|
33
|
+
Array[*prefixes].each do |prefix|
|
34
|
+
return replacement + line[prefix.length..-1] if line.start_with?(prefix)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
line
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
18
42
|
# Public: Gets the error associated with this message, if given.
|
19
43
|
#
|
20
44
|
attr_reader :error
|
@@ -65,12 +89,13 @@ module Hatchet
|
|
65
89
|
@message = args[:message] unless block
|
66
90
|
else
|
67
91
|
# Otherwise assume the old format and coerce args accordingly.
|
68
|
-
@ndc
|
69
|
-
@error
|
92
|
+
@ndc = []
|
93
|
+
@error = error
|
70
94
|
@message = args unless block
|
71
95
|
end
|
72
96
|
|
73
|
-
@
|
97
|
+
@error = ErrorDecorator.new(@error, args[:backtrace_filters]) if @error && args[:backtrace_filters]
|
98
|
+
@block = block
|
74
99
|
end
|
75
100
|
|
76
101
|
# Public: Returns the String representation of the message.
|
data/lib/hatchet/version.rb
CHANGED
data/spec/logger_spec.rb
CHANGED
@@ -60,7 +60,8 @@ describe HatchetLogger do
|
|
60
60
|
subject.send level, message, error
|
61
61
|
received = appender.messages.last
|
62
62
|
|
63
|
-
|
63
|
+
# Use __getobj__ as wrapped by delegator
|
64
|
+
assert error == received.message.error.__getobj__
|
64
65
|
end
|
65
66
|
end
|
66
67
|
end
|
data/spec/message_spec.rb
CHANGED
@@ -105,6 +105,58 @@ describe Message do
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
|
108
|
+
describe 'filtering backtraces' do
|
109
|
+
def generate_error
|
110
|
+
raise 'Example failure'
|
111
|
+
rescue => e
|
112
|
+
e
|
113
|
+
end
|
114
|
+
|
115
|
+
let(:dirname) { File.dirname(__FILE__) }
|
116
|
+
let(:error) { generate_error }
|
117
|
+
|
118
|
+
let(:subject) do
|
119
|
+
Message.new(error: generate_error, backtrace_filters: backtrace_filters)
|
120
|
+
end
|
121
|
+
|
122
|
+
require 'rbconfig'
|
123
|
+
|
124
|
+
describe 'string keys' do
|
125
|
+
let(:backtrace_filters) do
|
126
|
+
{
|
127
|
+
dirname => '$DIRNAME',
|
128
|
+
RbConfig::CONFIG['rubylibdir'] => '$RUBYLIBDIR',
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'replaces the matching keys' do
|
133
|
+
backtrace = subject.error.backtrace
|
134
|
+
|
135
|
+
backtrace_filters.each do |prefix, replacement|
|
136
|
+
refute backtrace.find { |line| line.start_with? prefix }, "Backtrace should not have a line starting '#{prefix}'\n\t#{backtrace.join("\n\t")}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'array keys' do
|
142
|
+
let(:backtrace_filters) do
|
143
|
+
{
|
144
|
+
[dirname, RbConfig::CONFIG['rubylibdir']] => '$REPLACEMENT',
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'replaces the matching keys' do
|
149
|
+
backtrace = subject.error.backtrace
|
150
|
+
|
151
|
+
backtrace_filters.each do |prefixes, replacement|
|
152
|
+
prefixes.each do |prefix|
|
153
|
+
refute backtrace.find { |line| line.start_with? prefix }, "Backtrace should not have a line starting '#{prefix}'\n\t#{backtrace.join("\n\t")}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
108
160
|
if ENV["BENCH"] then
|
109
161
|
describe 'benchmarks' do
|
110
162
|
let(:subject) { Message.new(ndc: [], message: 'Evaluated') }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hatchet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garry Shutler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Logging library that provides the ability to add class/module specific
|
14
14
|
filters
|