From 055e393fc8ab6333337941e06fce32ef672a7c7d Mon Sep 17 00:00:00 2001 From: Katherine Hooper Date: Thu, 20 Nov 2025 19:01:34 +0000 Subject: [PATCH 1/4] create directory for output path if it does not already exist --- .gitignore | 3 ++- lib/dvla/herodotus.rb | 4 ++++ lib/dvla/herodotus/version.rb | 2 +- spec/dvla/herodotus_spec.rb | 5 +++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 98518ca..94d2237 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,5 @@ /.idea -Gemfile.lock \ No newline at end of file +Gemfile.lock +/test-path \ No newline at end of file diff --git a/lib/dvla/herodotus.rb b/lib/dvla/herodotus.rb index 33c9d28..97d6d69 100644 --- a/lib/dvla/herodotus.rb +++ b/lib/dvla/herodotus.rb @@ -25,6 +25,10 @@ def self.logger(system_name, config: self.config, output_path: nil) private_class_method def self.create_logger(system_name, config, output_path) if output_path if output_path.is_a? String + directory = File.split(output_path).first + unless File.directory?(directory) + FileUtils.mkdir(directory) + end output_file = File.open(output_path, 'a') return HerodotusLogger.new(system_name, MultiWriter.new(output_file, $stdout), config: config) elsif output_path.is_a? Proc diff --git a/lib/dvla/herodotus/version.rb b/lib/dvla/herodotus/version.rb index 1b0197a..9f1b699 100644 --- a/lib/dvla/herodotus/version.rb +++ b/lib/dvla/herodotus/version.rb @@ -1,5 +1,5 @@ module DVLA module Herodotus - VERSION = '2.3.0'.freeze + VERSION = '2.3.1'.freeze end end diff --git a/spec/dvla/herodotus_spec.rb b/spec/dvla/herodotus_spec.rb index bc4324e..7a02d42 100644 --- a/spec/dvla/herodotus_spec.rb +++ b/spec/dvla/herodotus_spec.rb @@ -81,6 +81,11 @@ .to_stdout_from_any_process end + it 'will create a directory for output_path if it does not exist' do + output_path = "test-path/#{rand(9999)}/log.txt" + expect { DVLA::Herodotus.logger('rspec', output_path:) }.to_not raise_error + end + it 'raises an error when an unexpected type is passed in as an output_path' do unexpected_int = 123 expect { DVLA::Herodotus.logger('rspec', output_path: unexpected_int) }.to raise_error(ArgumentError, 'Unexpected output_path provided. Expecting either a string or a proc') From 2856eec99b5a635ac057bb9b5a29791443227631 Mon Sep 17 00:00:00 2001 From: Katherine Hooper Date: Fri, 21 Nov 2025 08:58:10 +0000 Subject: [PATCH 2/4] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cdc0b..a7b0f2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## [2.3.1] - 2025-11-21 +- Fixed issue with output_path in create_logger, will now make a directory if it did not exist + ## [2.3.0] - 2025-10-05 - Config block can now accept prefix colour options. Can be applied to the whole prefix or configure individual components. From 9043f27d2dba767c5bb9ad60f16e98a7522f5211 Mon Sep 17 00:00:00 2001 From: Katherine Hooper Date: Fri, 21 Nov 2025 10:04:18 +0000 Subject: [PATCH 3/4] issue creating directory through terminal --- lib/dvla/herodotus.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dvla/herodotus.rb b/lib/dvla/herodotus.rb index 97d6d69..e1a6d6e 100644 --- a/lib/dvla/herodotus.rb +++ b/lib/dvla/herodotus.rb @@ -27,7 +27,7 @@ def self.logger(system_name, config: self.config, output_path: nil) if output_path.is_a? String directory = File.split(output_path).first unless File.directory?(directory) - FileUtils.mkdir(directory) + FileUtils.mkdir_p(directory) end output_file = File.open(output_path, 'a') return HerodotusLogger.new(system_name, MultiWriter.new(output_file, $stdout), config: config) From 1b413587a0faee25bc1f4ceb774f44d282b1ac2b Mon Sep 17 00:00:00 2001 From: Katherine Hooper Date: Fri, 21 Nov 2025 10:43:55 +0000 Subject: [PATCH 4/4] run directory check method on both string and proc, make sure syntax compatible with ruby 3.0 --- lib/dvla/herodotus.rb | 14 ++++++++++---- spec/dvla/herodotus_spec.rb | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/dvla/herodotus.rb b/lib/dvla/herodotus.rb index e1a6d6e..95a91a8 100644 --- a/lib/dvla/herodotus.rb +++ b/lib/dvla/herodotus.rb @@ -1,4 +1,5 @@ require 'logger' +require 'fileutils' require_relative 'herodotus/herodotus_logger' require_relative 'herodotus/multi_writer' require_relative 'herodotus/proc_writer' @@ -25,13 +26,11 @@ def self.logger(system_name, config: self.config, output_path: nil) private_class_method def self.create_logger(system_name, config, output_path) if output_path if output_path.is_a? String - directory = File.split(output_path).first - unless File.directory?(directory) - FileUtils.mkdir_p(directory) - end + ensure_directory_exists(output_path: output_path) output_file = File.open(output_path, 'a') return HerodotusLogger.new(system_name, MultiWriter.new(output_file, $stdout), config: config) elsif output_path.is_a? Proc + ensure_directory_exists(output_path: output_path.call) proc_writer = ProcWriter.new(output_path) return HerodotusLogger.new(system_name, MultiWriter.new(proc_writer, $stdout), config: config) else @@ -40,5 +39,12 @@ def self.logger(system_name, config: self.config, output_path: nil) end HerodotusLogger.new(system_name, $stdout, config: config) end + + private_class_method def self.ensure_directory_exists(output_path:) + directory = File.split(output_path).first + unless File.directory?(directory) + FileUtils.mkdir_p(directory) + end + end end end diff --git a/spec/dvla/herodotus_spec.rb b/spec/dvla/herodotus_spec.rb index 7a02d42..a83cbe6 100644 --- a/spec/dvla/herodotus_spec.rb +++ b/spec/dvla/herodotus_spec.rb @@ -81,9 +81,14 @@ .to_stdout_from_any_process end - it 'will create a directory for output_path if it does not exist' do + it 'will create a directory for a string output_path if it does not exist' do output_path = "test-path/#{rand(9999)}/log.txt" - expect { DVLA::Herodotus.logger('rspec', output_path:) }.to_not raise_error + expect { DVLA::Herodotus.logger('rspec', output_path: output_path) }.to_not raise_error + end + + it 'will create a directory for a proc output_path if it does not exist' do + output_path = Proc.new { "test-path/#{rand(9999)}/log.txt" } + expect { DVLA::Herodotus.logger('rspec', output_path: output_path) }.to_not raise_error end it 'raises an error when an unexpected type is passed in as an output_path' do