lpxc 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lpxc.rb +14 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab326ae043382498e355d1c8c27cc3642a9dca80
|
4
|
+
data.tar.gz: 7e1ad3efa4fc3f1a9fdfe461d36f3866e535d9a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da1649d6fe13116634cbc9ed1aad344835e8051c5a335d5dc6483995d27cf4fb6e2045a6da1944dc76ffdffcd2055a4b99fccc951ed3583c32461b36aab22df2
|
7
|
+
data.tar.gz: 15492414fc68c9a15c872cce993bcea64c39667b8cecaa235ebac4d3a24c50249ce261c263d7151f5e3ccd65666a8c56db3e4ba0647612e793a0ebbd396dab23
|
data/lib/lpxc.rb
CHANGED
@@ -50,10 +50,14 @@ class Lpxc
|
|
50
50
|
Thread.new {delay_flush} if opts[:disable_delay_flush].nil?
|
51
51
|
end
|
52
52
|
|
53
|
-
#The interface to publish logs into the stream.
|
54
|
-
#This function will set the log message to the current time in UTC.
|
55
|
-
#If the buffer for this token's log
|
56
|
-
|
53
|
+
# The interface to publish logs into the stream.
|
54
|
+
# This function will set the log message to the current time in UTC.
|
55
|
+
# If the buffer for this token's log msgs is full, it will flush the buffer.
|
56
|
+
# You can specify a logplex token for the message, otherwise #puts will fall
|
57
|
+
# back on the default_token specified in the initializer. If default_token
|
58
|
+
# was not specified in the initializer, then the user portion of the
|
59
|
+
# LOGPLEX_URL will be used.
|
60
|
+
def puts(msg, tok=nil)
|
57
61
|
@hash_lock.synchronize do
|
58
62
|
#Messages are grouped by their token since 1 http request
|
59
63
|
#to logplex must only contain log messages belonging to a single token.
|
@@ -61,7 +65,7 @@ class Lpxc
|
|
61
65
|
#This call will block if the queue is full.
|
62
66
|
#However this should never happen since the next command will flush
|
63
67
|
#the queue if we add the last item.
|
64
|
-
q.enq({:t => Time.now.utc, :token => tok, :msg => msg})
|
68
|
+
q.enq({:t => Time.now.utc, :token => (tok || default_token), :msg => msg})
|
65
69
|
flush if q.size == q.max
|
66
70
|
end
|
67
71
|
end
|
@@ -78,6 +82,10 @@ class Lpxc
|
|
78
82
|
|
79
83
|
private
|
80
84
|
|
85
|
+
def default_token
|
86
|
+
@default_token || @logplex_url.user
|
87
|
+
end
|
88
|
+
|
81
89
|
#Take a lock to read all of the buffered messages.
|
82
90
|
#Once we have read the messages, we make 1 http request for the batch.
|
83
91
|
#We pass the request off into the request queue so that the request
|
@@ -99,7 +107,7 @@ class Lpxc
|
|
99
107
|
#Build a new HTTP request and place it into the queue
|
100
108
|
#to be processed by the HTTP connection.
|
101
109
|
req = Net::HTTP::Post.new(@logplex_url.path)
|
102
|
-
req.basic_auth("token",
|
110
|
+
req.basic_auth("token", @logplex_url.user)
|
103
111
|
req.add_field('Content-Type', 'application/logplex-1')
|
104
112
|
req.body = body
|
105
113
|
@request_queue.enq(req)
|