coralogix_logger 0.0.21 → 0.0.22

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: ba1085435b0b299b3779692579278c7f85ae0b47
4
- data.tar.gz: 5f9450e0c3ab3bc06f46581b066e6dbd3bdd9c6f
3
+ metadata.gz: b33f65bf7b4312c21ed86d29ab6d65d316b1dfe7
4
+ data.tar.gz: 04e7b73f26794d0981530a21c53fd9f663032fe4
5
5
  SHA512:
6
- metadata.gz: f286979abc8fc2882ef3bdc687a51ab95aa8869d66d017498f71afe38222eb322ca47f48051c3d282761498d1fe4d205b730e09e14736d1c37ce91f6dcb23689
7
- data.tar.gz: abe4e9e8d31b2046eea753d4f22f51ddeab6b5b7444292505c82bbafaf2ec3487e8e0ea64906e467cc087491e65ead7fb7ffb69a30f5fd38998f5b64ae7d669c
6
+ metadata.gz: 11de4f0a3d676c8eb583029551e1a65b87db19271e3659cbf7b4c93c9789db25bf824b62fbed3aa882919c2666d8c1fa5cfbf25282dc9cc23ac59cc81725c39a
7
+ data.tar.gz: e5bd4b6430c257fda6fd88bf876bf98c7c6000a10ff46d8c2f4b2db934f7d3e4469df5c354579212af8a110cedcc79d9a9bb7d9edce6f3128608b1a9ef157b4c
@@ -104,6 +104,13 @@ module Coralogix
104
104
  LoggerManager.reconnect
105
105
  end
106
106
 
107
+
108
+ # Flush all messages in buffer and send them immediately on the current thread.
109
+ def flush
110
+ LoggerManager.flush
111
+ end
112
+
113
+
107
114
  # Log a message.
108
115
  #
109
116
  # @param severity - log severity
data/lib/httpsender.rb CHANGED
@@ -49,25 +49,26 @@ module Coralogix
49
49
  #
50
50
  # @param bulk - JSON bulk containing the log entries
51
51
  def CoralogixHTTPSender.send_request bulk
52
-
53
- self.initialize unless @initialized
54
- attempt = 0
55
- while attempt < HTTP_SEND_RETRY_COUNT
56
- begin
57
- DebugLogger.info "About to send bulk to Coralogix server. Attempt number: #{attempt+1}"
58
- @req.body = bulk.to_json
59
- DebugLogger.debug Benchmark.measure {
60
- res = @http.request(@req)
61
- DebugLogger.info "Successfully sent bulk to Coralogix server. Result is: #{res.code}"
62
- }.to_s
63
- return true
64
- rescue Exception => e
65
- DebugLogger.error e.message
66
- DebugLogger.error e.backtrace.inspect
52
+ @mutex.synchronize do
53
+ self.initialize unless @initialized
54
+ attempt = 0
55
+ while attempt < HTTP_SEND_RETRY_COUNT
56
+ begin
57
+ DebugLogger.info "About to send bulk to Coralogix server. Attempt number: #{attempt+1}"
58
+ @req.body = bulk.to_json
59
+ DebugLogger.debug Benchmark.measure {
60
+ res = @http.request(@req)
61
+ DebugLogger.info "Successfully sent bulk to Coralogix server. Result is: #{res.code}"
62
+ }.to_s
63
+ return true
64
+ rescue Exception => e
65
+ DebugLogger.error e.message
66
+ DebugLogger.error e.backtrace.inspect
67
+ end
68
+ attempt+=1;
69
+ DebugLogger.error "Failed to send bulk. Will retry in: #{HTTP_SEND_RETRY_INTERVAL} seconds..."
70
+ sleep HTTP_SEND_RETRY_INTERVAL
67
71
  end
68
- attempt+=1;
69
- DebugLogger.error "Failed to send bulk. Will retry in: #{HTTP_SEND_RETRY_INTERVAL} seconds..."
70
- sleep HTTP_SEND_RETRY_INTERVAL
71
72
  end
72
73
  end
73
74
 
data/lib/manager.rb CHANGED
@@ -14,6 +14,8 @@ module Coralogix
14
14
 
15
15
  def self.initialize
16
16
  @bulk_template = {:privateKey => FAILED_PRIVATE_KEY, :applicationName => NO_APP_NAME, :subsystemName => NO_SUB_SYSTEM}
17
+ @time_delta_last_update = 0
18
+ @time_delta = 0
17
19
  self.init
18
20
  end
19
21
 
@@ -21,8 +23,7 @@ module Coralogix
21
23
  @buffer = []
22
24
  @buffer_size = 0
23
25
  @mutex = Mutex.new
24
- @time_delta_last_update = 0
25
- @time_delta = 0
26
+ @process= Process.pid
26
27
  self.run
27
28
  end
28
29
 
@@ -71,8 +72,9 @@ module Coralogix
71
72
  # @return [boolean] return true for success or false for failure.
72
73
  def self.add_logline message, severity, category, **args
73
74
  begin
74
-
75
+ return if @mutex.nil?
75
76
  @mutex.synchronize do
77
+ self.init if Process.pid != @process
76
78
  if @buffer_size < MAX_LOG_BUFFER_SIZE
77
79
  #Validate message
78
80
  message = (message.nil? || message.to_s.strip.empty?) ? "EMPTY_STRING" : self.msg2str(message)
@@ -118,11 +120,16 @@ module Coralogix
118
120
  return msg
119
121
  end
120
122
  end
123
+
124
+ # Flush all messages in buffer and send them immediately on the current thread.
125
+ def self.flush
126
+ self.send_bulk false
127
+ end
121
128
 
122
129
  # Send bulk from the buffer
123
- def self.send_bulk
130
+ def self.send_bulk time_sync=true
124
131
  begin
125
- self.update_time_delta_interval
132
+ self.update_time_delta_interval if time_sync
126
133
  @mutex.synchronize do
127
134
  # Total buffer size
128
135
  size = @buffer.size
@@ -173,9 +180,9 @@ module Coralogix
173
180
  end
174
181
  end
175
182
 
176
- # Spawn a new workter thread.
183
+ # Spawn a new workter thread. [Obsolete]
177
184
  def self.reconnect
178
- self.init
185
+ #Backword compatibilty
179
186
  end
180
187
 
181
188
  # Start timer execution.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coralogix_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.21
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Royee Goldberg