dvla-herodotus 1.0.0 → 1.2.0

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: def32028eabb2e8b3320cd06f229d9b882c1a586dbf8b7cdeef6e69f4998fd9a
4
- data.tar.gz: 0f9aadf85396b5585db242196f0f5562b9af755ac69901c967fd537a824e5f7c
3
+ metadata.gz: 26e2843c0b2fa7985bccb48c2d24d5e66cf19ff9a1008d27347d705605a979f1
4
+ data.tar.gz: 817acfe4641c6ad9a0bbcf607ce8b3968b2f2d5eccbe3586bfefae1a46236817
5
5
  SHA512:
6
- metadata.gz: 9bf48e9d451a7f9f42fdc44f6af3dcb1844ce36ac82cafc6c8bec0596bda2159d14ba2b9b6aad6ebfaf54b220e53bd66e762e36df68a938c4c6a04b95ccdd1c8
7
- data.tar.gz: d6566b93fc7289175e97b989c4948040be0152eae81997920912c722f26d5d34c24286b01c37ac49b961d28637bface0883b14867f2069db598665ede9affe7b
6
+ metadata.gz: afa99a580bb2f1082252c2dd44139b89d48d48625ee1223f7af6a93cc3ab68a1e65b7379e5646959ab37e772c2a72828b95eba75eb2c6cee75737dc42be85917
7
+ data.tar.gz: 1eab9992df8482e4218f59b3f926e2bfa8383f3c141f708f9fe5a0ef64576fc5eef2bc6eabcb7ef281ccf4e7e4e1eb2cc02e630919c744d0ac5330d16907479c
@@ -0,0 +1,48 @@
1
+ name: Ruby Gem Publish
2
+
3
+ on:
4
+ push:
5
+ branches: [ "main" ]
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
+ - name: Run tests
22
+ run: bundle exec rspec
23
+
24
+ deploy:
25
+ needs: test
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ packages: write
29
+ contents: read
30
+
31
+ steps:
32
+ - uses: actions/checkout@v2
33
+ - name: Set up Ruby 3.0.1
34
+ uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: 3.1.2
37
+ bundler-cache: true
38
+
39
+ - name: Publish to RubyGems
40
+ run: |
41
+ mkdir -p $HOME/.gem
42
+ touch $HOME/.gem/credentials
43
+ chmod 0600 $HOME/.gem/credentials
44
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
45
+ gem build *.gemspec
46
+ gem push *.gem
47
+ env:
48
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -0,0 +1,22 @@
1
+ name: Ruby Test
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [ "main" ]
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
+ - name: Run tests
22
+ run: bundle exec rspec
@@ -8,3 +8,5 @@
8
8
  /dataSources.local.xml
9
9
 
10
10
  /.idea
11
+
12
+ Gemfile.lock
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 HM Government (Driver and Vehicle Licensing Agency)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -28,6 +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 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
+
33
+ ```ruby
34
+ logger = DVLA::Herodotus.logger(output_path: 'logs.txt')
35
+ ```
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
+
31
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:
32
44
 
33
45
  `[CurrentDate CurrentTime CorrelationId] Level : -- Message`
@@ -8,6 +8,9 @@ Gem::Specification.new do |spec|
8
8
 
9
9
  spec.summary = 'Provides a lightweight logger with a common format'
10
10
  spec.required_ruby_version = Gem::Requirement.new('>= 3')
11
+ spec.homepage = 'https://github.com/dvla/herodotus'
12
+
13
+ spec.license = 'MIT'
11
14
 
12
15
  # Specify which files should be added to the gem when it is released.
13
16
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -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 and @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,21 @@
1
+ module DVLA
2
+ module Herodotus
3
+ class MultiWriter
4
+ attr_reader :targets
5
+
6
+ def initialize(*targets)
7
+ @targets = *targets
8
+ end
9
+
10
+ def write(*args)
11
+ @targets.each { |t| t.write(*args) }
12
+ end
13
+
14
+ def close
15
+ @targets.each do |t|
16
+ t.close unless t.eql? $stdout
17
+ end
18
+ end
19
+ end
20
+ end
21
+ 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.0.0'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
@@ -1,6 +1,8 @@
1
1
  require 'logger'
2
- require_relative 'herodotus/string'
3
2
  require_relative 'herodotus/herodotus_logger'
3
+ require_relative 'herodotus/multi_writer'
4
+ require_relative 'herodotus/proc_writer'
5
+ require_relative 'herodotus/string'
4
6
 
5
7
  module DVLA
6
8
  module Herodotus
@@ -16,8 +18,8 @@ module DVLA
16
18
  @config || configure
17
19
  end
18
20
 
19
- def self.logger
20
- logger = HerodotusLogger.new($stdout)
21
+ def self.logger(output_path: nil)
22
+ logger = create_logger(output_path)
21
23
  logger.system_name = "#{config.system_name} " unless config.system_name.nil?
22
24
  logger.requires_pid = config.pid
23
25
  logger.merge = config.merge
@@ -25,5 +27,20 @@ module DVLA
25
27
  logger.merge_correlation_ids if config.merge
26
28
  logger
27
29
  end
30
+
31
+ private_class_method def self.create_logger(output_path)
32
+ if output_path
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
42
+ end
43
+ HerodotusLogger.new($stdout)
44
+ end
28
45
  end
29
46
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dvla-herodotus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Driver and Vehicle Licensing Agency (DVLA)
8
8
  - George Bell
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-05-17 00:00:00.000000000 Z
12
+ date: 2024-01-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -25,25 +25,31 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.8'
28
- description:
28
+ description:
29
29
  email:
30
30
  - george.bell.contractor@dvla.gov.uk
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".idea/.gitignore"
35
+ - ".github/workflows/gem-push.yml"
36
+ - ".github/workflows/gem-test.yml"
37
+ - ".gitignore"
36
38
  - Gemfile
39
+ - LICENSE
37
40
  - README.md
38
41
  - dvla-herodotus.gemspec
39
42
  - lib/dvla/herodotus.rb
40
43
  - lib/dvla/herodotus/herodotus_logger.rb
44
+ - lib/dvla/herodotus/multi_writer.rb
45
+ - lib/dvla/herodotus/proc_writer.rb
41
46
  - lib/dvla/herodotus/string.rb
42
47
  - lib/dvla/herodotus/version.rb
43
- homepage:
44
- licenses: []
48
+ homepage: https://github.com/dvla/herodotus
49
+ licenses:
50
+ - MIT
45
51
  metadata: {}
46
- post_install_message:
52
+ post_install_message:
47
53
  rdoc_options: []
48
54
  require_paths:
49
55
  - lib
@@ -59,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
65
  version: '0'
60
66
  requirements: []
61
67
  rubygems_version: 3.3.7
62
- signing_key:
68
+ signing_key:
63
69
  specification_version: 4
64
70
  summary: Provides a lightweight logger with a common format
65
71
  test_files: []