splunk_logger 0.0.1 → 0.0.2

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: 8eaea19cf92ea00c6ac8bcf7ebec9b9e07c5d7e8
4
- data.tar.gz: 6bc9d6bbfdcc21b47779716fa09f555277fa2e26
3
+ metadata.gz: 335914ad6f35394b0feb928e1d161a37ec68b901
4
+ data.tar.gz: 578cb76bf268a394b7147f2e2bb3cb1373e26ca1
5
5
  SHA512:
6
- metadata.gz: 66efe22640215d1db09bbea5c6b30ba5063faa18663b9f458feea8a013a9dec4369d0a90ff03a1144ab7038eca3ddacd8f019596123d76d64ab13be22c0f8a5d
7
- data.tar.gz: 2d534fc00373c3c5a93d6f9a93263006e0455892075f7adab5cff0faa0ff0b1579f7f764eb7ba033e9add2421e4afdffd690f8c64ae49ce2fef6845947a2e261
6
+ metadata.gz: 92335641860e1cd730873b224994a11b3ae979d0a991b171a4be36b50511c6520b27fb0446ab6abea056bd0581ddf22980e1b58291510cf98f3eddee4fd79983
7
+ data.tar.gz: 060dade3bbe77a2ab67c96bf66c2c6d3262e49388df4c1dab6a476c7e3000d059219409c54fd2c46a96f841c661bc8a8886bee8da262d38657a7a50a3e200976
@@ -49,11 +49,21 @@ module SplunkLogger
49
49
  if delayed?
50
50
  @message_queue << {severity: level, message: message}
51
51
  @message_queue.shift if @message_queue.length > @max_queue_size + @max_batch_size
52
+ trigger_send_log if @message_queue.length >= @max_batch_size && @current_message_size == 0
52
53
  return true
53
54
  else
54
55
  send_log_now({severity: level, message: message})
55
56
  end
56
57
  end
58
+
59
+ def trigger_send_log
60
+ return if @semaphore.locked?
61
+ Thread.new do
62
+ @semaphore.synchronize do
63
+ send_log
64
+ end
65
+ end
66
+ end
57
67
  end
58
68
  end
59
- end
69
+ end
@@ -26,6 +26,7 @@ module SplunkLogger
26
26
  faraday.adapter Faraday.default_adapter
27
27
  end
28
28
  @conn.ssl.verify = verify_ssl
29
+ @semaphore = Mutex.new
29
30
  start
30
31
  end
31
32
 
@@ -36,7 +37,9 @@ module SplunkLogger
36
37
  @timer = Thread.new do
37
38
  while true do
38
39
  sleep @send_interval
39
- send_log
40
+ @semaphore.synchronize do
41
+ send_log
42
+ end
40
43
  end
41
44
  end
42
45
  end
@@ -56,12 +59,11 @@ module SplunkLogger
56
59
  def send_log
57
60
  return if @message_queue.empty? || @current_message_size > 0
58
61
 
59
- while(!@message_queue.empty?) do
62
+ until(@message_queue.empty?) do
60
63
  @current_message_size = [@message_queue.length, @max_batch_size].min
61
64
  messages = { "event": @message_queue.slice(0, @current_message_size) }
62
65
  body = messages[:event].map { |m| "#{{event: m}.to_json}" }.join("\n")
63
66
 
64
-
65
67
  begin
66
68
  response = @conn.post SplunkLogger::Client::COLLECTOR_PATH, body
67
69
  if response.body['text'] == 'Success' && response.body['code'] == 0
@@ -1,3 +1,3 @@
1
1
  module SplunkLogger
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splunk_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Ikeoka