semantic_logger 2.20.0 → 2.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/semantic_logger/appender/base.rb +6 -0
- data/lib/semantic_logger/base.rb +16 -7
- data/lib/semantic_logger/log.rb +2 -2
- data/lib/semantic_logger/version.rb +1 -1
- data/test/logger_test.rb +37 -16
- data/test/mock_logger.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7835135546f3ebf18ce484c594cd52fef0d4ecee
|
4
|
+
data.tar.gz: 12cd7ddcbf431f070a0b57792ad436f100aca649
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfb139be7ea5cb63d9787638e4e2e2bc464c8bd0bf49f60a9447b4b2b28033e66de8766c8c5b648e544d8bd3068813765d13cee9275130f2823416881e20bfde
|
7
|
+
data.tar.gz: 92e4e1fc6e445696c04596f4f12839d6504d32a62df005baa83e82adb2b4ed4343b9a808193104bfd615ac159ceab7631e5cb36e70457c265efb6de1cb475e18
|
data/lib/semantic_logger/base.rb
CHANGED
@@ -108,6 +108,15 @@ module SemanticLogger
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
+
# If the tag being supplied is definitely a string then this fast
|
112
|
+
# tag api can be used for short lived tags
|
113
|
+
def fast_tag(tag)
|
114
|
+
(Thread.current[:semantic_logger_tags] ||= []) << tag
|
115
|
+
yield
|
116
|
+
ensure
|
117
|
+
Thread.current[:semantic_logger_tags].pop
|
118
|
+
end
|
119
|
+
|
111
120
|
# Add the supplied tags to the list of tags to log for this thread whilst
|
112
121
|
# the supplied block is active
|
113
122
|
# Returns nil if no tags are currently set
|
@@ -290,7 +299,7 @@ module SemanticLogger
|
|
290
299
|
end
|
291
300
|
|
292
301
|
# Log message at the specified level
|
293
|
-
def log_internal(level, index, message=nil, payload=nil, exception=nil
|
302
|
+
def log_internal(level, index, message=nil, payload=nil, exception=nil)
|
294
303
|
# Detect exception being logged
|
295
304
|
if exception.nil? && payload.nil? && message.kind_of?(Exception)
|
296
305
|
exception = message
|
@@ -303,7 +312,7 @@ module SemanticLogger
|
|
303
312
|
end
|
304
313
|
|
305
314
|
# Add result of block as message or payload if not nil
|
306
|
-
if
|
315
|
+
if block_given? && (result = yield)
|
307
316
|
if result.is_a?(String)
|
308
317
|
message = message.nil? ? result : "#{message} -- #{result}"
|
309
318
|
elsif payload && payload.respond_to?(:merge)
|
@@ -320,7 +329,7 @@ module SemanticLogger
|
|
320
329
|
|
321
330
|
# Add caller stack trace
|
322
331
|
backtrace =
|
323
|
-
if
|
332
|
+
if index >= SemanticLogger.backtrace_level_index
|
324
333
|
trace = caller
|
325
334
|
# Remove call to this internal method
|
326
335
|
trace.shift(1)
|
@@ -332,18 +341,18 @@ module SemanticLogger
|
|
332
341
|
end
|
333
342
|
|
334
343
|
# Measure the supplied block and log the message
|
335
|
-
def benchmark_internal(level, index, message, params
|
344
|
+
def benchmark_internal(level, index, message, params)
|
336
345
|
start = Time.now
|
337
346
|
exception = nil
|
338
347
|
begin
|
339
|
-
if
|
348
|
+
if block_given?
|
340
349
|
result =
|
341
350
|
if silence_level = params[:silence]
|
342
351
|
# In case someone accidentally sets `silence: true` instead of `silence: :error`
|
343
352
|
silence_level = :error if silence_level == true
|
344
|
-
silence(silence_level) {
|
353
|
+
silence(silence_level) { yield(params) }
|
345
354
|
else
|
346
|
-
|
355
|
+
yield(params)
|
347
356
|
end
|
348
357
|
exception = params[:exception]
|
349
358
|
result
|
data/lib/semantic_logger/log.rb
CHANGED
@@ -43,14 +43,14 @@ module SemanticLogger
|
|
43
43
|
|
44
44
|
MAX_EXCEPTIONS_TO_UNWRAP = 5
|
45
45
|
# Call the block for exception and any nested exception
|
46
|
-
def each_exception
|
46
|
+
def each_exception
|
47
47
|
# With thanks to https://github.com/bugsnag/bugsnag-ruby/blob/6348306e44323eee347896843d16c690cd7c4362/lib/bugsnag/notification.rb#L81
|
48
48
|
depth = 0
|
49
49
|
exceptions = []
|
50
50
|
ex = exception
|
51
51
|
while ex != nil && !exceptions.include?(ex) && exceptions.length < MAX_EXCEPTIONS_TO_UNWRAP
|
52
52
|
exceptions << ex
|
53
|
-
|
53
|
+
yield(ex, depth)
|
54
54
|
|
55
55
|
depth += 1
|
56
56
|
ex =
|
data/test/logger_test.rb
CHANGED
@@ -64,7 +64,7 @@ class LoggerTest < Minitest::Test
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
it
|
67
|
+
it 'logs with backtrace' do
|
68
68
|
SemanticLogger.stub(:backtrace_level_index, 0) do
|
69
69
|
@logger.send(level, 'hello world', @hash) { 'Calculations' }
|
70
70
|
SemanticLogger.flush
|
@@ -72,10 +72,34 @@ class LoggerTest < Minitest::Test
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
it 'logs with backtrace and exception' do
|
76
|
+
SemanticLogger.stub(:backtrace_level_index, 0) do
|
77
|
+
exc = RuntimeError.new("Test")
|
78
|
+
@logger.send(level, 'hello world', exc)
|
79
|
+
SemanticLogger.flush
|
80
|
+
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}#{@file_name_reg_exp}\] LoggerTest -- hello world -- Exception: RuntimeError: Test/, @mock_logger.message
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'logs payload' do
|
85
|
+
hash = {tracking_number: '123456', even: 2, more: 'data'}
|
86
|
+
hash_str = hash.inspect.sub('{', '\{').sub('}', '\}')
|
87
|
+
@logger.send(level, 'Hello world', hash)
|
88
|
+
SemanticLogger.flush
|
89
|
+
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world -- #{hash_str}/, @mock_logger.message
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'does not log an empty payload' do
|
93
|
+
hash = {}
|
94
|
+
@logger.send(level, 'Hello world', hash)
|
95
|
+
SemanticLogger.flush
|
96
|
+
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ #{level_char} \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message
|
97
|
+
end
|
98
|
+
|
75
99
|
end
|
76
100
|
end
|
77
101
|
|
78
|
-
describe 'tagged
|
102
|
+
describe '#tagged' do
|
79
103
|
it 'add tags to log entries' do
|
80
104
|
@logger.tagged('12345', 'DJHSFK') do
|
81
105
|
@logger.info('Hello world')
|
@@ -96,7 +120,9 @@ class LoggerTest < Minitest::Test
|
|
96
120
|
assert_equal 'tags', @logger.tags.last
|
97
121
|
end
|
98
122
|
end
|
123
|
+
end
|
99
124
|
|
125
|
+
describe '#with_payload' do
|
100
126
|
it 'logs tagged payload' do
|
101
127
|
hash = {tracking_number: "123456", even: 2, more: "data"}
|
102
128
|
hash_str = hash.inspect.sub("{", "\\{").sub("}", "\\}")
|
@@ -108,24 +134,19 @@ class LoggerTest < Minitest::Test
|
|
108
134
|
end
|
109
135
|
end
|
110
136
|
end
|
137
|
+
end
|
111
138
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
it 'does not log an empty payload' do
|
121
|
-
hash = {}
|
122
|
-
@logger.info('Hello world', hash)
|
123
|
-
SemanticLogger.flush
|
124
|
-
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] LoggerTest -- Hello world/, @mock_logger.message
|
139
|
+
describe '#fast_tag' do
|
140
|
+
it 'add string tag to log entries' do
|
141
|
+
@logger.fast_tag('12345') do
|
142
|
+
@logger.info('Hello world')
|
143
|
+
SemanticLogger.flush
|
144
|
+
assert_match /\d+-\d+-\d+ \d+:\d+:\d+.\d+ I \[\d+:#{@thread_name}\] \[12345\] LoggerTest -- Hello world/, @mock_logger.message
|
145
|
+
end
|
125
146
|
end
|
126
147
|
end
|
127
148
|
|
128
|
-
describe 'Ruby Logger' do
|
149
|
+
describe 'Ruby Logger level' do
|
129
150
|
# Ensure that any log level can be logged
|
130
151
|
Logger::Severity.constants.each do |level|
|
131
152
|
it "log Ruby logger #{level} info" do
|
data/test/mock_logger.rb
CHANGED
@@ -5,11 +5,11 @@ class MockLogger
|
|
5
5
|
|
6
6
|
Logger::Severity.constants.each do |level|
|
7
7
|
class_eval <<-EOT, __FILE__, __LINE__
|
8
|
-
def #{level.downcase}(message = nil, progname = nil
|
8
|
+
def #{level.downcase}(message = nil, progname = nil)
|
9
9
|
if message
|
10
10
|
self.message = message
|
11
|
-
elsif
|
12
|
-
self.message =
|
11
|
+
elsif block_given?
|
12
|
+
self.message = yield
|
13
13
|
else
|
14
14
|
self.message = progname
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: semantic_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.4.
|
89
|
+
rubygems_version: 2.4.8
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Scalable, next generation enterprise logging for Ruby
|