lpxc 0.0.4 → 0.0.5

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/lpxc.rb +14 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 001fb59b50becee25a64490039d881a09a20545c
4
- data.tar.gz: 59f3aff79c8de8a030918ea393f390e2d2ed8c15
3
+ metadata.gz: ab326ae043382498e355d1c8c27cc3642a9dca80
4
+ data.tar.gz: 7e1ad3efa4fc3f1a9fdfe461d36f3866e535d9a3
5
5
  SHA512:
6
- metadata.gz: 0c0e643950ce3eaa55daa90e22fdb0baaf08218c09ec8ee67232bf5df7237d5fbdb212c508e6e24cafa6d7f4629dbfb51023f8e96b5069de3e32d6a60a645994
7
- data.tar.gz: 432f80cd8dbeed7a9940857bf53d53305d9a475749add03b8cf1ba6eda8443f036d02c96f4589c97146c2eb34e7a72f2d4997e3ae5b0d1a7d1b276278ffe6e3c
6
+ metadata.gz: da1649d6fe13116634cbc9ed1aad344835e8051c5a335d5dc6483995d27cf4fb6e2045a6da1944dc76ffdffcd2055a4b99fccc951ed3583c32461b36aab22df2
7
+ data.tar.gz: 15492414fc68c9a15c872cce993bcea64c39667b8cecaa235ebac4d3a24c50249ce261c263d7151f5e3ccd65666a8c56db3e4ba0647612e793a0ebbd396dab23
@@ -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 messages is full, it will flush the buffer.
56
- def puts(msg, tok=@default_token)
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", tok)
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lpxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Smith (♠ ace hacker)