le 2.1.6 → 2.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/LE.gemspec +1 -1
- data/lib/le.rb +8 -3
- data/lib/le/host.rb +2 -2
- data/lib/le/host/http.rb +29 -10
- metadata +2 -2
data/LE.gemspec
CHANGED
data/lib/le.rb
CHANGED
@@ -4,13 +4,18 @@ require 'logger'
|
|
4
4
|
|
5
5
|
module Le
|
6
6
|
|
7
|
-
def self.new(token,
|
7
|
+
def self.new(token, options={})
|
8
8
|
|
9
9
|
self.checkParams(token)
|
10
10
|
|
11
|
-
|
11
|
+
opt_local = options[:local] || false
|
12
|
+
opt_debug = options[:debug] || false
|
13
|
+
opt_log_level = options[:log_level] || Logger::DEBUG
|
14
|
+
|
15
|
+
host = Le::Host.new(token, opt_local, opt_debug)
|
12
16
|
logger = Logger.new(host)
|
13
|
-
|
17
|
+
|
18
|
+
logger.level = opt_log_level
|
14
19
|
|
15
20
|
if host.respond_to?(:formatter)
|
16
21
|
logger.formatter = host.formatter
|
data/lib/le/host.rb
CHANGED
data/lib/le/host/http.rb
CHANGED
@@ -7,9 +7,9 @@ module Le
|
|
7
7
|
module Host
|
8
8
|
class HTTP
|
9
9
|
include Le::Host::InstanceMethods
|
10
|
-
attr_accessor :token, :queue, :started, :thread, :conn, :local
|
10
|
+
attr_accessor :token, :queue, :started, :thread, :conn, :local, :debug
|
11
11
|
|
12
|
-
def initialize(token, local)
|
12
|
+
def initialize(token, local, debug)
|
13
13
|
if defined?(Rails)
|
14
14
|
@logger_console = Logger.new("log/#{Rails.env}.log")
|
15
15
|
else
|
@@ -17,11 +17,30 @@ module Le
|
|
17
17
|
end
|
18
18
|
@token = token
|
19
19
|
@local = local
|
20
|
+
@debug = debug
|
20
21
|
@queue = Queue.new
|
21
22
|
@started = false
|
22
23
|
@thread = nil
|
24
|
+
|
25
|
+
if @debug then
|
26
|
+
self.init_debug
|
27
|
+
end
|
23
28
|
end
|
24
29
|
|
30
|
+
def init_debug
|
31
|
+
filePath = "logentriesGem.log"
|
32
|
+
if File.exist?('log/')
|
33
|
+
filePath = "log/logentriesGem.log"
|
34
|
+
end
|
35
|
+
@debug_logger = Logger.new(filePath)
|
36
|
+
end
|
37
|
+
|
38
|
+
def dbg(message)
|
39
|
+
if @debug then
|
40
|
+
@debug_logger.add(Logger::Severity::DEBUG,message)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
25
44
|
def write(message)
|
26
45
|
if @local then
|
27
46
|
@logger_console.add(Logger::Severity::UNKNOWN,message)
|
@@ -38,27 +57,27 @@ module Le
|
|
38
57
|
|
39
58
|
def start_async_thread
|
40
59
|
@thread = Thread.new{run()}
|
41
|
-
|
60
|
+
dbg "LE: Asynchronous socket writer started"
|
42
61
|
@started = true
|
43
62
|
end
|
44
63
|
|
45
64
|
def check_async_thread
|
46
65
|
if not @thread.alive?
|
47
66
|
@thread = Thread.new{run()}
|
48
|
-
|
67
|
+
dbg "LE: Asyncrhonous socket writer restarted"
|
49
68
|
end
|
50
69
|
end
|
51
70
|
|
52
71
|
def close
|
53
|
-
|
72
|
+
dbg "LE: Closing asynchronous socket writer"
|
54
73
|
@started = false
|
55
74
|
end
|
56
75
|
|
57
76
|
def openConnection
|
58
|
-
|
77
|
+
dbg "LE: Reopening connection to Logentries API server"
|
59
78
|
@conn = TCPSocket.new('api.logentries.com', 10000)
|
60
79
|
|
61
|
-
|
80
|
+
dbg "LE: Connection established"
|
62
81
|
end
|
63
82
|
|
64
83
|
def reopenConnection
|
@@ -69,14 +88,14 @@ module Le
|
|
69
88
|
openConnection
|
70
89
|
break
|
71
90
|
rescue TimeoutError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, EOFError => e
|
72
|
-
|
91
|
+
dbg "LE: Unable to connect to Logentries"
|
73
92
|
end
|
74
93
|
root_delay *= 2
|
75
94
|
if root_delay >= 10 then
|
76
95
|
root_delay = 10
|
77
96
|
end
|
78
97
|
wait_for = (root_delay + rand(root_delay)).to_i
|
79
|
-
|
98
|
+
dbg "LE: Waiting for " + wait_for.to_s + "ms"
|
80
99
|
sleep(wait_for)
|
81
100
|
end
|
82
101
|
end
|
@@ -103,7 +122,7 @@ module Le
|
|
103
122
|
break
|
104
123
|
end
|
105
124
|
end
|
106
|
-
|
125
|
+
dbg "LE: Closing Asyncrhonous socket writer"
|
107
126
|
closeConnection
|
108
127
|
end
|
109
128
|
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.
|
4
|
+
version: 2.1.7
|
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: 2013-
|
12
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! '
|
15
15
|
|