centralized_ruby_logger 0.0.11 → 0.0.16

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: 4dab8cd1a8f5995b0ec46e29b58e6fbfe0a8ca58
4
- data.tar.gz: aec040ce3f19286bfb2528535c5b74af1a63d611
2
+ SHA256:
3
+ metadata.gz: 3bb22fe0d8a38a7ea50b49d947081024babce01aa34f90ff8bfb7ce441dd9574
4
+ data.tar.gz: 367f73a60b64c522257eadc8202a447a8f0189956ef88808aec56dcaddf2afec
5
5
  SHA512:
6
- metadata.gz: cb1a6a2f53882c21fcb499c681e9790beb929d2e7cef9b6bbad15802c932742043c9ade67614c8494dc04f877e00ce42c3ee57eea37cfe0d551a1a5fbf0e22cf
7
- data.tar.gz: 2f92ce54afe38de49a8fc1b0ed2db40c7b9312399f83350f0f20dbb5b71e064706f70d4fae47db6911086621c95f21d958985f398583d4dc7678fde94b47c020
6
+ metadata.gz: 506e90154cc95961cf3937d82ff16ce9ce0d58a80322e2c3436307f1f2614f9cf57b8ed4e0365ab5ec1b9a4d6dea7ca44d562adb8349d3167852b442a071d8b4
7
+ data.tar.gz: c6355047fa329e7be8d38e4a88e43497f302233d8fba782a56acb59ba9fb26cec12de117f71735b1c771820bd3b47ab4a562570f4ddd2354139d371ab08f2b19
@@ -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,33 +4,50 @@ 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
@@ -39,10 +56,12 @@ module Coralogix
39
56
 
40
57
  Logger::Severity.constants.each do |level|
41
58
  define_singleton_method("#{level.downcase}") do |*args|
42
- if @debug
59
+ if @enabled
43
60
  @mutex.synchronize do
44
61
  begin
45
- puts "#{__method__.upcase}: #{Time.now.strftime('%H:%M:%S.%L')} - #{args}"
62
+ if @external == false
63
+ puts "#{__method__.upcase}: #{Time.now.strftime('%H:%M:%S.%L')} - #{args}"
64
+ end
46
65
  @logger.send("#{__method__}", args)
47
66
  rescue Exception => e
48
67
  puts e.message
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
@@ -42,8 +53,8 @@ module Coralogix
42
53
  @http.open_timeout = HTTP_TIMEOUT # seconds
43
54
 
44
55
  headers = {
45
- 'Content-Type': 'application/json',
46
- 'Content-Encoding': 'deflate'
56
+ 'Content-Type' => 'application/json',
57
+ 'Content-Encoding' => 'deflate'
47
58
  }
48
59
  @req = Net::HTTP::Post.new(@uri.path, headers)
49
60
  rescue Exception => e
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
@@ -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
@@ -148,7 +150,7 @@ module Coralogix
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
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.11
4
+ version: 0.0.16
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-11 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: []