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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44f213f7b551a5dedbe3caaca66eafc7471b539eac4ec2271b3687e0be26d934
4
- data.tar.gz: 21b3bf02e8ddf43b4eb8accadd47a607a25013943869e8b3b03587e3157568fd
3
+ metadata.gz: e438adf38dbfed19a683688cbd116e9df9cd2381c64142ce1334eeea84ae681c
4
+ data.tar.gz: 6c4fc10b6f03e57261971d56fb86570283020c48217bdb4cdbb7ed6920a2a894
5
5
  SHA512:
6
- metadata.gz: 22fed7800687b7acaf63195afd9c93fcab67914b6456ad8928f2cd4345b256f92ff91b7c22239e2c9bb65853b1dd976f6835647f25431c42e1335af8c541c6e3
7
- data.tar.gz: 72177da622343e613def838c5e195e0da15c8fccaf8dadcb3bf84ce164eab7b1c481e45c898ca5b7ad99004634ad4e58bd339a6788aca1780786121852ada22b
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
@@ -0,0 +1,3 @@
1
+ ---
2
+ inherit_gem:
3
+ dvla-lint: ".rubocop.yml"
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 an output file, which will be logged to simultaneously with standard console logger
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`
@@ -21,5 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = %w[lib]
23
23
 
24
+ spec.add_development_dependency 'dvla-lint', '~> 1.7'
24
25
  spec.add_development_dependency 'rspec', '~> 3.8'
25
26
  end
@@ -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
@@ -1,6 +1,8 @@
1
1
  module DVLA
2
2
  module Herodotus
3
3
  class MultiWriter
4
+ attr_reader :targets
5
+
4
6
  def initialize(*targets)
5
7
  @targets = *targets
6
8
  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
@@ -1,5 +1,5 @@
1
1
  module DVLA
2
2
  module Herodotus
3
- VERSION = '1.1.0'.freeze
3
+ VERSION = '1.2.1'.freeze
4
4
  end
5
5
  end
@@ -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
- output_file = File.open(output_path, 'a+')
33
- HerodotusLogger.new(MultiWriter.new(output_file, $stdout))
34
- else
35
- HerodotusLogger.new($stdout)
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.0
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: 2023-08-15 00:00:00.000000000 Z
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