logtail 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/logtail/log_entry.rb +24 -15
- 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: 2ba9fd4e5a7de0392375297a8ac475049499afebb82b904ce43615f1b1c5e000
|
4
|
+
data.tar.gz: 0073e828790ded81976eefb1d42d48e0c9eff3123dc47c4c861960bf9a611ff2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c79321cad971e6fa844c08525b6b308594572e728f465561d4f9f594ddb4009047491014f4bc7267292e5d3f3c3d0249e5c0a27d5fb6f7107fd1a79cc10c36e
|
7
|
+
data.tar.gz: 37614b8402998ebfbf9d40741fcbe8085fa4beaf86cd0dfe2b6a2028e08b25a238e26dbd4efb6b5e2406116db2599e135f4f802135d2fc6bbf14e2d3809fcb96
|
data/CHANGELOG.md
CHANGED
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,40 @@ 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
|
+
|
124
|
+
return convert_to_runtime_context(frame)
|
120
125
|
end
|
121
126
|
|
122
127
|
def convert_to_runtime_context(frame)
|
123
128
|
{
|
124
|
-
file:
|
129
|
+
file: path_relative_to_app_root(frame),
|
125
130
|
line: frame.lineno,
|
126
131
|
frame_label: frame.label,
|
127
132
|
}
|
128
133
|
end
|
129
134
|
|
130
|
-
def
|
131
|
-
|
132
|
-
logtail_gem_paths.any? { |path| frame.absolute_path.start_with?(path) }
|
135
|
+
def logtail_logger_frame?(frame)
|
136
|
+
!frame.absolute_path.nil? && frame.absolute_path.end_with?(LOGGER_FILE)
|
133
137
|
end
|
134
138
|
|
135
|
-
def
|
136
|
-
|
139
|
+
def path_relative_to_app_root(frame)
|
140
|
+
Pathname.new(frame.absolute_path).relative_path_from(root_path).to_s
|
137
141
|
end
|
138
142
|
|
139
|
-
def
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
+
def root_path
|
144
|
+
if Object.const_defined?('Rails')
|
145
|
+
Rails.root.to_s
|
146
|
+
elsif Object.const_defined?('Rack::Directory')
|
147
|
+
Rack::Directory.new('').root
|
148
|
+
else
|
149
|
+
base_file = caller_locations.last.absolute_path
|
150
|
+
Pathname.new(File.dirname(base_file || '/'))
|
151
|
+
end
|
143
152
|
end
|
144
153
|
end
|
145
154
|
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.3
|
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-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: msgpack
|