centralized_ruby_logger 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/centralized_ruby_logger.rb +9 -6
- data/lib/constants.rb +2 -3
- data/lib/httpsender.rb +46 -3
- data/lib/manager.rb +7 -0
- 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: ee5ffc79f691e5234632af4da8e288917c659641
|
4
|
+
data.tar.gz: 52b9d4c416af247bfcea6536f6f66a553ad546ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc0d37f583e37b085e829d52e83c46f5d68b784dcbdcf8b6d485ecc39ea29ac4dd4e39799154411332e864815771380493be0ca4bea33abe69c56aee41c533da
|
7
|
+
data.tar.gz: 5a4549704e2d0d40fce9829c71251c778879689bbe89281e7c87929beca8808653d31402e882d4e903c60a289001530e3ce4201305da5cc2b8d0159b9388c63e
|
@@ -8,11 +8,11 @@ module Coralogix
|
|
8
8
|
# Constructor.
|
9
9
|
#
|
10
10
|
# @param name - logger name.
|
11
|
-
def initialize private_key, app_name, sub_system_name, debug=false, type_name="Centralized Ruby"
|
11
|
+
def initialize private_key, app_name, sub_system_name, debug=false, type_name="Centralized Ruby", force_compression = false
|
12
12
|
self.debug_mode=debug
|
13
13
|
@category = CORALOGIX_CATEGORY
|
14
14
|
@manager = LoggerManager.new
|
15
|
-
configure(private_key, app_name, sub_system_name, type_name)
|
15
|
+
configure(private_key, app_name, sub_system_name, type_name, force_compression)
|
16
16
|
end
|
17
17
|
|
18
18
|
# A getter for debug_mode.
|
@@ -44,15 +44,18 @@ module Coralogix
|
|
44
44
|
|
45
45
|
# Configure coralogix logger with customer specific values
|
46
46
|
#
|
47
|
-
# @param private_key
|
48
|
-
# @param app_name
|
49
|
-
# @param sub_system
|
47
|
+
# @param private_key - private key
|
48
|
+
# @param app_name - application name
|
49
|
+
# @param sub_system - sub system name
|
50
|
+
# @param type_name - type name
|
51
|
+
# @param force_compression - when true, will not send the raw data if data compression failed
|
50
52
|
# @return [boolean] return a true or false.
|
51
|
-
def configure private_key, app_name, sub_system, type_name
|
53
|
+
def configure private_key, app_name, sub_system, type_name, force_compression
|
52
54
|
private_key = (private_key.nil? || private_key.to_s.strip.empty?) ? FAILED_PRIVATE_KEY : private_key
|
53
55
|
app_name = (app_name.nil? || app_name.to_s.strip.empty?) ? NO_APP_NAME : app_name
|
54
56
|
sub_system = (sub_system.nil? || sub_system.to_s.strip.empty?) ? NO_SUB_SYSTEM : sub_system
|
55
57
|
@manager.set_logger_type_name type_name
|
58
|
+
@manager.force_compression = force_compression
|
56
59
|
@manager.configure(:privateKey => private_key, :applicationName => app_name, :subsystemName => sub_system) unless @manager.configured
|
57
60
|
end
|
58
61
|
|
data/lib/constants.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
module Coralogix
|
2
2
|
|
3
3
|
#Maximum log buffer size
|
4
|
-
MAX_LOG_BUFFER_SIZE = 12582912 #12mb
|
4
|
+
MAX_LOG_BUFFER_SIZE = ENV['CORALOGIX_MAX_LOG_BUFFER_SIZE'] ? ENV['CORALOGIX_MAX_LOG_BUFFER_SIZE'].to_i : 12582912 #12mb
|
5
5
|
|
6
6
|
#Maximum chunk size
|
7
|
-
MAX_LOG_CHUNK_SIZE =
|
7
|
+
MAX_LOG_CHUNK_SIZE = 2097152 #2 mb
|
8
8
|
|
9
9
|
#Bulk send interval in normal mode.
|
10
10
|
NORMAL_SEND_SPEED_INTERVAL = 500.0 / 1000
|
@@ -15,7 +15,6 @@ module Coralogix
|
|
15
15
|
#Corologix severity mapper
|
16
16
|
SEVERITIES = {:debug => 1, :verbose => 2, :info => 3, :warning => 4, :error => 5, :critical => 6}
|
17
17
|
|
18
|
-
|
19
18
|
module Severity
|
20
19
|
DEBUG = 1
|
21
20
|
VERBOSE = 2
|
data/lib/httpsender.rb
CHANGED
@@ -6,6 +6,8 @@ require 'openssl'
|
|
6
6
|
require 'benchmark'
|
7
7
|
require 'date'
|
8
8
|
require 'time'
|
9
|
+
require 'zlib'
|
10
|
+
require 'base64'
|
9
11
|
|
10
12
|
module Coralogix
|
11
13
|
# @private
|
@@ -19,6 +21,10 @@ module Coralogix
|
|
19
21
|
@disable_proxy = value
|
20
22
|
end
|
21
23
|
|
24
|
+
def force_compression=(value)
|
25
|
+
@force_compression = value
|
26
|
+
end
|
27
|
+
|
22
28
|
def initialize
|
23
29
|
begin
|
24
30
|
@initialized = false
|
@@ -34,13 +40,33 @@ module Coralogix
|
|
34
40
|
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
35
41
|
@http.read_timeout = HTTP_TIMEOUT # seconds
|
36
42
|
@http.open_timeout = HTTP_TIMEOUT # seconds
|
37
|
-
|
43
|
+
|
44
|
+
headers = {
|
45
|
+
'Content-Type': 'application/json',
|
46
|
+
'Content-Encoding': 'deflate'
|
47
|
+
}
|
48
|
+
@req = Net::HTTP::Post.new(@uri.path, headers)
|
38
49
|
rescue Exception => e
|
39
50
|
DebugLogger.error e.message
|
40
51
|
DebugLogger.error e.backtrace.inspect
|
41
52
|
end
|
42
53
|
end
|
43
54
|
|
55
|
+
# Compress json
|
56
|
+
# @param json - json to compress
|
57
|
+
#
|
58
|
+
# @return [String] return base 64 string that represents the compresed log message binary data
|
59
|
+
def json2zip(json)
|
60
|
+
begin
|
61
|
+
compressed_data = Zlib::Deflate.deflate(json)
|
62
|
+
return compressed_data
|
63
|
+
rescue Exception => e
|
64
|
+
DebugLogger.error e.message
|
65
|
+
DebugLogger.error e.backtrace.inspect
|
66
|
+
return nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
44
70
|
# A helper method to post http request
|
45
71
|
#
|
46
72
|
# @param bulk - JSON bulk containing the log entries
|
@@ -49,8 +75,25 @@ module Coralogix
|
|
49
75
|
attempt = 0
|
50
76
|
while attempt < HTTP_SEND_RETRY_COUNT
|
51
77
|
begin
|
52
|
-
DebugLogger.info "About to send bulk to Coralogix server. Attempt number: #{attempt+1}"
|
53
|
-
|
78
|
+
DebugLogger.info "About to send bulk to Coralogix server. Attempt number: #{attempt+1}"
|
79
|
+
|
80
|
+
DebugLogger.debug "Compressing bulk..."
|
81
|
+
zippedBulk = json2zip(bulk.to_json)
|
82
|
+
|
83
|
+
if zippedBulk.nil? && !@force_compression
|
84
|
+
DebugLogger.info "Failed to compress bulk, sending raw data instead"
|
85
|
+
@req = Net::HTTP::Post.new(@uri.path, 'Content-Type' => 'application/json')
|
86
|
+
@req.body = bulk.to_json
|
87
|
+
else
|
88
|
+
if zippedBulk.nil?
|
89
|
+
DebugLogger.error "Failed to compress bulk"
|
90
|
+
DebugLogger.error "Compressed bulk is nil"
|
91
|
+
end
|
92
|
+
|
93
|
+
DebugLogger.debug "Sending compressed bulk"
|
94
|
+
@req.body = zippedBulk
|
95
|
+
end
|
96
|
+
|
54
97
|
DebugLogger.debug Benchmark.measure {
|
55
98
|
res = @http.request(@req)
|
56
99
|
DebugLogger.info "Successfully sent bulk to Coralogix server. Result is: #{res.code}"
|
data/lib/manager.rb
CHANGED
@@ -171,6 +171,13 @@ module Coralogix
|
|
171
171
|
@http_sender.disable_proxy=value
|
172
172
|
end
|
173
173
|
|
174
|
+
# A setter for force data sending even if somehow the compression of data failed.
|
175
|
+
#
|
176
|
+
# @param value - true or false. (Default is false)
|
177
|
+
def force_compression=(value)
|
178
|
+
@http_sender.force_compression=value
|
179
|
+
end
|
180
|
+
|
174
181
|
# Sync log timestamps with coralogix server
|
175
182
|
def update_time_delta_interval
|
176
183
|
return
|