loga 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +21 -9
- data/CHANGELOG.md +50 -0
- data/Guardfile +45 -0
- data/LICENSE.txt +29 -0
- data/README.md +149 -81
- data/circle.yml +5 -5
- data/lib/loga.rb +12 -8
- data/lib/loga/configuration.rb +97 -46
- data/lib/loga/event.rb +11 -0
- data/lib/loga/rack/logger.rb +21 -16
- data/lib/loga/rack/request.rb +18 -6
- data/lib/loga/railtie.rb +74 -33
- data/lib/loga/service_version_strategies.rb +19 -0
- data/lib/loga/version.rb +1 -1
- data/loga.gemspec +5 -1
- data/spec/fixtures/rails32/config/application.rb +6 -6
- data/spec/fixtures/rails40/config/application.rb +6 -6
- data/spec/fixtures/rails50/config/application.rb +6 -6
- data/spec/integration/rails/railtie_spec.rb +69 -61
- data/spec/integration/rails/request_spec.rb +17 -18
- data/spec/integration/sinatra_spec.rb +53 -14
- data/spec/support/request_spec.rb +11 -10
- data/spec/unit/loga/configuration_spec.rb +163 -57
- data/spec/unit/loga/event_spec.rb +31 -1
- data/spec/unit/loga/rack/logger_spec.rb +22 -10
- data/spec/unit/loga/rack/request_spec.rb +19 -26
- data/spec/unit/loga/service_version_strategies_spec.rb +37 -0
- data/spec/unit/loga_spec.rb +52 -15
- metadata +53 -8
- data/.rubocop_todo.yml +0 -33
- data/lib/loga/revision_strategy.rb +0 -32
- data/spec/unit/loga/revision_strategy_spec.rb +0 -41
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Loga::ServiceVersionStrategies do
|
4
|
+
describe '#call' do
|
5
|
+
context 'when GIT is available' do
|
6
|
+
before do
|
7
|
+
allow(described_class::SCM_GIT).to receive(:call).and_return("2776b9c\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns the git sha' do
|
11
|
+
expect(subject.call).to eql('2776b9c')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when REVISION file is available' do
|
16
|
+
before do
|
17
|
+
allow(described_class::SCM_GIT).to receive(:call).and_return(nil)
|
18
|
+
allow(File).to receive(:read).with('REVISION').and_return("2776b9c\n")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns the file content' do
|
22
|
+
expect(subject.call).to eql('2776b9c')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when both GIT and REVISION file are unavailable' do
|
27
|
+
before do
|
28
|
+
allow(described_class::SCM_GIT).to receive(:call).and_return(nil)
|
29
|
+
allow(described_class::REVISION_FILE).to receive(:call).and_return(nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'returns a default value' do
|
33
|
+
expect(subject.call).to eql('unknown.sha')
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/spec/unit/loga_spec.rb
CHANGED
@@ -3,39 +3,76 @@ require 'spec_helper'
|
|
3
3
|
describe Loga do
|
4
4
|
before { described_class.reset }
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
it 'memoizes the result' do
|
10
|
-
expect(subject.configuration).to equal(subject.configuration)
|
11
|
-
end
|
6
|
+
let(:config_missing_class) { described_class::ConfigurationError }
|
7
|
+
let(:config_missing_msg) do
|
8
|
+
'Loga has not been configured. Configure with Loga.configure(options)'
|
12
9
|
end
|
10
|
+
let(:options) { { service_name: 'hello_world_app' } }
|
11
|
+
let(:framework_options) { { format: 'gelf' } }
|
13
12
|
|
14
13
|
describe '.configure' do
|
15
14
|
it 'configures Loga' do
|
16
|
-
expect
|
15
|
+
expect(Loga::Configuration).to receive(:new).with(options, {}).and_call_original
|
16
|
+
subject.configure(options)
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when framework options provided' do
|
20
|
+
it 'configures Loga' do
|
21
|
+
expect(Loga::Configuration)
|
22
|
+
.to receive(:new).with(options, framework_options).and_call_original
|
23
|
+
subject.configure(options, framework_options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when configure twice' do
|
28
|
+
before { subject.configure(options) }
|
29
|
+
|
30
|
+
it 'raises an error' do
|
31
|
+
expect { subject.configure(options) }
|
32
|
+
.to raise_error(config_missing_class, 'Loga has already been configured')
|
33
|
+
end
|
17
34
|
end
|
18
35
|
end
|
19
36
|
|
20
|
-
describe '.
|
21
|
-
|
22
|
-
|
37
|
+
describe '.configuration' do
|
38
|
+
context 'when Loga is not configured' do
|
39
|
+
it 'raises an error' do
|
40
|
+
expect { subject.configuration }
|
41
|
+
.to raise_error(config_missing_class, config_missing_msg)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'when Loga is configured' do
|
46
|
+
before { subject.configure(options) }
|
47
|
+
|
48
|
+
it 'returns the configuration' do
|
49
|
+
expect(subject.configuration.service_name).to eql(options[:service_name])
|
50
|
+
end
|
23
51
|
end
|
24
52
|
end
|
25
53
|
|
26
54
|
describe '.logger' do
|
27
|
-
context 'when Loga is not
|
28
|
-
|
55
|
+
context 'when Loga is not configured' do
|
56
|
+
it 'raises an error' do
|
57
|
+
expect { subject.logger }
|
58
|
+
.to raise_error(config_missing_class, config_missing_msg)
|
59
|
+
end
|
29
60
|
end
|
30
|
-
|
31
|
-
|
61
|
+
|
62
|
+
context 'when Loga is configured' do
|
63
|
+
before { subject.configure(options) }
|
32
64
|
specify { expect(subject.logger).to be_kind_of(Logger) }
|
33
65
|
end
|
34
66
|
end
|
35
67
|
|
36
68
|
describe '.reset' do
|
69
|
+
before { subject.configure(options) }
|
70
|
+
|
37
71
|
it 'resets the configuration' do
|
38
|
-
expect
|
72
|
+
expect do
|
73
|
+
subject.reset
|
74
|
+
subject.configure(options)
|
75
|
+
end.to change { subject.configuration.object_id }
|
39
76
|
end
|
40
77
|
end
|
41
78
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Funding Circle
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 3.
|
117
|
+
version: 3.5.0
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 3.
|
124
|
+
version: 3.5.0
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rubocop
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +150,48 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: guard
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '2.13'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '2.13'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: guard-rubocop
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '1.2'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '1.2'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard-rspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 4.7.3
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 4.7.3
|
153
195
|
description: Log aggregation through unified logging middleware, while respecting
|
154
196
|
the original log format.
|
155
197
|
email:
|
@@ -161,9 +203,11 @@ files:
|
|
161
203
|
- ".gitignore"
|
162
204
|
- ".rspec"
|
163
205
|
- ".rubocop.yml"
|
164
|
-
- ".rubocop_todo.yml"
|
165
206
|
- Appraisals
|
207
|
+
- CHANGELOG.md
|
166
208
|
- Gemfile
|
209
|
+
- Guardfile
|
210
|
+
- LICENSE.txt
|
167
211
|
- README.md
|
168
212
|
- Rakefile
|
169
213
|
- circle.yml
|
@@ -184,7 +228,7 @@ files:
|
|
184
228
|
- lib/loga/rack/request.rb
|
185
229
|
- lib/loga/rack/request_id.rb
|
186
230
|
- lib/loga/railtie.rb
|
187
|
-
- lib/loga/
|
231
|
+
- lib/loga/service_version_strategies.rb
|
188
232
|
- lib/loga/tagged_logging.rb
|
189
233
|
- lib/loga/utilities.rb
|
190
234
|
- lib/loga/version.rb
|
@@ -297,11 +341,12 @@ files:
|
|
297
341
|
- spec/unit/loga/parameter_filter_spec.rb
|
298
342
|
- spec/unit/loga/rack/logger_spec.rb
|
299
343
|
- spec/unit/loga/rack/request_spec.rb
|
300
|
-
- spec/unit/loga/
|
344
|
+
- spec/unit/loga/service_version_strategies_spec.rb
|
301
345
|
- spec/unit/loga/utilities_spec.rb
|
302
346
|
- spec/unit/loga_spec.rb
|
303
347
|
homepage: https://github.com/FundingCircle/loga
|
304
|
-
licenses:
|
348
|
+
licenses:
|
349
|
+
- BSD-3-Clause
|
305
350
|
metadata: {}
|
306
351
|
post_install_message:
|
307
352
|
rdoc_options: []
|
@@ -432,7 +477,7 @@ test_files:
|
|
432
477
|
- spec/unit/loga/parameter_filter_spec.rb
|
433
478
|
- spec/unit/loga/rack/logger_spec.rb
|
434
479
|
- spec/unit/loga/rack/request_spec.rb
|
435
|
-
- spec/unit/loga/
|
480
|
+
- spec/unit/loga/service_version_strategies_spec.rb
|
436
481
|
- spec/unit/loga/utilities_spec.rb
|
437
482
|
- spec/unit/loga_spec.rb
|
438
483
|
has_rdoc:
|
data/.rubocop_todo.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-06-18 23:19:09 +0100 using RuboCop version 0.30.1.
|
3
|
-
# The point is for the user to remove these configuration records
|
4
|
-
# one by one as the offenses are removed from the code base.
|
5
|
-
# Note that changes in the inspected code, or installation of new
|
6
|
-
# versions of RuboCop, may require this file to be generated again.
|
7
|
-
|
8
|
-
# Offense count: 2
|
9
|
-
Lint/HandleExceptions:
|
10
|
-
Enabled: false
|
11
|
-
|
12
|
-
# Offense count: 2
|
13
|
-
Lint/RescueException:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
# Offense count: 4
|
17
|
-
Metrics/AbcSize:
|
18
|
-
Max: 29
|
19
|
-
|
20
|
-
# Offense count: 16
|
21
|
-
# Configuration parameters: AllowURI, URISchemes.
|
22
|
-
Metrics/LineLength:
|
23
|
-
Max: 93
|
24
|
-
|
25
|
-
# Offense count: 8
|
26
|
-
# Configuration parameters: CountComments.
|
27
|
-
Metrics/MethodLength:
|
28
|
-
Max: 22
|
29
|
-
|
30
|
-
# Offense count: 14
|
31
|
-
Style/Documentation:
|
32
|
-
Enabled: false
|
33
|
-
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# rubocop:disable Style/SpecialGlobalVars
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
|
4
|
-
module Loga
|
5
|
-
class RevisionStrategy
|
6
|
-
DEFAULT_REVISION = 'unknown.sha'.freeze
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def call(service_version = :git)
|
10
|
-
if service_version == :git
|
11
|
-
fetch_from_git || read_from_file || DEFAULT_REVISION
|
12
|
-
elsif service_version.blank?
|
13
|
-
DEFAULT_REVISION
|
14
|
-
else
|
15
|
-
service_version.strip
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def fetch_from_git
|
20
|
-
sha1_hash = `git rev-parse --short HEAD`
|
21
|
-
$?.exitstatus == 0 ? sha1_hash.strip : false
|
22
|
-
end
|
23
|
-
|
24
|
-
def read_from_file
|
25
|
-
File.read('REVISION').strip
|
26
|
-
rescue Errno::ENOENT
|
27
|
-
false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
# rubocop:enable Style/SpecialGlobalVars
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Loga::RevisionStrategy do
|
4
|
-
describe '.call' do
|
5
|
-
it 'uses :git as default argument' do
|
6
|
-
expect(Loga::RevisionStrategy.call).to match(/\h+/)
|
7
|
-
end
|
8
|
-
|
9
|
-
it "returns 'unknown.sha' when argument is empty string" do
|
10
|
-
expect(Loga::RevisionStrategy.call('')).to eq('unknown.sha')
|
11
|
-
end
|
12
|
-
|
13
|
-
context 'called with :git argument' do
|
14
|
-
it 'fetches the service version from git' do
|
15
|
-
expect(Loga::RevisionStrategy.call(:git)).to match(/\h+/)
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'reads the REVISION file when no git repo' do
|
19
|
-
allow(Loga::RevisionStrategy).to receive(:fetch_from_git) { false }
|
20
|
-
expect(File).to receive(:read).with('REVISION').and_return('sha1_hash')
|
21
|
-
expect(Loga::RevisionStrategy.call(:git)).to eq('sha1_hash')
|
22
|
-
end
|
23
|
-
|
24
|
-
it "returns 'unknown.sha' otherwise" do
|
25
|
-
allow(Loga::RevisionStrategy).to receive(:fetch_from_git) { false }
|
26
|
-
allow(Loga::RevisionStrategy).to receive(:read_from_file) { false }
|
27
|
-
expect(Loga::RevisionStrategy.call(:git)).to eq('unknown.sha')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'called with anything else' do
|
32
|
-
it 'returns the argument called with' do
|
33
|
-
expect(Loga::RevisionStrategy.call('foobar')).to eq('foobar')
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'strips any leading and trailing whitespace' do
|
37
|
-
expect(Loga::RevisionStrategy.call("\t foobar\r\n ")).to eq('foobar')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|