logstash-logger 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,4 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- localhost
18
+
@@ -6,8 +6,7 @@ class LogStashLogger < ::Logger
6
6
  HOST = Socket.gethostname
7
7
 
8
8
  def initialize(host, port)
9
- @client = ::LogStashLogger::TCPClient.new(host, port)
10
- super
9
+ super(::LogStashLogger::TCPClient.new(host, port))
11
10
  end
12
11
 
13
12
  def add(severity, message = nil, progname = nil, &block)
@@ -24,7 +23,7 @@ class LogStashLogger < ::Logger
24
23
  progname = @progname
25
24
  end
26
25
  end
27
- @client.write(
26
+ @logdev.write(
28
27
  format_message(format_severity(severity), Time.now, progname, message))
29
28
  true
30
29
  end
@@ -2,6 +2,7 @@ class LogStashLogger::TCPClient
2
2
  def initialize(host, port)
3
3
  @host = host
4
4
  @port = port
5
+ @socket = nil
5
6
  end
6
7
 
7
8
  def write(event)
@@ -11,11 +12,17 @@ class LogStashLogger::TCPClient
11
12
  @socket.write("#{event.to_hash.to_json}\n")
12
13
  rescue => e
13
14
  warn "LogStashLogger::TCPClient - #{e.class} - #{e.message}"
14
- @socket && @socket.close rescue nil
15
+ close
15
16
  @socket = nil
16
17
  end
17
18
  end
18
19
 
20
+ def close
21
+ @socket && @socket.close
22
+ rescue => e
23
+ warn "LogStashLogger::TCPClient - #{e.class} - #{e.message}"
24
+ end
25
+
19
26
  private
20
27
  def connect
21
28
  @socket = TCPSocket.new(@host, @port)
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
2
 
3
3
  class LogStashLogger < ::Logger
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/spec/logger_spec.rb CHANGED
@@ -16,11 +16,20 @@ describe LogStashLogger do
16
16
  event['severity'] = 'INFO'
17
17
  event
18
18
  end
19
+
20
+ def logdev
21
+ subject.instance_variable_get(:@logdev)
22
+ end
23
+
24
+ it 'should use TCPClient as the log device' do
25
+ logdev.should be_a Logger::LogDevice
26
+ logdev.instance_variable_get(:@dev).should be_a LogStashLogger::TCPClient
27
+ end
19
28
 
20
29
  it 'should take a string message and write a logstash event' do
21
30
  message = 'test'
22
31
 
23
- subject.client.should_receive(:write) do |event|
32
+ logdev.should_receive(:write) do |event|
24
33
  event.should be_a LogStash::Event
25
34
  event.source.should eql(host)
26
35
  event.message.should eql(message)
@@ -31,7 +40,7 @@ describe LogStashLogger do
31
40
  end
32
41
 
33
42
  it 'should take a logstash-formatted json string and write out a logstash event' do
34
- subject.client.should_receive(:write) do |event|
43
+ logdev.should_receive(:write) do |event|
35
44
  event.should be_a LogStash::Event
36
45
  event.message.should eql(logstash_event.message)
37
46
  event.source.should eql(host)
@@ -41,7 +50,7 @@ describe LogStashLogger do
41
50
  end
42
51
 
43
52
  it 'should take a LogStash::Event and write it out' do
44
- subject.client.should_receive(:write) do |event|
53
+ logdev.should_receive(:write) do |event|
45
54
  event.should be_a LogStash::Event
46
55
  event.message.should eql(logstash_event.message)
47
56
  event['severity'].should eql(logstash_event['severity'])
@@ -58,7 +67,7 @@ describe LogStashLogger do
58
67
  'severity' => 'INFO'
59
68
  }
60
69
 
61
- subject.client.should_receive(:write) do |event|
70
+ logdev.should_receive(:write) do |event|
62
71
  event.should be_a LogStash::Event
63
72
  event.message.should eql('test')
64
73
  event['severity'].should eql('INFO')
metadata CHANGED
@@ -1,74 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: logstash-logger
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 0
10
- version: 0.1.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - David Butler
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-12-15 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-12-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: logstash-event
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
38
25
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
46
38
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rake
50
39
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
52
41
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
60
54
  type: :development
61
- version_requirements: *id003
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
62
  description: Ruby logger that writes directly to LogStash
63
- email:
63
+ email:
64
64
  - dwbutler@ucla.edu
65
65
  executables: []
66
-
67
66
  extensions: []
68
-
69
67
  extra_rdoc_files: []
70
-
71
- files:
68
+ files:
72
69
  - .gitignore
73
70
  - .travis.yml
74
71
  - Gemfile
@@ -84,37 +81,28 @@ files:
84
81
  - spec/spec_helper.rb
85
82
  homepage: http://github.com/dwbutler/logstash-logger
86
83
  licenses: []
87
-
88
84
  post_install_message:
89
85
  rdoc_options: []
90
-
91
- require_paths:
86
+ require_paths:
92
87
  - lib
93
- required_ruby_version: !ruby/object:Gem::Requirement
88
+ required_ruby_version: !ruby/object:Gem::Requirement
94
89
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
102
- required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
95
  none: false
104
- requirements:
105
- - - ">="
106
- - !ruby/object:Gem::Version
107
- hash: 3
108
- segments:
109
- - 0
110
- version: "0"
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
111
100
  requirements: []
112
-
113
101
  rubyforge_project:
114
- rubygems_version: 1.8.24
102
+ rubygems_version: 1.8.23
115
103
  signing_key:
116
104
  specification_version: 3
117
105
  summary: LogStash Logger for ruby
118
- test_files:
106
+ test_files:
119
107
  - spec/logger_spec.rb
120
108
  - spec/spec_helper.rb