logdna 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/{LICENSE.txt → LICENSE} +5 -5
- data/README.md +10 -3
- data/lib/logdna.rb +64 -92
- data/lib/logdna/client.rb +94 -119
- data/lib/logdna/resources.rb +13 -11
- data/lib/logdna/version.rb +3 -1
- metadata +11 -60
- data/.gitignore +0 -11
- data/.rspec +0 -2
- data/.ruby-version +0 -1
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/logdna.gemspec +0 -32
- data/test.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e53a67887ce8f0010133800e0e1846eef1c9d203
|
4
|
+
data.tar.gz: 1b5ab91a81414693bb8a9d98860038cceacaa780
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8e2d906aaeeecaa01e0340af6d88c16fb01343b06ec4ac91c8450c3975590048f03bf44f68b942058e4d69125a344f3c65ec65d4e8c261b7e2134a29b6c07db
|
7
|
+
data.tar.gz: def81ac988ce294d3e73d8c2f03698c8c5e27a7eed741d1e091c0eea6579dfaa722a98842ef42d70c54a45cbbf5fd9dc20f98dc287e03989e7004e8249138f56
|
data/{LICENSE.txt → LICENSE}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c)
|
3
|
+
Copyright (c) 2019 LogDNA
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
10
10
|
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
14
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -81,7 +81,6 @@ Clear current metadata, level, appname, environment
|
|
81
81
|
logger.clear
|
82
82
|
|
83
83
|
Check current log level:
|
84
|
-
|
85
84
|
logger.info? => true
|
86
85
|
logger.warn? => false
|
87
86
|
|
@@ -94,11 +93,19 @@ Log a message with a particular level easily
|
|
94
93
|
|
95
94
|
Hostname and app name cannot be more than 80 characters.
|
96
95
|
|
96
|
+
### Rails Setup
|
97
|
+
In your `config/environments/environment.rb`:
|
98
|
+
|
99
|
+
```
|
100
|
+
Rails.application.configure do
|
101
|
+
config.logger = Logdna::Ruby.new(your_api_key, options)
|
102
|
+
end
|
103
|
+
```
|
97
104
|
|
98
105
|
# Important Notes
|
99
106
|
|
100
107
|
1. This logger assumes that you pass in json formatted data
|
101
|
-
2. This logger is a singleton (do not create mutiple instances of the logger) even though the singleton structure is not strongly enforced.
|
108
|
+
2. This logger is a singleton (do not create mutiple instances of the logger) even though the singleton structure is not strongly enforced.
|
102
109
|
|
103
110
|
# API
|
104
111
|
|
@@ -119,7 +126,7 @@ Instantiates a new instance of the class it is called on. ingestion_key is requi
|
|
119
126
|
|{ :flushtime => Log flush interval in seconds } | 0.25 seconds |
|
120
127
|
|{ :flushbyte => Log flush upper limit in bytes } | 500000 bytes ~= 0.5 megabytes |
|
121
128
|
|
122
|
-
Different log level displays log messages in different colors as well.
|
129
|
+
Different log level displays log messages in different colors as well.
|
123
130
|
-  "Trace" "Debug" "Info"
|
124
131
|
-  "Warn"
|
125
132
|
-  "Error" "Fatal"
|
data/lib/logdna.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require_relative
|
7
|
-
require_relative
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "logger"
|
4
|
+
require "socket"
|
5
|
+
require "uri"
|
6
|
+
require_relative "logdna/client.rb"
|
7
|
+
require_relative "logdna/resources.rb"
|
8
|
+
require_relative "logdna/version.rb"
|
9
|
+
|
8
10
|
module Logdna
|
9
11
|
class ValidURLRequired < ArgumentError; end
|
10
12
|
class MaxLengthExceeded < ArgumentError; end
|
@@ -13,61 +15,38 @@ module Logdna
|
|
13
15
|
# uncomment line below and line 3 to enforce singleton
|
14
16
|
# include Singleton
|
15
17
|
Logger::TRACE = 5
|
16
|
-
attr_accessor :
|
18
|
+
attr_accessor :app, :env, :meta
|
17
19
|
|
18
|
-
def initialize(key, opts={})
|
19
|
-
@app = opts[:app] ||
|
20
|
-
@
|
20
|
+
def initialize(key, opts = {})
|
21
|
+
@app = opts[:app] || "default"
|
22
|
+
@log_level = opts[:level] || "INFO"
|
21
23
|
@env = opts[:env]
|
22
24
|
@meta = opts[:meta]
|
23
|
-
|
24
|
-
|
25
|
+
@internal_logger = Logger.new(STDOUT)
|
26
|
+
@internal_logger.level = Logger::DEBUG
|
25
27
|
endpoint = opts[:endpoint] || Resources::ENDPOINT
|
26
28
|
hostname = opts[:hostname] || Socket.gethostname
|
27
|
-
ip = opts.key?(:ip) ? "&ip=#{opts[:ip]}" : ''
|
28
|
-
mac = opts.key?(:mac) ? "&mac=#{opts[:mac]}" : ''
|
29
|
-
url = "#{endpoint}?hostname=#{hostname}#{mac}#{ip}"
|
30
|
-
|
31
|
-
begin
|
32
|
-
if (hostname.size > Resources::MAX_INPUT_LENGTH || @app.size > Resources::MAX_INPUT_LENGTH )
|
33
|
-
raise MaxLengthExceeded.new
|
34
|
-
end
|
35
|
-
rescue MaxLengthExceeded => e
|
36
|
-
puts "Hostname or Appname is over #{Resources::MAX_INPUT_LENGTH} characters"
|
37
|
-
handle_exception(e)
|
38
|
-
return
|
39
|
-
end
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
rescue URI::ValidURIRequired => e
|
44
|
-
puts "Invalid URL Endpoint: #{url}"
|
45
|
-
handle_exception(e)
|
30
|
+
if hostname.size > Resources::MAX_INPUT_LENGTH || @app.size > Resources::MAX_INPUT_LENGTH
|
31
|
+
@internal_logger.debug("Hostname or Appname is over #{Resources::MAX_INPUT_LENGTH} characters")
|
46
32
|
return
|
47
33
|
end
|
48
34
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
handle_exception(e)
|
54
|
-
return
|
55
|
-
end
|
56
|
-
|
57
|
-
@@client = Logdna::Client.new(request, uri, opts)
|
58
|
-
end
|
35
|
+
ip = opts.key?(:ip) ? "&ip=#{opts[:ip]}" : ""
|
36
|
+
mac = opts.key?(:mac) ? "&mac=#{opts[:mac]}" : ""
|
37
|
+
url = "#{endpoint}?hostname=#{hostname}#{mac}#{ip}"
|
38
|
+
uri = URI(url)
|
59
39
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
puts exception_message
|
40
|
+
request = Net::HTTP::Post.new(uri.request_uri, "Content-Type" => "application/json")
|
41
|
+
request.basic_auth("username", key)
|
42
|
+
request[:'user-agent'] = opts[:'user-agent'] || "ruby/#{LogDNA::VERSION}"
|
43
|
+
@client = Logdna::Client.new(request, uri, opts)
|
65
44
|
end
|
66
45
|
|
67
46
|
def default_opts
|
68
47
|
{
|
69
48
|
app: @app,
|
70
|
-
level: @
|
49
|
+
level: @log_level,
|
71
50
|
env: @env,
|
72
51
|
meta: @meta,
|
73
52
|
}
|
@@ -75,85 +54,78 @@ module Logdna
|
|
75
54
|
|
76
55
|
def level=(value)
|
77
56
|
if value.is_a? Numeric
|
78
|
-
@
|
57
|
+
@log_level = Resources::LOG_LEVELS[value]
|
79
58
|
return
|
80
59
|
end
|
81
60
|
|
82
|
-
@
|
61
|
+
@log_level = value
|
83
62
|
end
|
84
63
|
|
85
|
-
def log(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
64
|
+
def log(message = nil, opts = {})
|
65
|
+
if message.nil? && block_given?
|
66
|
+
message = yield
|
67
|
+
end
|
68
|
+
if message.nil?
|
69
|
+
@internal_logger.debug("provide either a message or block")
|
70
|
+
return
|
71
|
+
end
|
72
|
+
message = message.to_s.encode("UTF-8")
|
73
|
+
@client.write_to_buffer(message, default_opts.merge(opts).merge(
|
74
|
+
timestamp: (Time.now.to_f * 1000).to_i
|
75
|
+
))
|
93
76
|
end
|
94
77
|
|
95
78
|
Resources::LOG_LEVELS.each do |lvl|
|
96
79
|
name = lvl.downcase
|
97
80
|
|
98
|
-
define_method name do |msg=nil, opts={}, &block|
|
99
|
-
self.log(msg, opts.merge(
|
100
|
-
|
101
|
-
|
81
|
+
define_method name do |msg = nil, opts = {}, &block|
|
82
|
+
self.log(msg, opts.merge(
|
83
|
+
level: lvl
|
84
|
+
), &block)
|
102
85
|
end
|
103
86
|
|
104
87
|
define_method "#{name}?" do
|
105
|
-
return Resources::LOG_LEVELS[self.level] == lvl if
|
88
|
+
return Resources::LOG_LEVELS[self.level] == lvl if level.is_a? Numeric
|
89
|
+
|
106
90
|
self.level == lvl
|
107
91
|
end
|
108
92
|
end
|
109
93
|
|
110
94
|
def clear
|
111
|
-
@app =
|
112
|
-
@
|
95
|
+
@app = "default"
|
96
|
+
@log_level = "INFO"
|
113
97
|
@env = nil
|
114
98
|
@meta = nil
|
115
99
|
end
|
116
100
|
|
117
|
-
def
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def <<(msg=nil, opts={})
|
125
|
-
self.log(msg, opts.merge({
|
126
|
-
level: '',
|
127
|
-
}))
|
101
|
+
def <<(msg = nil, opts = {})
|
102
|
+
log(msg, opts.merge(
|
103
|
+
level: ""
|
104
|
+
))
|
128
105
|
end
|
129
106
|
|
130
|
-
def add(*
|
131
|
-
|
132
|
-
|
107
|
+
def add(*_arg)
|
108
|
+
@internal_logger.debug("add not supported in LogDNA logger")
|
109
|
+
false
|
133
110
|
end
|
134
111
|
|
135
|
-
def unknown(msg=nil, opts={})
|
136
|
-
|
137
|
-
|
138
|
-
|
112
|
+
def unknown(msg = nil, opts = {})
|
113
|
+
log(msg, opts.merge(
|
114
|
+
level: "UNKNOWN"
|
115
|
+
))
|
139
116
|
end
|
140
117
|
|
141
|
-
def datetime_format(*
|
142
|
-
|
143
|
-
|
118
|
+
def datetime_format(*_arg)
|
119
|
+
@internal_logger.debug("datetime_format not supported in LogDNA logger")
|
120
|
+
false
|
144
121
|
end
|
145
122
|
|
146
|
-
|
147
123
|
def close
|
148
|
-
|
149
|
-
@@client.exitout()
|
150
|
-
end
|
124
|
+
@client&.exitout
|
151
125
|
end
|
152
126
|
|
153
127
|
at_exit do
|
154
|
-
|
155
|
-
@@client.exitout()
|
156
|
-
end
|
128
|
+
@client&.exitout
|
157
129
|
end
|
158
130
|
end
|
159
131
|
end
|
data/lib/logdna/client.rb
CHANGED
@@ -1,47 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "socket"
|
5
|
+
require "json"
|
6
|
+
require "concurrent"
|
7
|
+
require "date"
|
6
8
|
|
7
9
|
module Logdna
|
8
10
|
class Client
|
9
|
-
|
10
11
|
def initialize(request, uri, opts)
|
11
12
|
@uri = uri
|
12
13
|
|
13
14
|
# NOTE: buffer is in memory
|
14
|
-
@buffer =
|
15
|
-
@
|
16
|
-
@buffer_over_limit = false
|
15
|
+
@buffer = []
|
16
|
+
@buffer_byte_size = 0
|
17
17
|
|
18
|
-
@side_buffer = StringIO.new
|
19
18
|
@side_messages = []
|
20
19
|
|
21
20
|
@lock = Mutex.new
|
22
|
-
@
|
21
|
+
@side_message_lock = Mutex.new
|
22
|
+
@flush_limit = opts[:flush_size] || Resources::FLUSH_BYTE_LIMIT
|
23
|
+
@flush_interval = opts[:flush_interval] || Resources::FLUSH_INTERVAL
|
24
|
+
@flush_scheduled = false
|
25
|
+
@exception_flag = false
|
23
26
|
|
24
|
-
|
25
|
-
@
|
26
|
-
@actual_flush_interval = opts[:flushtime] ||= Resources::FLUSH_INTERVAL
|
27
|
+
@request = request
|
28
|
+
@retry_timeout = opts[:retry_timeout] || Resources::RETRY_TIMEOUT
|
27
29
|
|
28
|
-
|
30
|
+
@internal_logger = Logger.new(STDOUT)
|
31
|
+
@internal_logger.level = Logger::DEBUG
|
29
32
|
end
|
30
33
|
|
31
|
-
def
|
32
|
-
|
33
|
-
|
34
|
-
begin
|
35
|
-
msg = msg.encode("UTF-8")
|
36
|
-
rescue Encoding::UndefinedConversionError => e
|
37
|
-
# NOTE: should this be raised or handled silently?
|
38
|
-
# raise e
|
39
|
-
end
|
40
|
-
msg
|
41
|
-
end
|
42
|
-
|
43
|
-
def message_hash(msg, opts={})
|
44
|
-
obj = {
|
34
|
+
def process_message(msg, opts = {})
|
35
|
+
processed_message = {
|
45
36
|
line: msg,
|
46
37
|
app: opts[:app],
|
47
38
|
level: opts[:level],
|
@@ -49,116 +40,100 @@ module Logdna
|
|
49
40
|
meta: opts[:meta],
|
50
41
|
timestamp: Time.now.to_i,
|
51
42
|
}
|
52
|
-
|
53
|
-
|
43
|
+
processed_message.delete(:meta) if processed_message[:meta].nil?
|
44
|
+
processed_message
|
54
45
|
end
|
55
46
|
|
56
|
-
def
|
57
|
-
|
47
|
+
def schedule_flush
|
48
|
+
start_timer = lambda {
|
49
|
+
sleep(@exception_flag ? @retry_timeout : @flush_interval)
|
50
|
+
flush if @flush_scheduled
|
51
|
+
}
|
52
|
+
thread = Thread.new { start_timer.call }
|
53
|
+
thread.join
|
54
|
+
end
|
58
55
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
56
|
+
def write_to_buffer(msg, opts)
|
57
|
+
if @lock.try_lock
|
58
|
+
processed_message = process_message(msg, opts)
|
59
|
+
new_message_size = processed_message.to_s.bytesize
|
60
|
+
@buffer.push(processed_message)
|
61
|
+
@buffer_byte_size += new_message_size
|
62
|
+
@flush_scheduled = true
|
63
|
+
@lock.unlock
|
64
|
+
|
65
|
+
if @flush_limit <= @buffer_byte_size
|
66
|
+
flush
|
66
67
|
else
|
67
|
-
|
68
|
-
|
68
|
+
schedule_flush
|
69
|
+
end
|
70
|
+
else
|
71
|
+
@side_message_lock.synchronize do
|
72
|
+
@side_messages.push(process_message(msg, opts))
|
69
73
|
end
|
70
|
-
end
|
71
|
-
t.execute
|
72
|
-
end
|
73
|
-
|
74
|
-
def check_side_buffer
|
75
|
-
return if @side_buffer.size == 0
|
76
|
-
|
77
|
-
@buffer.write(@side_buffer.string)
|
78
|
-
@side_buffer.truncate(0)
|
79
|
-
queued_side_messages = @side_messages
|
80
|
-
@side_messages = []
|
81
|
-
queued_side_messages.each { |message_hash_obj| @messages.push(message_hash_obj) }
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
# this should always be running synchronously within this thread
|
86
|
-
def buffer(msg, opts)
|
87
|
-
buffer_size = write_to_buffer(msg, opts)
|
88
|
-
unless buffer_size.nil?
|
89
|
-
process_buffer(buffer_size)
|
90
74
|
end
|
91
75
|
end
|
92
76
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
@side_buffer.write(msg)
|
99
|
-
@side_messages.push(message_hash(msg, opts))
|
100
|
-
return
|
77
|
+
# This method has to be called with @lock
|
78
|
+
def send_request
|
79
|
+
@side_message_lock.synchronize do
|
80
|
+
@buffer.concat(@side_messages)
|
81
|
+
@side_messages.clear
|
101
82
|
end
|
102
83
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
84
|
+
@request.body = {
|
85
|
+
e: "ls",
|
86
|
+
ls: @buffer
|
87
|
+
}.to_json
|
108
88
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
if buffer_size > @actual_byte_limit
|
116
|
-
@buffer_over_limit = true
|
117
|
-
flush()
|
118
|
-
@buffer_over_limit = false
|
119
|
-
else
|
120
|
-
@task = create_flush_task
|
89
|
+
handle_exception = lambda do |message|
|
90
|
+
@internal_logger.debug(message)
|
91
|
+
@exception_flag = true
|
92
|
+
@side_message_lock.synchronize do
|
93
|
+
@side_messages.concat(@buffer)
|
94
|
+
end
|
121
95
|
end
|
122
|
-
end
|
123
96
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
@buffer.truncate(0)
|
132
|
-
@messages = []
|
97
|
+
begin
|
98
|
+
@response = Net::HTTP.start(
|
99
|
+
@uri.hostname,
|
100
|
+
@uri.port,
|
101
|
+
use_ssl: @uri.scheme == "https"
|
102
|
+
) do |http|
|
103
|
+
http.request(@request)
|
133
104
|
end
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
ls: request_messages,
|
139
|
-
}.to_json
|
140
|
-
|
141
|
-
@@request.body = real
|
142
|
-
@response = Net::HTTP.start(@uri.hostname, @uri.port, use_ssl: @uri.scheme == 'https') do |http|
|
143
|
-
http.request(@@request)
|
105
|
+
if @response.is_a?(Net::HTTPForbidden)
|
106
|
+
@internal_logger.debug("Please provide a valid ingestion key")
|
107
|
+
elsif !@response.is_a?(Net::HTTPSuccess)
|
108
|
+
handle_exception.call("The response is not successful #{@response}")
|
144
109
|
end
|
110
|
+
@exception_flag = false
|
111
|
+
rescue SocketError
|
112
|
+
handle_exception.call("Network connectivity issue")
|
113
|
+
rescue Errno::ECONNREFUSED => e
|
114
|
+
handle_exception.call("The server is down. #{e.message}")
|
115
|
+
rescue Timeout::Error => e
|
116
|
+
handle_exception.call("Timeout error occurred. #{e.message}")
|
117
|
+
ensure
|
118
|
+
@buffer.clear
|
119
|
+
end
|
120
|
+
end
|
145
121
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
122
|
+
def flush
|
123
|
+
if @lock.try_lock
|
124
|
+
@flush_scheduled = false
|
125
|
+
if @buffer.any? || @side_messages.any?
|
126
|
+
send_request
|
151
127
|
end
|
128
|
+
@lock.unlock
|
129
|
+
else
|
130
|
+
schedule_flush
|
152
131
|
end
|
153
132
|
end
|
154
133
|
|
155
|
-
def exitout
|
156
|
-
|
157
|
-
|
158
|
-
flush()
|
159
|
-
end
|
160
|
-
puts "Exiting LogDNA logger: Logging remaining messages"
|
161
|
-
return
|
134
|
+
def exitout
|
135
|
+
flush
|
136
|
+
@internal_logger.debug("Exiting LogDNA logger: Logging remaining messages")
|
162
137
|
end
|
163
138
|
end
|
164
139
|
end
|
data/lib/logdna/resources.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Resources
|
2
|
-
LOG_LEVELS = [
|
3
|
-
DEFAULT_REQUEST_HEADER = {
|
4
|
-
DEFAULT_REQUEST_TIMEOUT =
|
5
|
-
MS_IN_A_DAY =
|
6
|
-
MAX_REQUEST_TIMEOUT =
|
7
|
-
MAX_LINE_LENGTH =
|
4
|
+
LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE].freeze
|
5
|
+
DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" }.freeze
|
6
|
+
DEFAULT_REQUEST_TIMEOUT = 180_000
|
7
|
+
MS_IN_A_DAY = 86_400_000
|
8
|
+
MAX_REQUEST_TIMEOUT = 300_000
|
9
|
+
MAX_LINE_LENGTH = 32_000
|
8
10
|
MAX_INPUT_LENGTH = 80
|
11
|
+
RETRY_TIMEOUT = 60
|
9
12
|
FLUSH_INTERVAL = 0.25
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
|
13
|
+
FLUSH_BYTE_LIMIT = 500_000
|
14
|
+
ENDPOINT = "https://logs.logdna.com/logs/ingest"
|
15
|
+
MAC_ADDR_CHECK = /^([0-9a-fA-F][0-9a-fA-F]:){5}([0-9a-fA-F][0-9a-fA-F])$/.freeze
|
16
|
+
IP_ADDR_CHECK = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.freeze
|
15
17
|
end
|
data/lib/logdna/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logdna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Gun Woo Choi, Derek Zhou
|
7
|
+
- Gun Woo Choi, Derek Zhou, Vilya Levitskiy, Muaz Siddiqui
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: require_all
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.4'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.4'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: json
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,80 +39,45 @@ dependencies:
|
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '2.0'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '1.13'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '1.13'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rake
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '10.5'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '10.5'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
42
|
+
name: require_all
|
85
43
|
requirement: !ruby/object:Gem::Requirement
|
86
44
|
requirements:
|
87
45
|
- - "~>"
|
88
46
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
90
|
-
type: :
|
47
|
+
version: '1.4'
|
48
|
+
type: :runtime
|
91
49
|
prerelease: false
|
92
50
|
version_requirements: !ruby/object:Gem::Requirement
|
93
51
|
requirements:
|
94
52
|
- - "~>"
|
95
53
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
54
|
+
version: '1.4'
|
97
55
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
56
|
+
name: rubocop
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
100
58
|
requirements:
|
101
59
|
- - "~>"
|
102
60
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
61
|
+
version: '0.78'
|
104
62
|
type: :development
|
105
63
|
prerelease: false
|
106
64
|
version_requirements: !ruby/object:Gem::Requirement
|
107
65
|
requirements:
|
108
66
|
- - "~>"
|
109
67
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
68
|
+
version: '0.78'
|
111
69
|
description:
|
112
70
|
email: support@logdna.com
|
113
71
|
executables: []
|
114
72
|
extensions: []
|
115
73
|
extra_rdoc_files: []
|
116
74
|
files:
|
117
|
-
-
|
118
|
-
- ".rspec"
|
119
|
-
- ".ruby-version"
|
120
|
-
- Gemfile
|
121
|
-
- LICENSE.txt
|
75
|
+
- LICENSE
|
122
76
|
- README.md
|
123
|
-
- Rakefile
|
124
77
|
- lib/logdna.rb
|
125
78
|
- lib/logdna/client.rb
|
126
79
|
- lib/logdna/resources.rb
|
127
80
|
- lib/logdna/version.rb
|
128
|
-
- logdna.gemspec
|
129
|
-
- test.rb
|
130
81
|
homepage: https://github.com/logdna/ruby
|
131
82
|
licenses:
|
132
83
|
- MIT
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.ruby-version
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
2.2.0
|
data/Gemfile
DELETED
data/Rakefile
DELETED
data/logdna.gemspec
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'logdna/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = 'logdna'
|
8
|
-
spec.version = LogDNA::VERSION
|
9
|
-
spec.authors = 'Gun Woo Choi, Derek Zhou'
|
10
|
-
spec.email = 'support@logdna.com'
|
11
|
-
|
12
|
-
spec.summary = 'LogDNA Ruby logger'
|
13
|
-
spec.homepage = 'https://github.com/logdna/ruby'
|
14
|
-
spec.license = 'MIT'
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
-
f.match(%r{^(test|spec|features)/})
|
18
|
-
end
|
19
|
-
spec.bindir = 'exe'
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ['lib']
|
22
|
-
|
23
|
-
|
24
|
-
spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
|
25
|
-
spec.add_runtime_dependency 'require_all', '~> 1.4'
|
26
|
-
spec.add_runtime_dependency 'json', '~> 2.0'
|
27
|
-
|
28
|
-
spec.add_development_dependency 'bundler', '~> 1.13'
|
29
|
-
spec.add_development_dependency 'rake', '~> 10.5'
|
30
|
-
spec.add_development_dependency 'rspec', '~> 3.5'
|
31
|
-
spec.add_development_dependency 'webmock', '~> 2.3'
|
32
|
-
end
|
data/test.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
require 'require_all'
|
2
|
-
require_all 'lib'
|
3
|
-
|
4
|
-
|
5
|
-
options = {hostname: "new_ruby", meta:{:once => {:first => "nested1", :another => "nested2"}}}
|
6
|
-
|
7
|
-
|
8
|
-
logger1 = Logdna::Ruby.new('Your API Key', options)
|
9
|
-
|
10
|
-
logger1.log('**************** This is the start of test ****************')
|
11
|
-
logger1.env = 'STAGING'
|
12
|
-
logger1.app = 'HELLO'
|
13
|
-
logger1.warn('Warn message with Staging and Hello')
|
14
|
-
logger1.clear
|
15
|
-
logger1.log('Is everything back to normal?')
|
16
|
-
|
17
|
-
|
18
|
-
logger1.log('Testing env app name change using log')
|
19
|
-
logger1.env = 'PRODUCTION'
|
20
|
-
logger1.app = 'CHANGED'
|
21
|
-
logger1.log('This should be stage = PRODUCTION and appname = CHANGED')
|
22
|
-
logger1.log('Testing env app name change using other messages')
|
23
|
-
|
24
|
-
|
25
|
-
logger1.error('This is error message with env = DEVELOPMENT and appname = NIHAO', {:env => 'DEVELOPMENT', :app => 'NIHAO'})
|
26
|
-
logger1.log('Should not stay as DEVELOPMENT and NIHAO')
|
27
|
-
logger1.env = 'DEVELOPMENT'
|
28
|
-
logger1.app = 'NIHAO'
|
29
|
-
logger1.log('Now should be DEVELOPMENT and NIHAO')
|
30
|
-
logger1.log('Logging metadata in trace level', {:meta => {:once => {:first => "nested1", :another => "nested2"}}, :level => "TRACE"})
|
31
|
-
|
32
|
-
|
33
|
-
logger1.level = Logger::DEBUG
|
34
|
-
logger1.log('This is debug message')
|
35
|
-
logger1.add('this should not be supported')
|
36
|
-
logger1.fatal('Does this continue as fatal?')
|
37
|
-
logger1.log('This should be debug')
|
38
|
-
logger1.level = Logger::WARN
|
39
|
-
logger1.log('**************** This is the end of test ****************')
|
40
|
-
|
41
|
-
|
42
|
-
=begin
|
43
|
-
logger1.level = Logger::WARN
|
44
|
-
logger1.log('This should be warn')
|
45
|
-
logger1.trace('This should be trace')
|
46
|
-
logger1.log('Again warn level')
|
47
|
-
|
48
|
-
logger1.log('Warn level log1')
|
49
|
-
logger1.info('Info level log1')
|
50
|
-
logger1.level = Logger::DEBUG
|
51
|
-
logger1.log('DEBUG log1')
|
52
|
-
|
53
|
-
logger1.app = 'NEW APP NAME'
|
54
|
-
logger1.env = 'Staging'
|
55
|
-
logger1.level = 'INFO'
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
logger1.level = 'INFO'
|
60
|
-
logger1.level == Logger::INFO
|
61
|
-
|
62
|
-
|
63
|
-
logger1.log('are changes all updated')
|
64
|
-
=end
|
65
|
-
sleep 3
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|