le 2.1.2 → 2.1.3

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.
Files changed (4) hide show
  1. data/LE.gemspec +1 -1
  2. data/lib/le/host.rb +19 -10
  3. data/lib/le/host/http.rb +30 -26
  4. metadata +2 -2
data/LE.gemspec CHANGED
@@ -3,7 +3,7 @@ require File.expand_path(File.join(dir, 'lib', 'le'))
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "le"
6
- s.version = "2.1.2"
6
+ s.version = "2.1.3"
7
7
  s.date = Time.now
8
8
  s.summary = "Logentries plugin"
9
9
  s.description =<<EOD
@@ -2,24 +2,33 @@ module Le
2
2
  module Host
3
3
 
4
4
  def self.new(token, local)
5
+
5
6
  Le::Host::HTTP.new(token, local)
7
+
6
8
  end
7
-
9
+
8
10
  module InstanceMethods
9
11
  def formatter
10
- proc do |severity, datetime, _, msg|
11
- message = "#{datetime} "
12
- message << format_message(msg, severity)
13
- end
14
- end
15
-
12
+ proc do |severity, datetime, progname, msg|
13
+ message = "#{datetime} "
14
+ message << format_message(msg, severity)
15
+ end
16
+ end
17
+
16
18
  def format_message(message_in, severity)
17
- message_in = message_in.inspect unless message_in.is_a?(String)
19
+ message_in = message_in.lstrip
18
20
 
19
- "severity=#{severity}, #{message_in.lstrip}"
21
+ message_out = ""
22
+ message_out = "severity=#{severity}, "
23
+ case message_in
24
+ when String
25
+ message_out << message_in
26
+ else
27
+ message_out << message_in.inspect
28
+ end
29
+ message_out
20
30
  end
21
31
  end
22
-
23
32
  end
24
33
  end
25
34
 
@@ -12,8 +12,9 @@ module Le
12
12
  def initialize(token, local)
13
13
  @token = token
14
14
  @local = local
15
- @queue = Queue.new
15
+ @queue = Queue.new
16
16
  @started = false
17
+ @thread = nil
17
18
  end
18
19
 
19
20
  def write(message)
@@ -24,25 +25,35 @@ module Le
24
25
 
25
26
  @queue << "#{@token}#{message}\n"
26
27
 
27
- if not @started then
28
- puts "LE: Starting asynchronous socket writer"
29
- @thread = Thread.new{run()}
30
- @started = true
28
+ if @started then
29
+ check_async_thread
30
+ else
31
+ start_async_thread
31
32
  end
32
33
  end
33
34
 
35
+ def start_async_thread
36
+ @thread = Thread.new{run()}
37
+ puts "LE: Asynchronous socket writer started"
38
+ @started = true
39
+ end
40
+
41
+ def check_async_thread
42
+ if not @thread.alive?
43
+ @thread = Thread.new{run()}
44
+ puts "LE: Asyncrhonous socket writer restarted"
45
+ end
46
+ end
47
+
34
48
  def close
35
49
  puts "LE: Closing asynchronous socket writer"
36
- @thread.raise Interrupt
50
+ @started = false
37
51
  end
38
52
 
39
53
  def openConnection
40
54
  puts "LE: Reopening connection to Logentries API server"
41
55
  @conn = TCPSocket.new('api.logentries.com', 10000)
42
56
 
43
- #@conn = OpenSSL::SSL::SSLSocket.new(@sock, OpenSSL::SSL::SSLContext.new())
44
- #@conn.connect
45
-
46
57
  puts "LE: Connection established"
47
58
  end
48
59
 
@@ -53,7 +64,7 @@ module Le
53
64
  begin
54
65
  openConnection
55
66
  break
56
- rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
67
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
57
68
  puts "LE: Unable to connect to Logentries"
58
69
  end
59
70
  root_delay *= 2
@@ -71,31 +82,24 @@ module Le
71
82
  @conn.sysclose
72
83
  @conn = nil
73
84
  end
74
- #if @sock != nil
75
- # @sock.close
76
- # @sock = nil
77
- #end
78
85
  end
79
86
 
80
87
  def run
81
- begin
82
88
  reopenConnection
83
89
 
90
+ while true
91
+ data = @queue.pop
84
92
  while true
85
- data = @queue.pop
86
- while true
87
- begin
88
- @conn.write(data)
89
- rescue OpenSSL::SSL::SSLError, TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEOUT, EOFError => e
90
- reopenConnection
91
- next
92
- end
93
- break
93
+ begin
94
+ @conn.write(data)
95
+ rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEOUT, EOFError => e
96
+ reopenConnection
97
+ next
94
98
  end
99
+ break
95
100
  end
96
- rescue Interrupt
97
- puts "LE: Asynchronous socket writer interrupted"
98
101
  end
102
+ puts "LE: Closing Asyncrhonous socket writer"
99
103
  closeConnection
100
104
  end
101
105
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: le
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! '
15
15