dvla-herodotus 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-build.yml +39 -0
- data/.rubocop.yml +3 -0
- data/README.md +7 -1
- data/dvla-herodotus.gemspec +1 -0
- data/lib/dvla/herodotus/herodotus_logger.rb +13 -0
- data/lib/dvla/herodotus/multi_writer.rb +2 -0
- data/lib/dvla/herodotus/proc_writer.rb +20 -0
- data/lib/dvla/herodotus/version.rb +1 -1
- data/lib/dvla/herodotus.rb +11 -4
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e438adf38dbfed19a683688cbd116e9df9cd2381c64142ce1334eeea84ae681c
|
4
|
+
data.tar.gz: 6c4fc10b6f03e57261971d56fb86570283020c48217bdb4cdbb7ed6920a2a894
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4942f36ded7e851ba5e9a43254dd02ec02a3e2bf1df3580103502873fe16d2f28787960c0277417c415103411f17d8396fe4947f5feeead0ac408cbf928756c
|
7
|
+
data.tar.gz: '095addb8fe673dcf789bec32357bad374aec2ffc6fc58e7331fbf20070dc22680630ca386ea5dc6b5a4fa2114e6ed701787747cd988d171788cf1a444bddf8c8'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
name: Ruby Build
|
2
|
+
|
3
|
+
on:
|
4
|
+
schedule:
|
5
|
+
- cron: '0 7 * * 1'
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby-version: [ '3.0', '3.1', '3.2' ]
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby-version }}
|
20
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
21
|
+
|
22
|
+
- name: Run checks
|
23
|
+
run: |
|
24
|
+
gem install bundler-audit
|
25
|
+
bundle-audit check --update
|
26
|
+
bundle exec rspec
|
27
|
+
|
28
|
+
- name: Report test failure
|
29
|
+
if: ${{ failure() }}
|
30
|
+
run: |
|
31
|
+
COMMIT_MESSAGE=$(git log -1 --pretty=%B)
|
32
|
+
COMMIT_AUTHOR=$(git log -1 --pretty=format:'%an')
|
33
|
+
curl -H 'Content-Type: application/json' -d "{\"title\": \"${REPO_NAME} GitHub build failed.\",\"text\": \"Build **${BUILD_NUMBER}** on the main branch by ${COMMIT_AUTHOR} [GitHub Action](${ACTION_LINK}) | [Repo Branch](${BRANCH_LINK}) **Commit Message** ${COMMIT_MESSAGE}\",\"themeColor\": \"EA4300\"}" -s ${WEBHOOK_URL}
|
34
|
+
env:
|
35
|
+
REPO_NAME: "${{ github.event.repository.name }}"
|
36
|
+
BUILD_NUMBER: "${{ github.run_number }}"
|
37
|
+
ACTION_LINK: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
|
38
|
+
BRANCH_LINK: "${{ github.server_url }}/${{ github.repository }}"
|
39
|
+
WEBHOOK_URL: "${{ secrets.WEBHOOK_URL }}"
|
data/.rubocop.yml
ADDED
data/README.md
CHANGED
@@ -28,12 +28,18 @@ You can get a logger by calling the following once Herodotus is installed:
|
|
28
28
|
logger = DVLA::Herodotus.logger
|
29
29
|
```
|
30
30
|
|
31
|
-
You can also provide the path to
|
31
|
+
You can also log out to a file. If you want all the logs in a single file, provide a string of the path to that output file and it will be logged to simultaneously with standard console logger
|
32
32
|
|
33
33
|
```ruby
|
34
34
|
logger = DVLA::Herodotus.logger(output_path: 'logs.txt')
|
35
35
|
```
|
36
36
|
|
37
|
+
Alternatively, if you want each scenario to log out to a separate file based on the scenario name, pass in a lambda that returns a string that attempts to interpolate `@scenario`.
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
logger = DVLA::Herodotus.logger(output_path: -> { "#{@scenario}_log.txt" })
|
41
|
+
```
|
42
|
+
|
37
43
|
This is a standard Ruby logger, so anything that would work on a logger acquired the traditional way will also work here, however it is formatted such that all logs will be output in the following format:
|
38
44
|
|
39
45
|
`[CurrentDate CurrentTime CorrelationId] Level : -- Message`
|
data/dvla-herodotus.gemspec
CHANGED
@@ -7,6 +7,7 @@ module DVLA
|
|
7
7
|
|
8
8
|
def register_default_correlation_id
|
9
9
|
@correlation_ids = { default: SecureRandom.uuid[0, 8] }
|
10
|
+
@current_scenario = :default
|
10
11
|
reset_format
|
11
12
|
end
|
12
13
|
|
@@ -28,9 +29,11 @@ module DVLA
|
|
28
29
|
%i[debug info warn error fatal].each do |log_level|
|
29
30
|
define_method log_level do |progname = nil, scenario_id = nil, &block|
|
30
31
|
if scenario_id == nil
|
32
|
+
set_proc_writer_scenario
|
31
33
|
super(progname, &block)
|
32
34
|
else
|
33
35
|
update_format(scenario_id)
|
36
|
+
set_proc_writer_scenario
|
34
37
|
super(progname, &block)
|
35
38
|
reset_format
|
36
39
|
end
|
@@ -40,6 +43,7 @@ module DVLA
|
|
40
43
|
private
|
41
44
|
|
42
45
|
def update_format(scenario_id)
|
46
|
+
@current_scenario = scenario_id
|
43
47
|
@correlation_ids[scenario_id] = SecureRandom.uuid[0, 8] unless @correlation_ids.key?(scenario_id)
|
44
48
|
|
45
49
|
self.formatter = proc do |severity, _datetime, _progname, msg|
|
@@ -60,6 +64,15 @@ module DVLA
|
|
60
64
|
"#{severity} -- : #{msg}\n"
|
61
65
|
end
|
62
66
|
end
|
67
|
+
|
68
|
+
def set_proc_writer_scenario
|
69
|
+
if @logdev.dev.is_a?(DVLA::Herodotus::MultiWriter) && @logdev.dev.targets.any?(DVLA::Herodotus::ProcWriter)
|
70
|
+
proc_writers = @logdev.dev.targets.select { |t| t.is_a? DVLA::Herodotus::ProcWriter }
|
71
|
+
proc_writers.each do |pr|
|
72
|
+
pr.scenario = @current_scenario
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
63
76
|
end
|
64
77
|
end
|
65
78
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module DVLA
|
2
|
+
module Herodotus
|
3
|
+
class ProcWriter
|
4
|
+
attr_accessor :scenario
|
5
|
+
def initialize(proc)
|
6
|
+
@proc = proc
|
7
|
+
end
|
8
|
+
|
9
|
+
def write(*args)
|
10
|
+
output_file = File.open(self.instance_exec(&@proc), 'a')
|
11
|
+
output_file.write(args[0])
|
12
|
+
output_file.close
|
13
|
+
end
|
14
|
+
|
15
|
+
def close
|
16
|
+
# Nothing to close but we want to maintain consistency with other ways Herodotus can output
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/dvla/herodotus.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require_relative 'herodotus/herodotus_logger'
|
3
3
|
require_relative 'herodotus/multi_writer'
|
4
|
+
require_relative 'herodotus/proc_writer'
|
4
5
|
require_relative 'herodotus/string'
|
5
6
|
|
6
7
|
module DVLA
|
@@ -29,11 +30,17 @@ module DVLA
|
|
29
30
|
|
30
31
|
private_class_method def self.create_logger(output_path)
|
31
32
|
if output_path
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
if output_path.is_a? String
|
34
|
+
output_file = File.open(output_path, 'a')
|
35
|
+
return HerodotusLogger.new(MultiWriter.new(output_file, $stdout))
|
36
|
+
elsif output_path.is_a? Proc
|
37
|
+
proc_writer = ProcWriter.new(output_path)
|
38
|
+
return HerodotusLogger.new(MultiWriter.new(proc_writer, $stdout))
|
39
|
+
else
|
40
|
+
raise ArgumentError.new 'Unexpected output_path provided. Expecting either a string or a proc'
|
41
|
+
end
|
36
42
|
end
|
43
|
+
HerodotusLogger.new($stdout)
|
37
44
|
end
|
38
45
|
end
|
39
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dvla-herodotus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Driver and Vehicle Licensing Agency (DVLA)
|
@@ -9,8 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-02-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: dvla-lint
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
14
28
|
- !ruby/object:Gem::Dependency
|
15
29
|
name: rspec
|
16
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -32,9 +46,11 @@ executables: []
|
|
32
46
|
extensions: []
|
33
47
|
extra_rdoc_files: []
|
34
48
|
files:
|
49
|
+
- ".github/workflows/gem-build.yml"
|
35
50
|
- ".github/workflows/gem-push.yml"
|
36
51
|
- ".github/workflows/gem-test.yml"
|
37
52
|
- ".gitignore"
|
53
|
+
- ".rubocop.yml"
|
38
54
|
- Gemfile
|
39
55
|
- LICENSE
|
40
56
|
- README.md
|
@@ -42,6 +58,7 @@ files:
|
|
42
58
|
- lib/dvla/herodotus.rb
|
43
59
|
- lib/dvla/herodotus/herodotus_logger.rb
|
44
60
|
- lib/dvla/herodotus/multi_writer.rb
|
61
|
+
- lib/dvla/herodotus/proc_writer.rb
|
45
62
|
- lib/dvla/herodotus/string.rb
|
46
63
|
- lib/dvla/herodotus/version.rb
|
47
64
|
homepage: https://github.com/dvla/herodotus
|