loga 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/loga.rb +1 -0
- data/lib/loga/configuration.rb +1 -21
- data/lib/loga/revision_strategy.rb +32 -0
- data/lib/loga/version.rb +1 -1
- data/spec/unit/loga/configuration_spec.rb +0 -8
- data/spec/unit/loga/revision_strategy_spec.rb +41 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a962ebefb507146c9e7e2586efb356fd9615db7d
|
4
|
+
data.tar.gz: d1cc277cb5364e6b017d1c2e8f5524da815d9f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd8aa79bea6fc3f231a11da411e4157ba61b9c7ed26bd016cf6627a211ca74cc46e41577ee1a3480c046323d5cc9a936bcea175c3bdb9f52aef4a8af91bae60b
|
7
|
+
data.tar.gz: af8f9e6abb19c279a1b3ca59310e33a0123e6b9e7d618d6a4e8bdca14ba237f2c8f929377d3f95c03157e06add6e0b011ba0bfe111154da2eb4411191c0992c0
|
data/lib/loga.rb
CHANGED
data/lib/loga/configuration.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'socket'
|
3
|
-
require 'active_support'
|
4
|
-
require 'active_support/core_ext/object/blank'
|
5
3
|
|
6
4
|
module Loga
|
7
5
|
class Configuration
|
@@ -43,26 +41,8 @@ module Loga
|
|
43
41
|
|
44
42
|
private
|
45
43
|
|
46
|
-
class GitRevisionStrategy
|
47
|
-
DEFAULT_REVISION = 'unknown.sha'.freeze
|
48
|
-
|
49
|
-
def self.call
|
50
|
-
revision = fetch_revision if binary_available?
|
51
|
-
revision = DEFAULT_REVISION if revision.blank?
|
52
|
-
revision
|
53
|
-
end
|
54
|
-
|
55
|
-
def self.binary_available?
|
56
|
-
system 'which git'
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.fetch_revision
|
60
|
-
`git rev-parse HEAD`.strip
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
44
|
def compute_service_version
|
65
|
-
|
45
|
+
RevisionStrategy.call(service_version)
|
66
46
|
end
|
67
47
|
|
68
48
|
def initialize_logger
|
@@ -0,0 +1,32 @@
|
|
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
|
data/lib/loga/version.rb
CHANGED
@@ -44,14 +44,6 @@ describe Loga::Configuration do
|
|
44
44
|
subject.initialize!
|
45
45
|
end
|
46
46
|
|
47
|
-
context 'when service_version is :git' do
|
48
|
-
before { subject.service_version = :git }
|
49
|
-
it 'computes the service_version with git' do
|
50
|
-
subject.initialize!
|
51
|
-
expect(subject.service_version).to match(/\h+/)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
47
|
describe 'logger' do
|
56
48
|
let(:logdev) { subject.logger.instance_variable_get(:@logdev) }
|
57
49
|
|
@@ -0,0 +1,41 @@
|
|
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
|
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: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Funding Circle
|
@@ -182,6 +182,7 @@ files:
|
|
182
182
|
- lib/loga/rack/request.rb
|
183
183
|
- lib/loga/rack/request_id.rb
|
184
184
|
- lib/loga/railtie.rb
|
185
|
+
- lib/loga/revision_strategy.rb
|
185
186
|
- lib/loga/tagged_logging.rb
|
186
187
|
- lib/loga/utilities.rb
|
187
188
|
- lib/loga/version.rb
|
@@ -256,6 +257,7 @@ files:
|
|
256
257
|
- spec/unit/loga/parameter_filter_spec.rb
|
257
258
|
- spec/unit/loga/rack/logger_spec.rb
|
258
259
|
- spec/unit/loga/rack/request_spec.rb
|
260
|
+
- spec/unit/loga/revision_strategy_spec.rb
|
259
261
|
- spec/unit/loga/utilities_spec.rb
|
260
262
|
- spec/unit/loga_spec.rb
|
261
263
|
homepage: https://github.com/FundingCircle/loga
|
@@ -352,6 +354,7 @@ test_files:
|
|
352
354
|
- spec/unit/loga/parameter_filter_spec.rb
|
353
355
|
- spec/unit/loga/rack/logger_spec.rb
|
354
356
|
- spec/unit/loga/rack/request_spec.rb
|
357
|
+
- spec/unit/loga/revision_strategy_spec.rb
|
355
358
|
- spec/unit/loga/utilities_spec.rb
|
356
359
|
- spec/unit/loga_spec.rb
|
357
360
|
has_rdoc:
|