loga 2.7.0 → 2.8.1
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/.github/workflows/build-and-test.yml +72 -0
- data/.github/workflows/publish-gem.yml +28 -0
- data/.rubocop.yml +4 -0
- data/.rubocop_todo.yml +206 -0
- data/Appraisals +58 -46
- data/CHANGELOG.md +10 -0
- data/Gemfile +22 -0
- data/gemfiles/rails52.gemfile +23 -1
- data/gemfiles/rails60.gemfile +22 -0
- data/gemfiles/rails61.gemfile +22 -0
- data/gemfiles/rails70.gemfile +24 -0
- data/gemfiles/rails71.gemfile +35 -0
- data/gemfiles/sidekiq51.gemfile +22 -0
- data/gemfiles/sidekiq60.gemfile +22 -0
- data/gemfiles/sidekiq61.gemfile +22 -0
- data/gemfiles/sidekiq62.gemfile +22 -0
- data/gemfiles/sidekiq63.gemfile +22 -0
- data/gemfiles/sidekiq64.gemfile +22 -0
- data/gemfiles/sidekiq65.gemfile +22 -0
- data/gemfiles/sidekiq7.gemfile +22 -0
- data/gemfiles/sidekiq70.gemfile +22 -0
- data/gemfiles/sidekiq71.gemfile +22 -0
- data/gemfiles/sinatra14.gemfile +22 -0
- data/gemfiles/sinatra2.gemfile +33 -0
- data/gemfiles/sinatra3.gemfile +33 -0
- data/gemfiles/sinatra4.gemfile +33 -0
- data/gemfiles/unit.gemfile +22 -0
- data/lib/loga/formatters/gelf_formatter.rb +13 -6
- data/lib/loga/railtie.rb +2 -2
- data/lib/loga/version.rb +1 -1
- data/loga.gemspec +0 -15
- data/spec/fixtures/{rails50.rb → rails71.rb} +1 -1
- data/spec/integration/rails/action_mailer_spec.rb +2 -0
- data/spec/integration/rails/railtie_spec.rb +13 -3
- data/spec/integration/rails/request_spec.rb +4 -2
- data/spec/integration/sidekiq5_spec.rb +15 -13
- data/spec/integration/sidekiq60_spec.rb +3 -3
- data/spec/integration/sidekiq61_spec.rb +6 -4
- data/spec/integration/sidekiq65_spec.rb +1 -1
- data/spec/integration/sinatra_spec.rb +9 -6
- data/spec/loga/sidekiq5/job_logger_spec.rb +2 -0
- data/spec/loga/sidekiq6/job_logger_spec.rb +3 -1
- data/spec/loga/sidekiq7/job_logger_spec.rb +3 -1
- data/spec/loga/sidekiq_spec.rb +4 -2
- data/spec/spec_helper.rb +6 -3
- data/spec/support/gethostname_shared.rb +3 -1
- data/spec/support/helpers.rb +2 -0
- data/spec/support/request_spec.rb +83 -81
- data/spec/support/timecop_shared.rb +3 -1
- data/spec/unit/loga/configuration_spec.rb +11 -9
- data/spec/unit/loga/event_spec.rb +4 -2
- data/spec/unit/loga/formatters/gelf_formatter_spec.rb +38 -13
- data/spec/unit/loga/formatters/simple_formatter_spec.rb +7 -5
- data/spec/unit/loga/log_subscribers/action_mailer_spec.rb +6 -4
- data/spec/unit/loga/parameter_filter_spec.rb +2 -0
- data/spec/unit/loga/rack/logger_spec.rb +18 -16
- data/spec/unit/loga/rack/request_spec.rb +2 -0
- data/spec/unit/loga/service_version_strategies_spec.rb +2 -0
- data/spec/unit/loga/utilities_spec.rb +2 -0
- data/spec/unit/loga_spec.rb +3 -1
- metadata +12 -206
- data/.circleci/config.yml +0 -112
- data/gemfiles/rails42.gemfile +0 -11
- data/gemfiles/rails50.gemfile +0 -11
- data/spec/fixtures/rails42.rb +0 -80
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'timecop'
|
3
5
|
require 'fakeredis'
|
@@ -27,8 +29,8 @@ describe 'Sidekiq client logger' do
|
|
27
29
|
attr_reader :latest_error, :mutex, :cond
|
28
30
|
|
29
31
|
def initialize
|
30
|
-
@mutex =
|
31
|
-
@cond =
|
32
|
+
@mutex = Mutex.new
|
33
|
+
@cond = ConditionVariable.new
|
32
34
|
end
|
33
35
|
|
34
36
|
def processor_died(_inst, err)
|
@@ -46,7 +48,7 @@ describe 'Sidekiq client logger' do
|
|
46
48
|
concurrency: 3,
|
47
49
|
queues: ['default'],
|
48
50
|
job_logger: Loga::Sidekiq6::JobLogger,
|
49
|
-
}.tap { |opts| opts[:fetch] =
|
51
|
+
}.tap { |opts| opts[:fetch] = Sidekiq::BasicFetch.new(opts) }
|
50
52
|
end
|
51
53
|
end
|
52
54
|
end
|
@@ -87,7 +89,7 @@ describe 'Sidekiq client logger' do
|
|
87
89
|
aggregate_failures do
|
88
90
|
expect(last_element['class']).to eq 'MySidekiqWorker'
|
89
91
|
expect(last_element['args']).to eq ['Bob']
|
90
|
-
expect(last_element['retry']).to
|
92
|
+
expect(last_element['retry']).to be true
|
91
93
|
expect(last_element['queue']).to eq 'default'
|
92
94
|
end
|
93
95
|
end
|
@@ -75,7 +75,7 @@ describe 'Sidekiq client logger' do
|
|
75
75
|
aggregate_failures do
|
76
76
|
expect(last_element['class']).to eq 'MySidekiqWorker'
|
77
77
|
expect(last_element['args']).to eq ['Bob']
|
78
|
-
expect(last_element['retry']).to
|
78
|
+
expect(last_element['retry']).to be true
|
79
79
|
expect(last_element['queue']).to eq 'default'
|
80
80
|
end
|
81
81
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
class MySinatraApp < Sinatra::Base
|
@@ -21,7 +23,7 @@ class MySinatraApp < Sinatra::Base
|
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
RSpec.describe 'Structured logging with Sinatra', :
|
26
|
+
RSpec.describe 'Structured logging with Sinatra', :timecop, :with_hostname do
|
25
27
|
let(:io) { StringIO.new }
|
26
28
|
let(:format) {}
|
27
29
|
let(:last_log_entry) do
|
@@ -69,12 +71,12 @@ RSpec.describe 'Structured logging with Sinatra', :with_hostname, :timecop do
|
|
69
71
|
let(:data) do
|
70
72
|
{
|
71
73
|
'method' => 'GET',
|
72
|
-
'path'
|
74
|
+
'path' => '/ok',
|
73
75
|
'params' => { 'username'=>'yoshi' },
|
74
76
|
'request_id' => '700a6a01',
|
75
77
|
'request_ip' => '127.0.0.1',
|
76
78
|
'user_agent' => nil,
|
77
|
-
'duration'
|
79
|
+
'duration' => 0,
|
78
80
|
'status' => 200,
|
79
81
|
}
|
80
82
|
end
|
@@ -97,7 +99,7 @@ RSpec.describe 'Structured logging with Sinatra', :with_hostname, :timecop do
|
|
97
99
|
let(:data) do
|
98
100
|
super().merge(
|
99
101
|
'status' => 302,
|
100
|
-
'path'
|
102
|
+
'path' => '/new',
|
101
103
|
'params' => {},
|
102
104
|
)
|
103
105
|
end
|
@@ -112,14 +114,15 @@ RSpec.describe 'Structured logging with Sinatra', :with_hostname, :timecop do
|
|
112
114
|
let(:data) do
|
113
115
|
super().merge(
|
114
116
|
'status' => 500,
|
115
|
-
'path'
|
117
|
+
'path' => '/error',
|
116
118
|
'params' => {},
|
117
119
|
)
|
118
120
|
end
|
119
121
|
|
120
122
|
it 'logs the request with the exception' do
|
121
123
|
get '/error', {}, 'HTTP_X_REQUEST_ID' => '700a6a01'
|
122
|
-
|
124
|
+
|
125
|
+
expect(last_log_entry).to start_with("E, #{time_pid_tags} GET /error 500 in 0ms type=request #{data_as_text} exception=undefined method `name' for nil")
|
123
126
|
end
|
124
127
|
end
|
125
128
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'loga/sidekiq6/job_logger'
|
3
5
|
|
@@ -24,7 +26,7 @@ RSpec.describe Loga::Sidekiq6::JobLogger do
|
|
24
26
|
|
25
27
|
# https://github.com/mperham/sidekiq/blob/v6.1.2/lib/sidekiq/job_logger.rb
|
26
28
|
it 'inherits from ::Sidekiq::JobLogger' do
|
27
|
-
expect(subject).to be_a(
|
29
|
+
expect(subject).to be_a(Sidekiq::JobLogger)
|
28
30
|
end
|
29
31
|
|
30
32
|
describe '#call' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'loga/sidekiq7/job_logger'
|
3
5
|
|
@@ -26,7 +28,7 @@ RSpec.describe Loga::Sidekiq7::JobLogger do
|
|
26
28
|
|
27
29
|
# https://github.com/mperham/sidekiq/blob/v6.1.2/lib/sidekiq/job_logger.rb
|
28
30
|
it 'inherits from ::Sidekiq::JobLogger' do
|
29
|
-
expect(subject).to be_a(
|
31
|
+
expect(subject).to be_a(Sidekiq::JobLogger)
|
30
32
|
end
|
31
33
|
|
32
34
|
describe '#call' do
|
data/spec/loga/sidekiq_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
RSpec.describe Loga::Sidekiq do
|
@@ -32,9 +34,9 @@ RSpec.describe Loga::Sidekiq do
|
|
32
34
|
|
33
35
|
case m['version']
|
34
36
|
when '51'
|
35
|
-
expect(
|
37
|
+
expect(Sidekiq.options[:job_logger]).to eq(Loga::Sidekiq5::JobLogger)
|
36
38
|
when '6'
|
37
|
-
expect(
|
39
|
+
expect(Sidekiq.options[:job_logger]).to eq(Loga::Sidekiq6::JobLogger)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'byebug'
|
2
4
|
require 'pry'
|
3
5
|
require 'support/gethostname_shared'
|
@@ -8,16 +10,17 @@ require 'rack/test'
|
|
8
10
|
require 'simplecov'
|
9
11
|
|
10
12
|
SimpleCov.start do
|
11
|
-
command_name "ruby-#{RUBY_VERSION}-#{File.basename(ENV
|
13
|
+
command_name "ruby-#{RUBY_VERSION}-#{File.basename(ENV.fetch('BUNDLE_GEMFILE', nil),
|
14
|
+
'.gemfile')}"
|
12
15
|
|
13
16
|
# Exclude specs from showing up in the code coverage report.
|
14
17
|
add_filter 'spec/'
|
15
18
|
end
|
16
19
|
|
17
|
-
case ENV
|
20
|
+
case ENV.fetch('BUNDLE_GEMFILE', nil)
|
18
21
|
when /rails/
|
19
22
|
rspec_pattern = 'integration/rails/**/*_spec.rb'
|
20
|
-
/(?<appraisal>rails\d{2})\.gemfile/ =~ ENV
|
23
|
+
/(?<appraisal>rails\d{2})\.gemfile/ =~ ENV.fetch('BUNDLE_GEMFILE', nil)
|
21
24
|
require 'rails'
|
22
25
|
require 'action_mailer'
|
23
26
|
require File.expand_path("../fixtures/#{appraisal}.rb", __FILE__)
|
data/spec/support/helpers.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.shared_examples 'request logger' do
|
2
4
|
describe 'get request' do
|
3
5
|
it 'logs the request' do
|
@@ -6,23 +8,23 @@ RSpec.shared_examples 'request logger' do
|
|
6
8
|
'HTTP_USER_AGENT' => 'Chrome', 'HTTP_X_REQUEST_ID' => '471a34dc'
|
7
9
|
|
8
10
|
expect(last_log_entry).to include(
|
9
|
-
'version'
|
10
|
-
'host'
|
11
|
-
'short_message'
|
12
|
-
'timestamp'
|
13
|
-
'level'
|
14
|
-
'_type'
|
15
|
-
'_service.name'
|
16
|
-
'_service.version'
|
17
|
-
'_request.method'
|
18
|
-
'_request.path'
|
19
|
-
'_request.params'
|
11
|
+
'version' => '1.1',
|
12
|
+
'host' => 'bird.example.com',
|
13
|
+
'short_message' => 'GET /ok?username=yoshi 200 in 0ms',
|
14
|
+
'timestamp' => 1_450_150_205.123,
|
15
|
+
'level' => 6,
|
16
|
+
'_type' => 'request',
|
17
|
+
'_service.name' => 'hello_world_app',
|
18
|
+
'_service.version' => '1.0',
|
19
|
+
'_request.method' => 'GET',
|
20
|
+
'_request.path' => '/ok',
|
21
|
+
'_request.params' => { 'username' => 'yoshi' },
|
20
22
|
'_request.request_ip' => '127.0.0.1',
|
21
23
|
'_request.user_agent' => 'Chrome',
|
22
|
-
'_request.status'
|
24
|
+
'_request.status' => 200,
|
23
25
|
'_request.request_id' => '471a34dc',
|
24
|
-
'_request.duration'
|
25
|
-
'_tags'
|
26
|
+
'_request.duration' => 0,
|
27
|
+
'_tags' => '471a34dc TEST_TAG',
|
26
28
|
)
|
27
29
|
end
|
28
30
|
end
|
@@ -36,23 +38,23 @@ RSpec.shared_examples 'request logger' do
|
|
36
38
|
'HTTP_USER_AGENT' => 'Chrome', 'HTTP_X_REQUEST_ID' => '471a34dc'
|
37
39
|
|
38
40
|
expect(last_log_entry).to include(
|
39
|
-
'version'
|
40
|
-
'host'
|
41
|
-
'short_message'
|
42
|
-
'timestamp'
|
43
|
-
'level'
|
44
|
-
'_type'
|
45
|
-
'_service.name'
|
46
|
-
'_service.version'
|
47
|
-
'_request.method'
|
48
|
-
'_request.path'
|
49
|
-
'_request.params'
|
41
|
+
'version' => '1.1',
|
42
|
+
'host' => 'bird.example.com',
|
43
|
+
'short_message' => 'POST /users?username=yoshi 200 in 0ms',
|
44
|
+
'timestamp' => 1_450_150_205.123,
|
45
|
+
'level' => 6,
|
46
|
+
'_type' => 'request',
|
47
|
+
'_service.name' => 'hello_world_app',
|
48
|
+
'_service.version' => '1.0',
|
49
|
+
'_request.method' => 'POST',
|
50
|
+
'_request.path' => '/users',
|
51
|
+
'_request.params' => { 'username' => 'yoshi', 'email' => 'hello@world.com' },
|
50
52
|
'_request.request_ip' => '127.0.0.1',
|
51
53
|
'_request.user_agent' => 'Chrome',
|
52
|
-
'_request.status'
|
54
|
+
'_request.status' => 200,
|
53
55
|
'_request.request_id' => '471a34dc',
|
54
|
-
'_request.duration'
|
55
|
-
'_tags'
|
56
|
+
'_request.duration' => 0,
|
57
|
+
'_tags' => '471a34dc TEST_TAG',
|
56
58
|
)
|
57
59
|
end
|
58
60
|
|
@@ -68,23 +70,23 @@ RSpec.shared_examples 'request logger' do
|
|
68
70
|
get '/new', {}, 'HTTP_USER_AGENT' => 'Chrome', 'HTTP_X_REQUEST_ID' => '471a34dc'
|
69
71
|
|
70
72
|
expect(last_log_entry).to include(
|
71
|
-
'version'
|
72
|
-
'host'
|
73
|
-
'short_message'
|
74
|
-
'timestamp'
|
75
|
-
'level'
|
76
|
-
'_type'
|
77
|
-
'_service.name'
|
78
|
-
'_service.version'
|
79
|
-
'_request.method'
|
80
|
-
'_request.path'
|
81
|
-
'_request.params'
|
73
|
+
'version' => '1.1',
|
74
|
+
'host' => 'bird.example.com',
|
75
|
+
'short_message' => 'GET /new 302 in 0ms',
|
76
|
+
'timestamp' => 1_450_150_205.123,
|
77
|
+
'level' => 6,
|
78
|
+
'_type' => 'request',
|
79
|
+
'_service.name' => 'hello_world_app',
|
80
|
+
'_service.version' => '1.0',
|
81
|
+
'_request.method' => 'GET',
|
82
|
+
'_request.path' => '/new',
|
83
|
+
'_request.params' => {},
|
82
84
|
'_request.request_ip' => '127.0.0.1',
|
83
85
|
'_request.user_agent' => 'Chrome',
|
84
|
-
'_request.status'
|
86
|
+
'_request.status' => 302,
|
85
87
|
'_request.request_id' => '471a34dc',
|
86
|
-
'_request.duration'
|
87
|
-
'_tags'
|
88
|
+
'_request.duration' => 0,
|
89
|
+
'_tags' => '471a34dc TEST_TAG',
|
88
90
|
)
|
89
91
|
end
|
90
92
|
end
|
@@ -96,26 +98,26 @@ RSpec.shared_examples 'request logger' do
|
|
96
98
|
'HTTP_USER_AGENT' => 'Chrome', 'HTTP_X_REQUEST_ID' => '471a34dc'
|
97
99
|
|
98
100
|
expect(last_log_entry).to include(
|
99
|
-
'version'
|
100
|
-
'host'
|
101
|
-
'short_message'
|
102
|
-
'timestamp'
|
103
|
-
'level'
|
104
|
-
'_type'
|
105
|
-
'_service.name'
|
106
|
-
'_service.version'
|
107
|
-
'_request.method'
|
108
|
-
'_request.path'
|
109
|
-
'_request.params'
|
110
|
-
'_request.request_ip'
|
111
|
-
'_request.user_agent'
|
112
|
-
'_request.status'
|
113
|
-
'_request.request_id'
|
114
|
-
'_request.duration'
|
115
|
-
'_exception.klass'
|
116
|
-
'_exception.message'
|
101
|
+
'version' => '1.1',
|
102
|
+
'host' => 'bird.example.com',
|
103
|
+
'short_message' => 'GET /error?username=yoshi 500 in 0ms',
|
104
|
+
'timestamp' => 1_450_150_205.123,
|
105
|
+
'level' => 3,
|
106
|
+
'_type' => 'request',
|
107
|
+
'_service.name' => 'hello_world_app',
|
108
|
+
'_service.version' => '1.0',
|
109
|
+
'_request.method' => 'GET',
|
110
|
+
'_request.path' => '/error',
|
111
|
+
'_request.params' => { 'username' => 'yoshi' },
|
112
|
+
'_request.request_ip' => '127.0.0.1',
|
113
|
+
'_request.user_agent' => 'Chrome',
|
114
|
+
'_request.status' => 500,
|
115
|
+
'_request.request_id' => '471a34dc',
|
116
|
+
'_request.duration' => 0,
|
117
|
+
'_exception.klass' => 'NoMethodError',
|
118
|
+
'_exception.message' => start_with("undefined method `name' for nil"),
|
117
119
|
'_exception.backtrace' => be_a(String),
|
118
|
-
'_tags'
|
120
|
+
'_tags' => '471a34dc TEST_TAG',
|
119
121
|
)
|
120
122
|
end
|
121
123
|
end
|
@@ -125,23 +127,23 @@ RSpec.shared_examples 'request logger' do
|
|
125
127
|
get '/not_found', {}, 'HTTP_X_REQUEST_ID' => '471a34dc'
|
126
128
|
|
127
129
|
expect(last_log_entry).to include(
|
128
|
-
'version'
|
129
|
-
'host'
|
130
|
-
'short_message'
|
131
|
-
'timestamp'
|
132
|
-
'level'
|
133
|
-
'_type'
|
134
|
-
'_service.name'
|
135
|
-
'_service.version'
|
136
|
-
'_request.method'
|
137
|
-
'_request.path'
|
138
|
-
'_request.params'
|
139
|
-
'_request.request_ip'
|
140
|
-
'_request.user_agent'
|
141
|
-
'_request.status'
|
142
|
-
'_request.request_id'
|
143
|
-
'_request.duration'
|
144
|
-
'_tags'
|
130
|
+
'version' => '1.1',
|
131
|
+
'host' => 'bird.example.com',
|
132
|
+
'short_message' => 'GET /not_found 404 in 0ms',
|
133
|
+
'timestamp' => 1_450_150_205.123,
|
134
|
+
'level' => 6,
|
135
|
+
'_type' => 'request',
|
136
|
+
'_service.name' => 'hello_world_app',
|
137
|
+
'_service.version' => '1.0',
|
138
|
+
'_request.method' => 'GET',
|
139
|
+
'_request.path' => '/not_found',
|
140
|
+
'_request.params' => {},
|
141
|
+
'_request.request_ip' => '127.0.0.1',
|
142
|
+
'_request.user_agent' => nil,
|
143
|
+
'_request.status' => 404,
|
144
|
+
'_request.request_id' => '471a34dc',
|
145
|
+
'_request.duration' => 0,
|
146
|
+
'_tags' => '471a34dc TEST_TAG',
|
145
147
|
)
|
146
148
|
end
|
147
149
|
end
|
@@ -188,9 +190,9 @@ RSpec.shared_examples 'request logger' do
|
|
188
190
|
bob_file: Rack::Test::UploadedFile.new('spec/fixtures/random_bin')
|
189
191
|
|
190
192
|
expect(last_log_entry).to include(
|
191
|
-
'short_message'
|
192
|
-
'level'
|
193
|
-
'_request.params'
|
193
|
+
'short_message' => 'POST /users?username=yoshi 200 in 0ms',
|
194
|
+
'level' => 6,
|
195
|
+
'_request.params' => {
|
194
196
|
'username' => 'yoshi',
|
195
197
|
'bob_file' => include(
|
196
198
|
'filename' => 'random_bin',
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Loga::Configuration do
|
@@ -20,8 +22,8 @@ describe Loga::Configuration do
|
|
20
22
|
allow(Loga::ServiceVersionStrategies).to receive(:call).and_return('unknown.sha')
|
21
23
|
end
|
22
24
|
|
23
|
-
context 'defaults', with_hostname
|
24
|
-
specify { expect(subject.device).to eq(
|
25
|
+
context 'defaults', :with_hostname do
|
26
|
+
specify { expect(subject.device).to eq($stdout) }
|
25
27
|
specify { expect(subject.filter_exceptions).to eq(framework_exceptions) }
|
26
28
|
specify { expect(subject.filter_parameters).to eq([]) }
|
27
29
|
specify { expect(subject.format).to eq(:simple) }
|
@@ -29,7 +31,7 @@ describe Loga::Configuration do
|
|
29
31
|
specify { expect(subject.level).to eq(:info) }
|
30
32
|
specify { expect(subject.service_name).to eq('hello_world_app') }
|
31
33
|
specify { expect(subject.service_version).to eq('unknown.sha') }
|
32
|
-
specify { expect(subject.sync).to
|
34
|
+
specify { expect(subject.sync).to be(true) }
|
33
35
|
specify { expect(subject.tags).to eq([]) }
|
34
36
|
end
|
35
37
|
|
@@ -174,11 +176,11 @@ describe Loga::Configuration do
|
|
174
176
|
let(:logdev) { subject.logger.instance_variable_get(:@logdev) }
|
175
177
|
|
176
178
|
{
|
177
|
-
debug:
|
178
|
-
info:
|
179
|
-
warn:
|
180
|
-
error:
|
181
|
-
fatal:
|
179
|
+
debug: 0,
|
180
|
+
info: 1,
|
181
|
+
warn: 2,
|
182
|
+
error: 3,
|
183
|
+
fatal: 4,
|
182
184
|
unknown: 5,
|
183
185
|
}.each do |sym, level|
|
184
186
|
context "when log level is #{sym}" do
|
@@ -194,7 +196,7 @@ describe Loga::Configuration do
|
|
194
196
|
let(:options) { super().merge(sync: false) }
|
195
197
|
|
196
198
|
it 'uses warn log level' do
|
197
|
-
expect(logdev.dev.sync).to
|
199
|
+
expect(logdev.dev.sync).to be(false)
|
198
200
|
end
|
199
201
|
end
|
200
202
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
|
-
RSpec.describe Loga::Event, timecop
|
5
|
+
RSpec.describe Loga::Event, :timecop do
|
4
6
|
describe 'initialize' do
|
5
7
|
context 'when no message is passed' do
|
6
8
|
it 'sets message to an empty string' do
|
@@ -9,7 +11,7 @@ RSpec.describe Loga::Event, timecop: true do
|
|
9
11
|
end
|
10
12
|
|
11
13
|
context 'when message is passed' do
|
12
|
-
let(:message) { "stuff \xC2".force_encoding 'ASCII-8BIT' }
|
14
|
+
let(:message) { "stuff \xC2".dup.force_encoding 'ASCII-8BIT' }
|
13
15
|
let(:subject) { described_class.new message: message }
|
14
16
|
|
15
17
|
it 'sanitizes the input to be UTF-8 convertable' do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Loga::Formatters::GELFFormatter do
|
@@ -8,25 +10,25 @@ describe Loga::Formatters::GELFFormatter do
|
|
8
10
|
let(:host) { 'www.example.com' }
|
9
11
|
let(:params) do
|
10
12
|
{
|
11
|
-
service_name:
|
13
|
+
service_name: service_name,
|
12
14
|
service_version: service_version,
|
13
|
-
host:
|
15
|
+
host: host,
|
14
16
|
}
|
15
17
|
end
|
16
18
|
|
17
19
|
shared_examples 'valid GELF message' do
|
18
20
|
it 'includes the required fields' do
|
19
|
-
expect(json).to include('version'
|
20
|
-
'host'
|
21
|
+
expect(json).to include('version' => '1.1',
|
22
|
+
'host' => host,
|
21
23
|
'short_message' => be_a(String),
|
22
|
-
'timestamp'
|
23
|
-
'level'
|
24
|
+
'timestamp' => be_a(Float),
|
25
|
+
'level' => 6)
|
24
26
|
end
|
25
27
|
|
26
28
|
it 'includes Loga additional fields' do
|
27
|
-
expect(json).to include('_service.name'
|
29
|
+
expect(json).to include('_service.name' => service_name,
|
28
30
|
'_service.version' => service_version,
|
29
|
-
'_tags'
|
31
|
+
'_tags' => '')
|
30
32
|
end
|
31
33
|
|
32
34
|
it 'outputs the timestamp in seconds since UNIX epoch' do
|
@@ -209,12 +211,35 @@ describe Loga::Formatters::GELFFormatter do
|
|
209
211
|
end
|
210
212
|
end
|
211
213
|
|
214
|
+
context 'when working with additional fields via otel' do
|
215
|
+
let(:options) { { message: 'Wooden house' } }
|
216
|
+
let(:message) { Loga::Event.new(options) }
|
217
|
+
let(:trace_context) { { hex_trace_id: '123', hex_span_id: '456' } }
|
218
|
+
|
219
|
+
before do
|
220
|
+
klass = Class.new do
|
221
|
+
class << self
|
222
|
+
attr_accessor :current_span
|
223
|
+
end
|
224
|
+
end
|
225
|
+
klass.current_span = OpenStruct.new(context: OpenStruct.new(trace_context))
|
226
|
+
stub_const('::OpenTelemetry::Trace', klass)
|
227
|
+
end
|
228
|
+
|
229
|
+
it 'includes the trace_id and span_id' do
|
230
|
+
expect(json['_trace_id']).to eq('123')
|
231
|
+
expect(json['_span_id']).to eq('456')
|
232
|
+
end
|
233
|
+
|
234
|
+
include_examples 'valid GELF message'
|
235
|
+
end
|
236
|
+
|
212
237
|
{
|
213
|
-
'DEBUG'
|
214
|
-
'INFO'
|
215
|
-
'WARN'
|
216
|
-
'ERROR'
|
217
|
-
'FATAL'
|
238
|
+
'DEBUG' => 7,
|
239
|
+
'INFO' => 6,
|
240
|
+
'WARN' => 4,
|
241
|
+
'ERROR' => 3,
|
242
|
+
'FATAL' => 2,
|
218
243
|
'UNKNOWN' => 1,
|
219
244
|
}.each do |ruby_severity, syslog_level|
|
220
245
|
context "with severity #{ruby_severity}" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'loga/formatters/simple_formatter'
|
3
5
|
|
@@ -112,11 +114,11 @@ describe Loga::Formatters::SimpleFormatter do
|
|
112
114
|
end
|
113
115
|
|
114
116
|
{
|
115
|
-
'DEBUG'
|
116
|
-
'INFO'
|
117
|
-
'WARN'
|
118
|
-
'ERROR'
|
119
|
-
'FATAL'
|
117
|
+
'DEBUG' => 'D',
|
118
|
+
'INFO' => 'I',
|
119
|
+
'WARN' => 'W',
|
120
|
+
'ERROR' => 'E',
|
121
|
+
'FATAL' => 'F',
|
120
122
|
'UNKNOWN' => 'U',
|
121
123
|
}.each do |ruby_severity, formatted_severity|
|
122
124
|
context "with severity #{ruby_severity}" do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'active_support'
|
3
5
|
require 'loga/log_subscribers/action_mailer'
|
@@ -9,7 +11,7 @@ RSpec.describe Loga::LogSubscribers::ActionMailer do
|
|
9
11
|
|
10
12
|
let(:event) do
|
11
13
|
instance_double(
|
12
|
-
|
14
|
+
ActiveSupport::Notifications::Event,
|
13
15
|
payload: payload,
|
14
16
|
duration: 0.0001,
|
15
17
|
time: Time.now,
|
@@ -21,7 +23,7 @@ RSpec.describe Loga::LogSubscribers::ActionMailer do
|
|
21
23
|
let(:payload) do
|
22
24
|
{
|
23
25
|
mailer: 'FakeMailer',
|
24
|
-
to:
|
26
|
+
to: ['user@example.com'],
|
25
27
|
}
|
26
28
|
end
|
27
29
|
let(:config) { instance_double Loga::Configuration, hide_pii: hide_pii }
|
@@ -82,8 +84,8 @@ RSpec.describe Loga::LogSubscribers::ActionMailer do
|
|
82
84
|
context 'when an email is sent' do
|
83
85
|
let(:payload) do
|
84
86
|
{
|
85
|
-
mailer:
|
86
|
-
from:
|
87
|
+
mailer: 'FakeMailer',
|
88
|
+
from: 'loremipsum@example.com',
|
87
89
|
subject: 'Lorem ipsum',
|
88
90
|
}
|
89
91
|
end
|