semantic_logger 2.9.2 → 2.10.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/README.md +18 -8
- data/lib/semantic_logger.rb +1 -0
- data/lib/semantic_logger/appender/splunk.rb +56 -0
- data/lib/semantic_logger/version.rb +1 -1
- data/test/appender_splunk_test.rb +63 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0114b0cd9c89056b16e797dad89c995cc0fb9485
|
4
|
+
data.tar.gz: f2df244261d122b2967e973380cf94770b24325e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2eb3829a86b55f7b0014e72a0c624970f134ebc1e9c25ad7a89298078a4d71a993728ec0817f5205fa3afcd82d96186f5dc2e649cceab1e0502bdbfde3cd7845
|
7
|
+
data.tar.gz: 614edca05b62f3de8b48c301c2e059868e607ebea3e4eaa25aacb6fe86e7cde3e83f24fe86b7ca21ac007ff8a96dc217aaaf8c14062e0574003b98876fffcc1c
|
data/README.md
CHANGED
@@ -11,13 +11,16 @@ For complete documentation see: http://reidmorrison.github.io/semantic_logger
|
|
11
11
|
|
12
12
|
## Dependencies
|
13
13
|
|
14
|
-
|
14
|
+
Semantic Logger supports the following Ruby platforms:
|
15
|
+
- Ruby 1.9.3, 2.0, 2.1
|
16
|
+
- JRuby 1.7
|
15
17
|
|
16
18
|
The following gems are only required when their corresponding appenders are being used,
|
17
19
|
and are therefore not automatically included by this gem:
|
18
|
-
- MongoDB Appender: mongo 1.9.2 or above
|
19
|
-
- Syslog Appender: syslog_protocol 0.9.2 or above
|
20
|
-
- Syslog Appender to a remote syslogng server over TCP or UDP: resilient_socket 0.5.0 or above
|
20
|
+
- MongoDB Appender: gem 'mongo' 1.9.2 or above
|
21
|
+
- Syslog Appender: gem 'syslog_protocol' 0.9.2 or above
|
22
|
+
- Syslog Appender to a remote syslogng server over TCP or UDP: gem 'resilient_socket' 0.5.0 or above
|
23
|
+
- Splunk Appender: gem 'splunk-sdk-ruby'
|
21
24
|
|
22
25
|
## Install
|
23
26
|
|
@@ -25,8 +28,14 @@ and are therefore not automatically included by this gem:
|
|
25
28
|
|
26
29
|
## Upgrade Notes:
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
### V2.10
|
32
|
+
|
33
|
+
Ruby 1.8 is no longer supported, see [Ruby 1.8.7 EOL](https://www.ruby-lang.org/en/news/2014/07/01/eol-for-1-8-7-and-1-9-2/)
|
34
|
+
|
35
|
+
### V2.0
|
36
|
+
|
37
|
+
Rails logging is no longer automatically replaced when including SemanticLogger.
|
38
|
+
Include the [rails_semantic_logger](http://github.com/reidmorrison/rails_semantic_logger)
|
30
39
|
gem to replace the Rails default logger with SemanticLogger
|
31
40
|
|
32
41
|
## Meta
|
@@ -40,11 +49,12 @@ This project uses [Semantic Versioning](http://semver.org/).
|
|
40
49
|
|
41
50
|
## Author
|
42
51
|
|
43
|
-
Reid Morrison
|
52
|
+
[Reid Morrison](https://github.com/reidmorrison) :: @reidmorrison
|
44
53
|
|
45
54
|
## Contributors
|
46
55
|
|
47
|
-
Marc Bellingrath
|
56
|
+
* [Marc Bellingrath](https://github.com/marc)
|
57
|
+
* [Andrew Medeiros](https://github.com/amedeiros)
|
48
58
|
|
49
59
|
## License
|
50
60
|
|
data/lib/semantic_logger.rb
CHANGED
@@ -14,6 +14,7 @@ module SemanticLogger
|
|
14
14
|
autoload :MongoDB, 'semantic_logger/appender/mongodb'
|
15
15
|
autoload :Syslog, 'semantic_logger/appender/syslog'
|
16
16
|
autoload :NewRelic, 'semantic_logger/appender/new_relic'
|
17
|
+
autoload :Splunk, 'semantic_logger/appender/splunk'
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'splunk-sdk-ruby'
|
2
|
+
|
3
|
+
|
4
|
+
# Recommended not to use the colorized formatter.
|
5
|
+
|
6
|
+
class SemanticLogger::Appender::Splunk < SemanticLogger::Appender::Base
|
7
|
+
attr_reader :config, :index, :service, :service_index
|
8
|
+
|
9
|
+
# Allow the level for this appender to be overwritten
|
10
|
+
# Default: :error
|
11
|
+
def initialize(options, level=:error, &block)
|
12
|
+
# Parse input options for setting up splunk connection
|
13
|
+
parse_options(options)
|
14
|
+
|
15
|
+
# Connect to splunk. Connect is a synonym for creating a Service by hand and calling login.
|
16
|
+
@service = Splunk::connect(@config)
|
17
|
+
|
18
|
+
# The index we are logging to
|
19
|
+
@service_index = @service.indexes[@index]
|
20
|
+
|
21
|
+
# Pass on the level and custom formatter if supplied
|
22
|
+
super(level, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Log the message to Splunk
|
27
|
+
def log(log)
|
28
|
+
# Ensure minimum log level is met, and check filter
|
29
|
+
return false if (level_index > (log.level_index || 0)) || !include_message?(log)
|
30
|
+
# Submit the log message
|
31
|
+
@service_index.submit(formatter.call(log))
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def parse_options(options)
|
38
|
+
@config = {
|
39
|
+
scheme: options[:scheme] || :https,
|
40
|
+
host: options[:host] || 'localhost',
|
41
|
+
port: options[:port] || 8089,
|
42
|
+
username: options[:username],
|
43
|
+
password: options[:password]
|
44
|
+
}
|
45
|
+
|
46
|
+
@index = options[:index]
|
47
|
+
|
48
|
+
if @config[:username].nil?
|
49
|
+
raise ArgumentError, 'Must supply a username.'
|
50
|
+
elsif @config[:password].nil?
|
51
|
+
raise ArgumentError, 'Must supply a password.'
|
52
|
+
elsif @index.nil?
|
53
|
+
raise ArgumentError, 'Must supply an index.'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Allow test to be run in-place without requiring a gem install
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'mocha/setup'
|
7
|
+
require 'shoulda'
|
8
|
+
require 'logger'
|
9
|
+
require 'semantic_logger'
|
10
|
+
|
11
|
+
# Unit Test for SemanticLogger::Appender::Splunk
|
12
|
+
#
|
13
|
+
class AppenderSplunkTest < Test::Unit::TestCase
|
14
|
+
context SemanticLogger::Appender::Splunk do
|
15
|
+
|
16
|
+
context '#parse_options' do
|
17
|
+
context 'argument errors' do
|
18
|
+
should 'raise argument error for missing username' do
|
19
|
+
error = assert_raises ArgumentError do
|
20
|
+
SemanticLogger::Appender::Splunk.new({})
|
21
|
+
end
|
22
|
+
|
23
|
+
assert_equal 'Must supply a username.', error.message
|
24
|
+
end
|
25
|
+
|
26
|
+
should 'raise argument error for missing password' do
|
27
|
+
error = assert_raises ArgumentError do
|
28
|
+
SemanticLogger::Appender::Splunk.new(username: 'username')
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_equal 'Must supply a password.', error.message
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'raise argument error for missing index' do
|
35
|
+
error = assert_raises ArgumentError do
|
36
|
+
SemanticLogger::Appender::Splunk.new(username: 'username', password: 'password')
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_equal 'Must supply an index.', error.message
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'set default values' do
|
44
|
+
# Stub the splunk connect call, and index call.
|
45
|
+
setup do
|
46
|
+
Splunk.expects(:connect).returns(Splunk::Service.new({}))
|
47
|
+
Splunk::Service.any_instance.expects(:indexes).returns({})
|
48
|
+
end
|
49
|
+
|
50
|
+
should 'have default values' do
|
51
|
+
appender = SemanticLogger::Appender::Splunk.new(username: 'username', password: 'password', index: 'index')
|
52
|
+
config = appender.config
|
53
|
+
# Default host
|
54
|
+
assert_equal 'localhost', config[:host]
|
55
|
+
# Default pot
|
56
|
+
assert_equal 8089, config[:port]
|
57
|
+
# Default scheme
|
58
|
+
assert_equal :https, config[:scheme]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
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.10.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: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sync_attr
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- lib/semantic_logger/appender/file.rb
|
55
55
|
- lib/semantic_logger/appender/mongodb.rb
|
56
56
|
- lib/semantic_logger/appender/new_relic.rb
|
57
|
+
- lib/semantic_logger/appender/splunk.rb
|
57
58
|
- lib/semantic_logger/appender/syslog.rb
|
58
59
|
- lib/semantic_logger/appender/wrapper.rb
|
59
60
|
- lib/semantic_logger/base.rb
|
@@ -65,6 +66,7 @@ files:
|
|
65
66
|
- test/appender_file_test.rb
|
66
67
|
- test/appender_mongodb_test.rb
|
67
68
|
- test/appender_new_relic_test.rb
|
69
|
+
- test/appender_splunk_test.rb
|
68
70
|
- test/appender_syslog_test.rb
|
69
71
|
- test/appender_wrapper_test.rb
|
70
72
|
- test/loggable_test.rb
|
@@ -99,6 +101,7 @@ test_files:
|
|
99
101
|
- test/appender_file_test.rb
|
100
102
|
- test/appender_mongodb_test.rb
|
101
103
|
- test/appender_new_relic_test.rb
|
104
|
+
- test/appender_splunk_test.rb
|
102
105
|
- test/appender_syslog_test.rb
|
103
106
|
- test/appender_wrapper_test.rb
|
104
107
|
- test/loggable_test.rb
|