logtail 0.1.1 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/logtail/log_devices/http.rb +11 -1
- data/lib/logtail/log_entry.rb +27 -15
- data/lib/logtail/logger.rb +3 -3
- data/lib/logtail/version.rb +1 -1
- data/spec/logtail/log_entry_spec.rb +5 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0af39db5d892f490e82d5c495f4e51b0646f418a13d4b940566c997aff7e5b1a
|
4
|
+
data.tar.gz: c3e756d0ecc74b2d8128d43914cf677458edce92c8d3bf261047f23a8ae54d65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abd7b6e30cbaa22c698259a59fdaf31a1f46b5c194a14ee9f24b03db08140876c19d25784038235574d9ddbd4b2429ae09f85400291767be88bae60adf023354
|
7
|
+
data.tar.gz: e99b8366d6dcd585f0472091e48b3e4f17f350a3d7ff3a8d97c05022e821a7ab1c05daf5420a512eec76e18ea7e53c3367429bddd53dfeea6488951c9e844c9c
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
-
## [1.0
|
10
|
+
## [0.1.0] - 2021-02-11
|
11
11
|
|
12
12
|
- The first version of the client.
|
13
|
+
|
14
|
+
## [0.1.2] - 2021-04-22
|
15
|
+
|
16
|
+
- Fixed string encoding.
|
17
|
+
|
18
|
+
## [0.1.3] - 2021-06-11
|
19
|
+
|
20
|
+
- Fixed detection of the frame that calls the logger.
|
@@ -201,10 +201,20 @@ MESSAGE
|
|
201
201
|
req['Authorization'] = authorization_payload
|
202
202
|
req['Content-Type'] = CONTENT_TYPE
|
203
203
|
req['User-Agent'] = USER_AGENT
|
204
|
-
req.body = msgs.to_msgpack
|
204
|
+
req.body = msgs.map { |msg| force_utf8_encoding(msg.to_hash) }.to_msgpack
|
205
205
|
req
|
206
206
|
end
|
207
207
|
|
208
|
+
def force_utf8_encoding(data)
|
209
|
+
if data.respond_to?(:force_encoding)
|
210
|
+
data.dup.force_encoding('UTF-8')
|
211
|
+
elsif data.respond_to?(:transform_values)
|
212
|
+
data.transform_values { |val| force_utf8_encoding(val) }
|
213
|
+
else
|
214
|
+
data
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
208
218
|
# Flushes the message buffer asynchronously. The reason we provide this
|
209
219
|
# method is because the message buffer limit is constricted by the
|
210
220
|
# Logtail API. The application limit is multiples of the buffer limit,
|
data/lib/logtail/log_entry.rb
CHANGED
@@ -12,7 +12,7 @@ module Logtail
|
|
12
12
|
BINARY_LIMIT_THRESHOLD = 1_000.freeze
|
13
13
|
DT_PRECISION = 6.freeze
|
14
14
|
MESSAGE_MAX_BYTES = 8192.freeze
|
15
|
-
|
15
|
+
LOGGER_FILE = '/logtail/logger.rb'.freeze
|
16
16
|
|
17
17
|
attr_reader :context_snapshot, :event, :level, :message, :progname, :tags, :time
|
18
18
|
|
@@ -39,6 +39,7 @@ module Logtail
|
|
39
39
|
@tags = options[:tags]
|
40
40
|
@context_snapshot = context_snapshot
|
41
41
|
@event = event
|
42
|
+
@runtime_context = current_runtime_context || {}
|
42
43
|
end
|
43
44
|
|
44
45
|
# Builds a hash representation containing simple objects, suitable for serialization (JSON).
|
@@ -64,7 +65,7 @@ module Logtail
|
|
64
65
|
|
65
66
|
hash[:context] ||= {}
|
66
67
|
hash[:context][:runtime] ||= {}
|
67
|
-
hash[:context][:runtime].merge!(
|
68
|
+
hash[:context][:runtime].merge!(@runtime_context)
|
68
69
|
|
69
70
|
if options[:only]
|
70
71
|
hash.select do |key, _value|
|
@@ -114,32 +115,43 @@ module Logtail
|
|
114
115
|
end
|
115
116
|
|
116
117
|
def current_runtime_context
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
last_logger_invocation_index = caller_locations.rindex { |frame| logtail_logger_frame?(frame) }
|
119
|
+
return {} if last_logger_invocation_index.nil?
|
120
|
+
|
121
|
+
calling_frame_index = last_logger_invocation_index + 1
|
122
|
+
frame = caller_locations[calling_frame_index]
|
123
|
+
return {} if frame.nil?
|
124
|
+
|
125
|
+
return convert_to_runtime_context(frame)
|
120
126
|
end
|
121
127
|
|
122
128
|
def convert_to_runtime_context(frame)
|
123
129
|
{
|
124
|
-
file:
|
130
|
+
file: path_relative_to_app_root(frame),
|
125
131
|
line: frame.lineno,
|
126
132
|
frame_label: frame.label,
|
127
133
|
}
|
128
134
|
end
|
129
135
|
|
130
|
-
def
|
131
|
-
|
132
|
-
logtail_gem_paths.any? { |path| frame.absolute_path.start_with?(path) }
|
136
|
+
def logtail_logger_frame?(frame)
|
137
|
+
!frame.absolute_path.nil? && frame.absolute_path.end_with?(LOGGER_FILE)
|
133
138
|
end
|
134
139
|
|
135
|
-
def
|
136
|
-
|
140
|
+
def path_relative_to_app_root(frame)
|
141
|
+
Pathname.new(frame.absolute_path).relative_path_from(root_path).to_s
|
142
|
+
rescue
|
143
|
+
frame.absolute_path
|
137
144
|
end
|
138
145
|
|
139
|
-
def
|
140
|
-
|
141
|
-
|
142
|
-
|
146
|
+
def root_path
|
147
|
+
if Object.const_defined?('Rails')
|
148
|
+
Rails.root
|
149
|
+
elsif Object.const_defined?('Rack::Directory')
|
150
|
+
Pathname.new(Rack::Directory.new('').root)
|
151
|
+
else
|
152
|
+
base_file = caller_locations.last.absolute_path
|
153
|
+
Pathname.new(File.dirname(base_file || '/'))
|
154
|
+
end
|
143
155
|
end
|
144
156
|
end
|
145
157
|
end
|
data/lib/logtail/logger.rb
CHANGED
@@ -34,14 +34,13 @@ module Logtail
|
|
34
34
|
def build_log_entry(severity, time, progname, logged_obj)
|
35
35
|
context_snapshot = CurrentContext.instance.snapshot
|
36
36
|
level = SEVERITY_MAP.fetch(severity)
|
37
|
-
tags = extract_active_support_tagged_logging_tags
|
37
|
+
tags = extract_active_support_tagged_logging_tags.clone
|
38
38
|
|
39
39
|
if logged_obj.is_a?(Event)
|
40
40
|
LogEntry.new(level, time, progname, logged_obj.message, context_snapshot, logged_obj,
|
41
41
|
tags: tags)
|
42
42
|
elsif logged_obj.is_a?(Hash)
|
43
43
|
# Extract the tags
|
44
|
-
tags = tags.clone
|
45
44
|
tags.push(logged_obj.delete(:tag)) if logged_obj.key?(:tag)
|
46
45
|
tags.concat(logged_obj.delete(:tags)) if logged_obj.key?(:tags)
|
47
46
|
tags.uniq!
|
@@ -56,7 +55,8 @@ module Logtail
|
|
56
55
|
|
57
56
|
# Because of all the crazy ways Rails has attempted tags, we need this crazy method.
|
58
57
|
def extract_active_support_tagged_logging_tags
|
59
|
-
|
58
|
+
@current_tags ||
|
59
|
+
Thread.current[:activesupport_tagged_logging_tags] ||
|
60
60
|
Thread.current[tagged_logging_object_key_name] ||
|
61
61
|
EMPTY_ARRAY
|
62
62
|
end
|
data/lib/logtail/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Logtail::LogEntry do
|
4
|
-
let(:time) { Time.utc(
|
4
|
+
let(:time) { Time.utc(2021, 06, 11, 12, 0, 0) }
|
5
5
|
|
6
6
|
describe "#to_msgpack" do
|
7
7
|
it "should encode properly with an event and context" do
|
@@ -16,20 +16,19 @@ describe Logtail::LogEntry do
|
|
16
16
|
context = {custom: {a: "b"}}
|
17
17
|
log_entry = described_class.new("INFO", time, nil, "log message", context, event)
|
18
18
|
msgpack = log_entry.to_msgpack
|
19
|
-
expect(msgpack).to start_with("\x85\xA5level\xA4INFO\xA2dt\
|
19
|
+
expect(msgpack).to start_with("\x85\xA5level\xA4INFO\xA2dt\xBB2021-06-11T12:00:00.000000Z".force_encoding("ASCII-8BIT"))
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "#to_hash" do
|
24
24
|
it "should include runtime context information" do
|
25
|
-
|
25
|
+
log_entry = Logtail::Logger::PassThroughFormatter.new.call("INFO", time, "", "log message")
|
26
26
|
|
27
|
-
log_entry = described_class.new("INFO", time, nil, "log message", {}, {})
|
28
27
|
hash = log_entry.to_hash
|
29
28
|
expect(hash[:context]).to_not be_nil
|
30
29
|
expect(hash[:context][:runtime]).to_not be_nil
|
31
|
-
expect(hash[:context][:runtime][:file]).
|
32
|
-
expect(hash[:context][:runtime][:line]).
|
30
|
+
expect(hash[:context][:runtime][:file]).to end_with('/spec/logtail/log_entry_spec.rb')
|
31
|
+
expect(hash[:context][:runtime][:line]).to be(25)
|
33
32
|
expect(hash[:context][:runtime][:frame_label]).to_not be_nil
|
34
33
|
end
|
35
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logtail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Logtail
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|