logglier 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,29 +6,19 @@ module Logglier
6
6
 
7
7
  class Sync
8
8
  include Logglier::Client::InstanceMethods
9
+ include Logglier::Client::HTTP::InstanceMethods
9
10
 
10
11
  attr_reader :input_uri, :http
11
12
 
12
13
  def initialize(opts={})
13
14
  setup_input_uri(opts)
14
15
 
15
- @http = Net::HTTP.new(@input_uri.host, @input_uri.port)
16
- if @input_uri.scheme == 'https'
17
- @http.use_ssl = true
18
- @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
19
- end
20
-
21
- @http.read_timeout = opts[:read_timeout] || 2
22
- @http.open_timeout = opts[:open_timeout] || 2
16
+ setup_http(opts)
23
17
  end
24
18
 
25
19
  # Required by Logger::LogDevice
26
20
  def write(message)
27
- begin
28
- @http.request_post(@input_uri.path, message)
29
- rescue TimeoutError => e
30
- $stderr.puts "WARNING: TimeoutError posting message: #{message}"
31
- end
21
+ deliver(message)
32
22
  end
33
23
 
34
24
  # Required by Logger::LogDevice
@@ -11,6 +11,7 @@ module Logglier
11
11
  #
12
12
  # Not meant to be used directly.
13
13
  class DeliveryThread < Thread
14
+ include Logglier::Client::HTTP::InstanceMethods
14
15
 
15
16
  # @param [URI] input_uri The uri to deliver messags to
16
17
  # @param [Integer] read_timeout Read timeout for the http session. defaults to 120
@@ -21,21 +22,16 @@ module Logglier
21
22
 
22
23
  @input_uri = input_uri
23
24
 
24
- @http = Net::HTTP.new(@input_uri.host, @input_uri.port)
25
- if @input_uri.scheme == 'https'
26
- @http.use_ssl = true
27
- @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
- end
29
-
30
- @http.read_timeout = read_timeout
31
- @http.open_timeout = open_timeout
25
+ setup_http( {:read_timeout => read_timeout, :open_timeout => open_timeout} )
32
26
 
33
27
  @queue = Queue.new
34
28
  @exiting = false
35
29
 
36
30
  super do
37
- until @exiting && @queue.empty?
38
- deliver(@queue.pop)
31
+ loop do
32
+ msg = @queue.pop
33
+ break if msg == :__delivery_thread_exit_signal__
34
+ deliver(msg)
39
35
  end
40
36
  end
41
37
 
@@ -48,18 +44,7 @@ module Logglier
48
44
  # Signals the queue that we're exiting
49
45
  def exit!
50
46
  @exiting = true
51
- @queue.push(:__delivery_thread_exit_signal__)
52
- end
53
-
54
- # Delivers individual messages via http
55
- def deliver(message)
56
- unless message == :__delivery_thread_exit_signal__
57
- begin
58
- @http.request_post(@input_uri.path, message)
59
- rescue TimeoutError => e
60
- $stderr.puts "WARNING: TimeoutError posting message: #{message}"
61
- end
62
- end
47
+ @queue.push :__delivery_thread_exit_signal__
63
48
  end
64
49
 
65
50
  # Pushes a message onto the internal queue
@@ -13,6 +13,37 @@ module Logglier
13
13
  end
14
14
  end
15
15
 
16
+ module InstanceMethods
17
+
18
+ # Sets up @http
19
+ #
20
+ # @param [Hash] opts The options Hash
21
+ # @option opts [String] :read_timeout The read timeout for the http connection
22
+ # @option opts [String] :open_timeout The open timeout for the http connection
23
+ def setup_http(opts={})
24
+ @http = Net::HTTP.new(@input_uri.host, @input_uri.port)
25
+ if @input_uri.scheme == 'https'
26
+ @http.use_ssl = true
27
+ @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
+ end
29
+
30
+ @http.read_timeout = opts[:read_timeout] || 2
31
+ @http.open_timeout = opts[:open_timeout] || 2
32
+ end
33
+
34
+ # Delivers the message via HTTP, handling errors
35
+ #
36
+ # @param [String] message The message to deliver
37
+ def deliver(message)
38
+ begin
39
+ @http.request_post(@input_uri.path, message)
40
+ rescue TimeoutError, OpenSSL::SSL::SSLError, EOFError, Errno::ECONNRESET => e
41
+ $stderr.puts "WARNING: #{e.class} posting message: #{message}"
42
+ end
43
+ end
44
+
45
+ end
46
+
16
47
  end
17
48
  end
18
49
  end
@@ -1,3 +1,3 @@
1
1
  module Logglier
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/logglier.gemspec CHANGED
@@ -12,7 +12,7 @@ EOD
12
12
 
13
13
  s.authors = ["Edward Muller (aka freeformz)"]
14
14
  s.email = "edwardam@interlix.com"
15
- s.homepage = "http://icanhazdowntime.org"
15
+ s.homepage = "http://github.com/freeformz/logglier"
16
16
 
17
17
  s.files = %w{ README.md Gemfile LICENSE logglier.gemspec Rakefile } + Dir["#{dir}/lib/**/*.rb"]
18
18
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logglier
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease:
5
- version: 0.1.0
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
6
11
  platform: ruby
7
12
  authors:
8
13
  - Edward Muller (aka freeformz)
@@ -10,7 +15,7 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2011-05-07 00:00:00 -07:00
18
+ date: 2011-05-11 00:00:00 -07:00
14
19
  default_executable:
15
20
  dependencies:
16
21
  - !ruby/object:Gem::Dependency
@@ -21,6 +26,9 @@ dependencies:
21
26
  requirements:
22
27
  - - ">="
23
28
  - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
24
32
  version: "0"
25
33
  type: :development
26
34
  version_requirements: *id001
@@ -32,6 +40,11 @@ dependencies:
32
40
  requirements:
33
41
  - - ~>
34
42
  - !ruby/object:Gem::Version
43
+ hash: 27
44
+ segments:
45
+ - 2
46
+ - 5
47
+ - 0
35
48
  version: 2.5.0
36
49
  type: :development
37
50
  version_requirements: *id002
@@ -63,7 +76,7 @@ files:
63
76
  - ./spec/spec_helper.rb
64
77
  - ./spec/threaded_spec.rb
65
78
  has_rdoc: true
66
- homepage: http://icanhazdowntime.org
79
+ homepage: http://github.com/freeformz/logglier
67
80
  licenses: []
68
81
 
69
82
  post_install_message:
@@ -76,17 +89,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
89
  requirements:
77
90
  - - ">="
78
91
  - !ruby/object:Gem::Version
92
+ hash: 3
93
+ segments:
94
+ - 0
79
95
  version: "0"
80
96
  required_rubygems_version: !ruby/object:Gem::Requirement
81
97
  none: false
82
98
  requirements:
83
99
  - - ">="
84
100
  - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
85
104
  version: "0"
86
105
  requirements: []
87
106
 
88
107
  rubyforge_project: logglier
89
- rubygems_version: 1.6.2
108
+ rubygems_version: 1.5.2
90
109
  signing_key:
91
110
  specification_version: 3
92
111
  summary: Loggly 'plugin' for Logger