semantic_logger 2.21.0 → 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/LICENSE.txt +1 -1
- data/lib/semantic_logger.rb +13 -9
- data/lib/semantic_logger/appender/base.rb +20 -24
- data/lib/semantic_logger/appender/bugsnag.rb +37 -53
- data/lib/semantic_logger/appender/elasticsearch.rb +53 -0
- data/lib/semantic_logger/appender/file.rb +17 -3
- data/lib/semantic_logger/appender/graylog.rb +123 -0
- data/lib/semantic_logger/appender/http.rb +169 -0
- data/lib/semantic_logger/appender/mongodb.rb +90 -111
- data/lib/semantic_logger/appender/new_relic.rb +38 -72
- data/lib/semantic_logger/appender/splunk.rb +10 -5
- data/lib/semantic_logger/appender/splunk_http.rb +99 -0
- data/lib/semantic_logger/appender/syslog.rb +116 -103
- data/lib/semantic_logger/appender/wrapper.rb +26 -11
- data/lib/semantic_logger/base.rb +13 -16
- data/lib/semantic_logger/log.rb +85 -5
- data/lib/semantic_logger/logger.rb +1 -1
- data/lib/semantic_logger/semantic_logger.rb +24 -0
- data/lib/semantic_logger/version.rb +1 -1
- data/test/appender/bugsnag_test.rb +39 -41
- data/test/appender/graylog_test.rb +63 -0
- data/test/appender/http_test.rb +61 -0
- data/test/appender/mongodb_test.rb +20 -20
- data/test/appender/new_relic_test.rb +4 -3
- data/test/appender/splunk_http_test.rb +78 -0
- data/test/logger_test.rb +1 -1
- metadata +27 -3
@@ -10,7 +10,7 @@ module Appender
|
|
10
10
|
@appender = SemanticLogger::Appender::MongoDB.new(
|
11
11
|
db: @db,
|
12
12
|
collection_size: 10*1024**2, # 10MB
|
13
|
-
|
13
|
+
host: 'test',
|
14
14
|
application: 'test_application',
|
15
15
|
level: :trace
|
16
16
|
)
|
@@ -22,18 +22,17 @@ module Appender
|
|
22
22
|
@appender.purge_all if @appender
|
23
23
|
end
|
24
24
|
|
25
|
-
describe
|
26
|
-
|
27
|
-
it "handle nil name, message and hash" do
|
25
|
+
describe 'format logs into documents' do
|
26
|
+
it 'handle nil name, message and hash' do
|
28
27
|
@appender.debug
|
29
28
|
document = @appender.collection.find_one
|
30
29
|
assert_equal :debug, document['level']
|
31
30
|
assert_equal nil, document['message']
|
32
|
-
assert_equal 'thread', document['
|
31
|
+
assert_equal 'thread', document['thread']
|
33
32
|
assert document['time'].is_a?(Time)
|
34
33
|
assert_equal nil, document['payload']
|
35
34
|
assert_equal $$, document['pid']
|
36
|
-
assert_equal 'test', document['
|
35
|
+
assert_equal 'test', document['host']
|
37
36
|
assert_equal 'test_application', document['application']
|
38
37
|
end
|
39
38
|
|
@@ -43,40 +42,40 @@ module Appender
|
|
43
42
|
document = @appender.collection.find_one
|
44
43
|
assert_equal :debug, document['level']
|
45
44
|
assert_equal @hash.inspect, document['message']
|
46
|
-
assert_equal 'thread', document['
|
45
|
+
assert_equal 'thread', document['thread']
|
47
46
|
assert document['time'].is_a?(Time)
|
48
47
|
assert_nil document['payload']
|
49
48
|
assert_equal $$, document['pid']
|
50
|
-
assert_equal 'test', document['
|
49
|
+
assert_equal 'test', document['host']
|
51
50
|
assert_equal 'test_application', document['application']
|
52
51
|
end
|
53
52
|
|
54
|
-
it
|
53
|
+
it 'handle message and payload' do
|
55
54
|
@appender.debug('hello world', @hash)
|
56
55
|
|
57
56
|
document = @appender.collection.find_one
|
58
57
|
assert_equal :debug, document['level']
|
59
58
|
assert_equal 'hello world', document['message']
|
60
|
-
assert_equal 'thread', document['
|
59
|
+
assert_equal 'thread', document['thread']
|
61
60
|
assert document['time'].is_a?(Time)
|
62
|
-
assert_equal
|
61
|
+
assert_equal 12345, document['tracking_number']
|
62
|
+
assert_equal 'HSSKLEU@JDK767', document['session_id']
|
63
63
|
assert_equal $$, document['pid']
|
64
|
-
assert_equal 'test', document['
|
64
|
+
assert_equal 'test', document['host']
|
65
65
|
assert_equal 'test_application', document['application']
|
66
66
|
end
|
67
67
|
|
68
|
-
it
|
68
|
+
it 'handle message without payload' do
|
69
69
|
log = SemanticLogger::Log.new(:debug)
|
70
70
|
@appender.debug('hello world')
|
71
71
|
|
72
72
|
document = @appender.collection.find_one
|
73
73
|
assert_equal :debug, document['level']
|
74
74
|
assert_equal 'hello world', document['message']
|
75
|
-
assert_equal 'thread', document['
|
75
|
+
assert_equal 'thread', document['thread']
|
76
76
|
assert document['time'].is_a?(Time)
|
77
|
-
assert_equal nil, document['payload']
|
78
77
|
assert_equal $$, document['pid']
|
79
|
-
assert_equal 'test', document['
|
78
|
+
assert_equal 'test', document['host']
|
80
79
|
assert_equal 'test_application', document['application']
|
81
80
|
end
|
82
81
|
end
|
@@ -84,16 +83,17 @@ module Appender
|
|
84
83
|
describe "for each log level" do
|
85
84
|
# Ensure that any log level can be logged
|
86
85
|
SemanticLogger::LEVELS.each do |level|
|
87
|
-
it
|
86
|
+
it 'log #{level} information' do
|
88
87
|
@appender.send(level, 'hello world -- Calculations', @hash)
|
89
88
|
document = @appender.collection.find_one
|
90
89
|
assert_equal level, document['level']
|
91
90
|
assert_equal 'hello world -- Calculations', document['message']
|
92
|
-
assert_equal 'thread', document['
|
91
|
+
assert_equal 'thread', document['thread']
|
93
92
|
assert document['time'].is_a?(Time)
|
94
|
-
assert_equal
|
93
|
+
assert_equal 12345, document['tracking_number']
|
94
|
+
assert_equal 'HSSKLEU@JDK767', document['session_id']
|
95
95
|
assert_equal $$, document['pid']
|
96
|
-
assert_equal 'test', document['
|
96
|
+
assert_equal 'test', document['host']
|
97
97
|
assert_equal 'test_application', document['application']
|
98
98
|
end
|
99
99
|
end
|
@@ -37,7 +37,7 @@ module Appender
|
|
37
37
|
assert_equal @message, exception.message
|
38
38
|
assert_equal ['test'], hash[:custom_params][:tags]
|
39
39
|
assert_nil hash[:custom_params][:duration]
|
40
|
-
assert hash[:custom_params][:
|
40
|
+
assert hash[:custom_params][:thread], hash.inspect
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -55,9 +55,10 @@ module Appender
|
|
55
55
|
assert_equal 'RuntimeError', exception.class.to_s
|
56
56
|
assert_equal @message, exception.message
|
57
57
|
assert_equal ['test'], hash[:custom_params][:tags], hash
|
58
|
-
assert_equal
|
58
|
+
assert_equal 1, hash[:custom_params][:key1], hash
|
59
|
+
assert_equal 'a', hash[:custom_params][:key2], hash
|
59
60
|
assert hash[:custom_params][:duration], hash
|
60
|
-
assert hash[:custom_params][:
|
61
|
+
assert hash[:custom_params][:thread], hash
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
# Unit Test for SemanticLogger::Appender::SplunkHttp
|
4
|
+
module Appender
|
5
|
+
class SplunkHttpTest < Minitest::Test
|
6
|
+
response_mock = Struct.new(:code, :body)
|
7
|
+
|
8
|
+
describe SemanticLogger::Appender::SplunkHttp do
|
9
|
+
before do
|
10
|
+
@appender = SemanticLogger::Appender::SplunkHttp.new(
|
11
|
+
url: 'http://localhost:8088/path',
|
12
|
+
token: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
|
13
|
+
)
|
14
|
+
@message = 'AppenderSplunkHttpTest log message'
|
15
|
+
end
|
16
|
+
|
17
|
+
SemanticLogger::LEVELS.each do |level|
|
18
|
+
it "send #{level}" do
|
19
|
+
request = nil
|
20
|
+
@appender.http.stub(:request, -> r { request = r; response_mock.new('200', 'ok') }) do
|
21
|
+
@appender.send(level, @message)
|
22
|
+
end
|
23
|
+
body = decompress_data(request.body)
|
24
|
+
message = JSON.parse(body)
|
25
|
+
assert_equal @message, message['event']['message']
|
26
|
+
assert_equal level.to_s, message['event']['level']
|
27
|
+
refute message['event']['exception']
|
28
|
+
end
|
29
|
+
|
30
|
+
it "sends #{level} exceptions" do
|
31
|
+
exc = nil
|
32
|
+
begin
|
33
|
+
Uh oh
|
34
|
+
rescue Exception => e
|
35
|
+
exc = e
|
36
|
+
end
|
37
|
+
request = nil
|
38
|
+
@appender.http.stub(:request, -> r { request = r; response_mock.new('200', 'ok') }) do
|
39
|
+
@appender.send(level, 'Reading File', exc)
|
40
|
+
end
|
41
|
+
body = decompress_data(request.body)
|
42
|
+
hash = JSON.parse(body)
|
43
|
+
# assert message['event']['message'].include?('Reading File -- NameError: undefined local variable or method'), message['message']
|
44
|
+
# assert_equal level.to_s, message['event']['level']
|
45
|
+
# assert message['event']['backtrace'].include?(__FILE__), message['event']['backtrace']
|
46
|
+
assert 'Reading File', hash['message']
|
47
|
+
assert exception = hash['event']['exception']
|
48
|
+
assert 'NameError', exception['name']
|
49
|
+
assert 'undefined local variable or method', exception['message']
|
50
|
+
assert_equal level.to_s, hash['event']['level']
|
51
|
+
assert exception['stack_trace'].first.include?(__FILE__), exception
|
52
|
+
end
|
53
|
+
|
54
|
+
it "sends #{level} custom attributes" do
|
55
|
+
request = nil
|
56
|
+
@appender.http.stub(:request, -> r { request = r; response_mock.new('200', 'ok') }) do
|
57
|
+
@appender.send(level, @message, {key1: 1, key2: 'a'})
|
58
|
+
end
|
59
|
+
body = decompress_data(request.body)
|
60
|
+
message = JSON.parse(body)
|
61
|
+
assert_equal @message, message['event']['message']
|
62
|
+
assert_equal level.to_s, message['event']['level']
|
63
|
+
refute message['event']['backtrace']
|
64
|
+
assert_equal(1, message['event']['key1'], message)
|
65
|
+
assert_equal('a', message['event']['key2'], message)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def decompress_data(data)
|
70
|
+
str = StringIO.new(data)
|
71
|
+
gz = Zlib::GzipReader.new(str)
|
72
|
+
raw = gz.read
|
73
|
+
gz.close
|
74
|
+
raw
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/test/logger_test.rb
CHANGED
@@ -26,7 +26,7 @@ class LoggerTest < Minitest::Test
|
|
26
26
|
@hash = {session_id: 'HSSKLEU@JDK767', tracking_number: 12345}
|
27
27
|
@hash_str = @hash.inspect.sub("{", "\\{").sub("}", "\\}")
|
28
28
|
@thread_name = Thread.current.name
|
29
|
-
@file_name_reg_exp =
|
29
|
+
@file_name_reg_exp = ' logger_test.rb:\d+'
|
30
30
|
|
31
31
|
assert_equal [], @logger.tags
|
32
32
|
assert_equal 65535, SemanticLogger.backtrace_level_index
|
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:
|
4
|
+
version: 3.0.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:
|
11
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
27
41
|
description: Next generation logging system for Ruby to support highly concurrent,
|
28
42
|
high throughput, low latency enterprise systems
|
29
43
|
email:
|
@@ -38,10 +52,14 @@ files:
|
|
38
52
|
- lib/semantic_logger.rb
|
39
53
|
- lib/semantic_logger/appender/base.rb
|
40
54
|
- lib/semantic_logger/appender/bugsnag.rb
|
55
|
+
- lib/semantic_logger/appender/elasticsearch.rb
|
41
56
|
- lib/semantic_logger/appender/file.rb
|
57
|
+
- lib/semantic_logger/appender/graylog.rb
|
58
|
+
- lib/semantic_logger/appender/http.rb
|
42
59
|
- lib/semantic_logger/appender/mongodb.rb
|
43
60
|
- lib/semantic_logger/appender/new_relic.rb
|
44
61
|
- lib/semantic_logger/appender/splunk.rb
|
62
|
+
- lib/semantic_logger/appender/splunk_http.rb
|
45
63
|
- lib/semantic_logger/appender/syslog.rb
|
46
64
|
- lib/semantic_logger/appender/wrapper.rb
|
47
65
|
- lib/semantic_logger/base.rb
|
@@ -55,9 +73,12 @@ files:
|
|
55
73
|
- lib/semantic_logger/version.rb
|
56
74
|
- test/appender/bugsnag_test.rb
|
57
75
|
- test/appender/file_test.rb
|
76
|
+
- test/appender/graylog_test.rb
|
77
|
+
- test/appender/http_test.rb
|
58
78
|
- test/appender/mongodb_test.rb
|
59
79
|
- test/appender/new_relic_test.rb
|
60
80
|
- test/appender/newrelic_rpm.rb
|
81
|
+
- test/appender/splunk_http_test.rb
|
61
82
|
- test/appender/splunk_test.rb
|
62
83
|
- test/appender/syslog_test.rb
|
63
84
|
- test/appender/wrapper_test.rb
|
@@ -86,16 +107,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
107
|
version: '0'
|
87
108
|
requirements: []
|
88
109
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.1
|
90
111
|
signing_key:
|
91
112
|
specification_version: 4
|
92
113
|
summary: Scalable, next generation enterprise logging for Ruby
|
93
114
|
test_files:
|
94
115
|
- test/appender/bugsnag_test.rb
|
95
116
|
- test/appender/file_test.rb
|
117
|
+
- test/appender/graylog_test.rb
|
118
|
+
- test/appender/http_test.rb
|
96
119
|
- test/appender/mongodb_test.rb
|
97
120
|
- test/appender/new_relic_test.rb
|
98
121
|
- test/appender/newrelic_rpm.rb
|
122
|
+
- test/appender/splunk_http_test.rb
|
99
123
|
- test/appender/splunk_test.rb
|
100
124
|
- test/appender/syslog_test.rb
|
101
125
|
- test/appender/wrapper_test.rb
|