centralized_ruby_logger 0.0.14 → 0.0.18

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
  SHA256:
3
- metadata.gz: 736938172b64af455525ee085d0d9074ab4c8d3ac6650a96366389ed45af3931
4
- data.tar.gz: 7c65b71f1cdca2326cf8cd24a80d8a68e1f7d3e4d75583b9e7503a9d6827049d
3
+ metadata.gz: 20a07e2863d7240959e7cfdf9f9d03f32449634b77cf37bdebeb29e17fa53a48
4
+ data.tar.gz: cfd7a6a07639d67315899c0371a9cc4928e0f0a5a8b2fac876ac4a7a9728d42a
5
5
  SHA512:
6
- metadata.gz: 43923897aade7111db8a567f406dce3d86168842d83d53718cc4982d79a811bace89fe2ec31d04749f66e662bd1a556e88db474f9ac2abde05ee0ce354feb8e5
7
- data.tar.gz: 58ce3122d7c482c39ba7b039d26780ca8595d59abfbf5dd7fd7efbf58195da2f7877e2215c52c105090c37214a6828dd66978bac1a1243f4053471de22ae357e
6
+ metadata.gz: 550db13666f26095fce330a516ae00a53c6630e2eca88b02f6b5022f71cbdb56e8800a3d6a06b6a00eb3dedd500d08b7e4c40ec6a5d31f780a43dbba4c8285fa
7
+ data.tar.gz: 71e8793fc942bcd4ae8302c1f021a05192835315e8bfbfcd0f867bb7c83d55dc92f70931b039e5e67b3c059a51b740bd15324cf28317dca10d860861249e8aef
@@ -8,10 +8,15 @@ 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", force_compression=false, proxy={}
11
+ def initialize private_key, app_name, sub_system_name, debug=false, type_name="Centralized Ruby", force_compression=false, proxy={}, external_logger=nil
12
12
  self.debug_mode=debug
13
13
  @category = CORALOGIX_CATEGORY
14
14
  @manager = LoggerManager.new proxy
15
+ unless external_logger.nil?
16
+ DebugLogger.enabled = true
17
+ DebugLogger.external = true
18
+ DebugLogger.logger = external_logger
19
+ end
15
20
  configure(private_key, app_name, sub_system_name, type_name, force_compression)
16
21
  end
17
22
 
data/lib/debug_logger.rb CHANGED
@@ -4,45 +4,65 @@ module Coralogix
4
4
  # @private
5
5
  class DebugLogger
6
6
 
7
+ # attr_accessor :external, :enabled, :logger
8
+
7
9
  def self.initialize
8
10
  begin
9
11
  @mutex = Mutex.new
10
- @debug = false
12
+ @enabled = false
13
+ @external = false
11
14
  rescue Exception => e
12
- if @debug
15
+ if @enabled
13
16
  puts e.message
14
17
  puts e.backtrace.inspect
15
18
  end
16
19
  end
17
20
  end
18
21
 
22
+ def self.enabled=(value)
23
+ @enabled = value
24
+ end
25
+
26
+ def self.external=(value)
27
+ @external = value
28
+ end
29
+
30
+ def self.logger=(value)
31
+ @logger = value
32
+ end
33
+
19
34
  def self.debug_mode?
20
- @debug
35
+ @enabled
21
36
  end
22
37
 
23
38
  def self.debug_mode=(value)
24
39
  begin
25
- @debug = value
40
+ @enabled = value
26
41
  if value
27
42
  @logger = Logger.new("/tmp/#{LOG_FILE_NAME}", 1, 10485760)
28
43
  else
29
- @logger.close unless @logger == nil
30
- @logger = nil
44
+ if @external == false
45
+ @logger.close unless @logger == nil
46
+ @logger = nil
47
+ end
31
48
  end
32
49
  rescue Exception => e
33
- if @debug
50
+ if @enabled
34
51
  puts e.message
35
52
  puts e.backtrace.inspect
36
53
  end
37
54
  end
38
55
  end
39
56
 
57
+ Logger::Severity.const_set("TRACE", 0)
40
58
  Logger::Severity.constants.each do |level|
41
59
  define_singleton_method("#{level.downcase}") do |*args|
42
- if @debug
60
+ if @enabled
43
61
  @mutex.synchronize do
44
62
  begin
45
- puts "#{__method__.upcase}: #{Time.now.strftime('%H:%M:%S.%L')} - #{args}"
63
+ if @external == false
64
+ puts "#{__method__.upcase}: #{Time.now.strftime('%H:%M:%S.%L')} - #{args}"
65
+ end
46
66
  @logger.send("#{__method__}", args)
47
67
  rescue Exception => e
48
68
  puts e.message
@@ -50,10 +70,9 @@ module Coralogix
50
70
  end
51
71
  end
52
72
  end
53
- end
73
+ end
54
74
  end
55
75
 
56
-
57
76
  initialize
58
77
 
59
78
  end
data/lib/httpsender.rb CHANGED
@@ -48,7 +48,7 @@ module Coralogix
48
48
  end
49
49
  @http.use_ssl = true
50
50
  #@http.keep_alive_timeout = 10
51
- @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
51
+ @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
52
52
  @http.read_timeout = HTTP_TIMEOUT # seconds
53
53
  @http.open_timeout = HTTP_TIMEOUT # seconds
54
54
 
@@ -86,13 +86,13 @@ module Coralogix
86
86
  attempt = 0
87
87
  while attempt < HTTP_SEND_RETRY_COUNT
88
88
  begin
89
- DebugLogger.info "About to send bulk to Coralogix server. Attempt number: #{attempt+1}"
89
+ DebugLogger.debug "About to send bulk to Coralogix server. Attempt number: #{attempt+1}"
90
90
 
91
- DebugLogger.debug "Compressing bulk..."
91
+ DebugLogger.trace "Compressing bulk..."
92
92
  zippedBulk = json2zip(bulk.to_json)
93
93
 
94
94
  if zippedBulk.nil? && !@force_compression
95
- DebugLogger.info "Failed to compress bulk, sending raw data instead"
95
+ DebugLogger.debug "Failed to compress bulk, sending raw data instead"
96
96
  @req = Net::HTTP::Post.new(@uri.path, 'Content-Type' => 'application/json')
97
97
  @req.body = bulk.to_json
98
98
  else
@@ -101,13 +101,13 @@ module Coralogix
101
101
  DebugLogger.error "Compressed bulk is nil"
102
102
  end
103
103
 
104
- DebugLogger.debug "Sending compressed bulk"
104
+ DebugLogger.trace "Sending compressed bulk"
105
105
  @req.body = zippedBulk
106
106
  end
107
-
108
- DebugLogger.debug Benchmark.measure {
107
+
108
+ DebugLogger.trace Benchmark.measure {
109
109
  res = @http.request(@req)
110
- DebugLogger.info "Successfully sent bulk to Coralogix server. Result is: #{res.code}"
110
+ DebugLogger.debug "Successfully sent bulk to Coralogix server. Result is: #{res.code}"
111
111
  }.to_s
112
112
  return true
113
113
  rescue Exception => e
@@ -127,7 +127,7 @@ module Coralogix
127
127
  def get_time_sync
128
128
  @mutex.synchronize do
129
129
  begin
130
- DebugLogger.info "Syncing time with coralogix server"
130
+ DebugLogger.trace "Syncing time with coralogix server"
131
131
  res = @http.get(CORALOGIX_TIME_DELTA_URL)
132
132
 
133
133
  if res.is_a?(Net::HTTPSuccess) && !res.body.to_s.empty?
@@ -140,7 +140,7 @@ module Coralogix
140
140
  local_time = Time.now.utc
141
141
 
142
142
  time_delta = (server_time - local_time) * 1000.0
143
- DebugLogger.info "Updating time delta to: #{time_delta}"
143
+ DebugLogger.trace "Updating time delta to: #{time_delta}"
144
144
  return true, time_delta
145
145
  end
146
146
  return false, 0
data/lib/manager.rb CHANGED
@@ -32,7 +32,7 @@ module Coralogix
32
32
  def configure args={}
33
33
  begin
34
34
  @bulk_template = args.merge({:computerName => `hostname`.strip})
35
- DebugLogger.info "Successfully configured Coralogix logger."
35
+ DebugLogger.debug "Successfully configured Coralogix logger."
36
36
  @configured = true
37
37
  add_logline "The Application Name #{@bulk_template[:applicationName]} and Subsystem Name #{@bulk_template[:subsystemName]} from the #{@logger_type} SDK, version #{version?} has started to send data.", Severity::INFO, CORALOGIX_CATEGORY
38
38
  rescue Exception => e
@@ -84,6 +84,8 @@ module Coralogix
84
84
  @buffer << new_entry
85
85
  #Update the buffer size to reflect the new size.
86
86
  @buffer_size+=new_entry.to_json.bytesize
87
+ else
88
+ DebugLogger.warn "max logs exceeded, dropping log"
87
89
  end
88
90
  end
89
91
  rescue Exception => e
@@ -144,16 +146,16 @@ module Coralogix
144
146
  # we need to take it anyway.
145
147
  size = size > 0 ? size : 1
146
148
 
147
- DebugLogger.info "Checking buffer size. Total log entries is: #{size}"
149
+ DebugLogger.debug "Checking buffer size. Total log entries is: #{size}"
148
150
  @bulk_template[:logEntries] = @buffer.shift(size)
149
151
 
150
152
  # Extract from the buffer size the total amount of the logs we removed from the buffer
151
- @buffer_size-= (@bulk_template[:logEntries].to_json.bytesize - 2 - size-1)
153
+ @buffer_size-= (@bulk_template[:logEntries].to_json.bytesize - 2 - (size-1))
152
154
 
153
155
  # Make sure we are always positive
154
156
  @buffer_size = @buffer_size >= 0 ? @buffer_size : 0
155
157
 
156
- DebugLogger.info "Bufer size after removal is: #{@buffer.join(",").bytesize}"
158
+ DebugLogger.debug "Bufer size after removal is: #{@buffer.join(",").bytesize}"
157
159
  end
158
160
  @http_sender.send_request(@bulk_template) unless @bulk_template[:logEntries].empty?
159
161
  rescue Exception => e
@@ -209,7 +211,7 @@ module Coralogix
209
211
  # Check when is the next time we should send logs?
210
212
  # If we already have at least half of the max chunk size then we are working in fast mode
211
213
  next_check_interval = @buffer_size > (MAX_LOG_CHUNK_SIZE / 2) ? FAST_SEND_SPEED_INTERVAL : NORMAL_SEND_SPEED_INTERVAL
212
- DebugLogger.debug "Next buffer check is scheduled in #{next_check_interval} seconds"
214
+ DebugLogger.trace "Next buffer check is scheduled in #{next_check_interval} seconds"
213
215
  sleep next_check_interval
214
216
  end
215
217
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: centralized_ruby_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Royee Goldberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-13 00:00:00.000000000 Z
11
+ date: 2021-10-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Coralogix Centralized Ruby Logger to send logs to Coralogix server.
14
14
  email: royee@coralogix.com
@@ -42,8 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  requirements: []
45
- rubyforge_project:
46
- rubygems_version: 2.7.3
45
+ rubygems_version: 3.0.3
47
46
  signing_key:
48
47
  specification_version: 4
49
48
  summary: Coralogix Centralized Ruby Logger SDK