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 +4 -4
- data/lib/splunk_logger/client/log.rb +11 -1
- data/lib/splunk_logger/client.rb +5 -3
- data/lib/splunk_logger/version.rb +1 -1
- 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: 335914ad6f35394b0feb928e1d161a37ec68b901
|
4
|
+
data.tar.gz: 578cb76bf268a394b7147f2e2bb3cb1373e26ca1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/splunk_logger/client.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|