centralized_ruby_logger 0.0.12 → 0.0.17

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
- SHA1:
3
- metadata.gz: fcfa42cda13a4d02dd703a4e0195f8342c61df99
4
- data.tar.gz: df8c24a7dfeedf6209ec46ce282a0ab18d3aae1c
2
+ SHA256:
3
+ metadata.gz: 33ef705c6e4330c8a36cb16984aad708dad39b48a4a78b3c01cec87c5c99c498
4
+ data.tar.gz: f478764300a534ca8864702c256feecbc035bc4238edc6b6d9d623dfcf1753d0
5
5
  SHA512:
6
- metadata.gz: f117003aebbd6b711f6ce73f0c664499aa6428010bdc103b22c13554c4eb92acfa1c5a46d67386de6f12f429aa2796a9d0becc45ffa59c4899c3cf869567bd68
7
- data.tar.gz: aa93ae24dca04354c48318ba61e330c23ccf3c94b414ead4090714b13f63758d7a379ab9882089db674d80046bb45cc9d9185dc9a644d9f01fbb9d477e37182e
6
+ metadata.gz: 8e386b8e11d8986d302d656dd2e7652ac754287d3be7b4dfbc927c862d8852d669fa23c0c661283bacd40a70e8378db1bf0f74f9d3f5096d80def7573faef756
7
+ data.tar.gz: 7fdc6c0d177fabda7dd0e0f91f32e49a9ce4e10d94c621e8c41e46a42c0ff44a9a7f595f9e503ebe9f8924b39232b7cb91a20832dcbe640f9ae7880effed6ef3
@@ -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
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
- @manager = LoggerManager.new
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/constants.rb CHANGED
@@ -26,10 +26,10 @@ module Coralogix
26
26
 
27
27
 
28
28
  #Coralogix logs url
29
- CORALOGIX_LOG_URL = "https://api.coralogix.com:443/api/v1/logs"
29
+ CORALOGIX_LOG_URL = ENV['CORALOGIX_LOG_URL'] ? ENV['CORALOGIX_LOG_URL'] : "https://api.coralogix.com:443/api/v1/logs"
30
30
 
31
31
  #Coralogix time delat url
32
- CORALOGIX_TIME_DELTA_URL = "https://api.coralogix.com:443/sdk/v1/time"
32
+ CORALOGIX_TIME_DELTA_URL = ENV['CORALOGIX_TIME_DELTA_URL'] ? ENV['CORALOGIX_TIME_DELTA_URL'] : "https://api.coralogix.com:443/sdk/v1/time"
33
33
 
34
34
  #Default private key
35
35
  FAILED_PRIVATE_KEY = "9626c7dd-8174-5015-a3fe-5572e042b6d9"
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
@@ -25,7 +25,7 @@ module Coralogix
25
25
  @force_compression = value
26
26
  end
27
27
 
28
- def initialize
28
+ def initialize proxy={}
29
29
  begin
30
30
  @initialized = false
31
31
  @mutex = Mutex.new
@@ -33,7 +33,18 @@ module Coralogix
33
33
  if(@disable_proxy)
34
34
  @http = Net::HTTP.new(@uri.host, @uri.port, p_addr=nil, p_port=nil)
35
35
  else
36
- @http = Net::HTTP.new(@uri.host, @uri.port)
36
+ if proxy.empty? or proxy.fetch("host", nil).nil? or proxy.fetch("port", nil).nil?
37
+ @http = Net::HTTP.new(@uri.host, @uri.port)
38
+ else
39
+ @http = Net::HTTP.new(
40
+ @uri.host,
41
+ @uri.port,
42
+ p_addr=proxy["host"],
43
+ p_port=proxy["port"],
44
+ p_user=proxy.fetch("user", nil),
45
+ p_pass=proxy.fetch("password", nil)
46
+ )
47
+ end
37
48
  end
38
49
  @http.use_ssl = true
39
50
  #@http.keep_alive_timeout = 10
@@ -75,13 +86,13 @@ module Coralogix
75
86
  attempt = 0
76
87
  while attempt < HTTP_SEND_RETRY_COUNT
77
88
  begin
78
- 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}"
79
90
 
80
- DebugLogger.debug "Compressing bulk..."
91
+ DebugLogger.trace "Compressing bulk..."
81
92
  zippedBulk = json2zip(bulk.to_json)
82
93
 
83
94
  if zippedBulk.nil? && !@force_compression
84
- DebugLogger.info "Failed to compress bulk, sending raw data instead"
95
+ DebugLogger.debug "Failed to compress bulk, sending raw data instead"
85
96
  @req = Net::HTTP::Post.new(@uri.path, 'Content-Type' => 'application/json')
86
97
  @req.body = bulk.to_json
87
98
  else
@@ -90,13 +101,13 @@ module Coralogix
90
101
  DebugLogger.error "Compressed bulk is nil"
91
102
  end
92
103
 
93
- DebugLogger.debug "Sending compressed bulk"
104
+ DebugLogger.trace "Sending compressed bulk"
94
105
  @req.body = zippedBulk
95
106
  end
96
-
97
- DebugLogger.debug Benchmark.measure {
107
+
108
+ DebugLogger.trace Benchmark.measure {
98
109
  res = @http.request(@req)
99
- 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}"
100
111
  }.to_s
101
112
  return true
102
113
  rescue Exception => e
@@ -116,7 +127,7 @@ module Coralogix
116
127
  def get_time_sync
117
128
  @mutex.synchronize do
118
129
  begin
119
- DebugLogger.info "Syncing time with coralogix server"
130
+ DebugLogger.trace "Syncing time with coralogix server"
120
131
  res = @http.get(CORALOGIX_TIME_DELTA_URL)
121
132
 
122
133
  if res.is_a?(Net::HTTPSuccess) && !res.body.to_s.empty?
@@ -129,7 +140,7 @@ module Coralogix
129
140
  local_time = Time.now.utc
130
141
 
131
142
  time_delta = (server_time - local_time) * 1000.0
132
- DebugLogger.info "Updating time delta to: #{time_delta}"
143
+ DebugLogger.trace "Updating time delta to: #{time_delta}"
133
144
  return true, time_delta
134
145
  end
135
146
  return false, 0
data/lib/manager.rb CHANGED
@@ -10,12 +10,12 @@ module Coralogix
10
10
 
11
11
  attr_accessor :configured
12
12
 
13
- def initialize
13
+ def initialize proxy={}
14
14
  @logger_type = "Centralized Ruby"
15
15
  @bulk_template = {:privateKey => FAILED_PRIVATE_KEY, :applicationName => NO_APP_NAME, :subsystemName => NO_SUB_SYSTEM}
16
16
  @time_delta_last_update = 0
17
17
  @time_delta = 0
18
- @http_sender = CoralogixHTTPSender.new
18
+ @http_sender = CoralogixHTTPSender.new proxy
19
19
  @buffer = []
20
20
  @buffer_size = 0
21
21
  @mutex = Mutex.new
@@ -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.12
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Royee Goldberg
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2021-03-15 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
@@ -27,7 +27,7 @@ homepage: http://www.coralogix.com
27
27
  licenses:
28
28
  - MIT
29
29
  metadata: {}
30
- post_install_message:
30
+ post_install_message:
31
31
  rdoc_options: []
32
32
  require_paths:
33
33
  - lib
@@ -42,9 +42,9 @@ 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.5.2
47
- signing_key:
45
+ rubyforge_project:
46
+ rubygems_version: 2.7.3
47
+ signing_key:
48
48
  specification_version: 4
49
49
  summary: Coralogix Centralized Ruby Logger SDK
50
50
  test_files: []