glo-logging-server-client 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 903724353811d3e8e23c8c15319927096a792c02
|
4
|
+
data.tar.gz: 0a13930a2563d09898ba9881d6461d2b63539c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cfbc9b263d86d31532fca3c46a9dbcbb1478fc85c2ecda44ad4843278fac4c7f0328588461bb6130000fb757f5a4ec08d8dee519ef73475e4d10b7d18003fba
|
7
|
+
data.tar.gz: 3d058df58c54060c879d89a8aa7864e4d18ad196073ecdf320434084ac6a9e9c5913569e46dff70d2e379023df9d21a412807d6c0a297b6074cd27d9151d8f13
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module GLO::LOG
|
2
2
|
class Client
|
3
|
-
def initialize ( app )
|
4
|
-
@conn = GLO::LOG::Conn.new( app )
|
3
|
+
def initialize ( target, app )
|
4
|
+
@conn = GLO::LOG::Conn.new( target, app )
|
5
5
|
end
|
6
6
|
def log ( log_level, msg, tag )
|
7
|
-
|
8
|
-
@conn.log( log_level, msg, tag, ts )
|
7
|
+
@conn.log( log_level, msg, tag)
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
@@ -1,11 +1,105 @@
|
|
1
1
|
module GLO::LOG
|
2
2
|
class Conn
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
|
4
|
+
def initialize ( target, app )
|
5
|
+
|
6
|
+
if target =~ /(.+)\:(\d+)$/i
|
7
|
+
@host = $~[1]
|
8
|
+
@port = $~[2]
|
9
|
+
else
|
10
|
+
@host = target
|
11
|
+
@port = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
@app = app
|
15
|
+
@max_tries = 6
|
16
|
+
@socket = nil
|
6
17
|
end
|
7
|
-
|
8
|
-
|
18
|
+
|
19
|
+
def log ( log_level ='debug' , msg = '' , tag = {})
|
20
|
+
tries = 0
|
21
|
+
connect( @host, @port )
|
22
|
+
data = {'app' => @app, 'log_level' => log_level,'message'=>msg,'tag'=>tag}.to_json
|
23
|
+
data_size = data.size.to_s
|
24
|
+
begin
|
25
|
+
write "*2\r\n$3\r\nLOG\r\n$"+data_size+"\r\n"+data+"\r\n"
|
26
|
+
rescue Exception => e
|
27
|
+
$stderr.puts "Failed to write to server! Retrying... ( #{tries} )"
|
28
|
+
|
29
|
+
if @max_tries == -1 || tries < @max_tries
|
30
|
+
tries += 1
|
31
|
+
close_possibly_dead_conn(tries)
|
32
|
+
reconnect
|
33
|
+
retry
|
34
|
+
else
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
9
40
|
end
|
41
|
+
def flush
|
42
|
+
@socket.flush unless @socket.nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def close
|
46
|
+
@socket.nil? ? nil : @socket.close rescue nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def closed?
|
50
|
+
@socket.nil? ? true : @socket.closed?
|
51
|
+
end
|
52
|
+
|
53
|
+
def reconnect!
|
54
|
+
close unless closed?
|
55
|
+
connect( @host, @port )
|
56
|
+
end
|
57
|
+
|
58
|
+
alias :reconnect :reconnect!
|
59
|
+
|
60
|
+
def connect(host, port)
|
61
|
+
if @socket.nil? || @socket.closed?
|
62
|
+
real_connect(host, port)
|
63
|
+
else
|
64
|
+
@socket
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def real_connect(host, port)
|
69
|
+
tries = 0
|
70
|
+
begin
|
71
|
+
@socket = TCPSocket.new( host, port)
|
72
|
+
raise "Unable to create socket!" if @socket.nil?
|
73
|
+
rescue Exception => e
|
74
|
+
$stderr.puts "Fauled to establish connection with server! Retrying..( #{tries} )" unless @max_tries == -1
|
75
|
+
if @max_tries == -1 || tries < @max_tries
|
76
|
+
tries += 1
|
77
|
+
close_possibly_dead_conn(tries)
|
78
|
+
retry
|
79
|
+
else
|
80
|
+
raise e
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def write ( msg, flush = false )
|
86
|
+
conn_timeout do
|
87
|
+
wrtlen = @socket.write(msg)
|
88
|
+
end
|
89
|
+
self.flush if flush
|
90
|
+
@socket
|
91
|
+
end
|
92
|
+
|
93
|
+
def close_possibly_dead_conn( tries = 0)
|
94
|
+
close unless @socket.nil? || closed?
|
95
|
+
@socket = nil
|
96
|
+
select(nil,nil,nil, tries * 0.2) if tries > 0
|
97
|
+
@socket
|
98
|
+
end
|
99
|
+
|
100
|
+
def conn_timeout( &block )
|
101
|
+
::Timeout::timeout( 6, GLO::LOG::Timeout, &block )
|
102
|
+
end
|
103
|
+
|
10
104
|
end
|
11
105
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glo-logging-server-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Gideon Rosales
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: client
|
14
14
|
email: gideonrosales@gmail.com
|
@@ -22,7 +22,7 @@ files:
|
|
22
22
|
- lib/glo-logging-server-client/logger.rb
|
23
23
|
homepage: http://rubygems.org/gems/glo-logging-server-client
|
24
24
|
licenses:
|
25
|
-
-
|
25
|
+
- BSD
|
26
26
|
metadata: {}
|
27
27
|
post_install_message:
|
28
28
|
rdoc_options: []
|