diff --git a/lib/fluent/supervisor.rb b/lib/fluent/supervisor.rb index 1bd61d3c1c..69d8383d67 100644 --- a/lib/fluent/supervisor.rb +++ b/lib/fluent/supervisor.rb @@ -341,6 +341,10 @@ def init(process_type, worker_id) @opts[:worker_id] = worker_id if @path && @path != "-" + unless File.exist?(@path) + FileUtils.mkdir_p(File.dirname(@path)) + end + @logdev = if @log_rotate_age || @log_rotate_size Fluent::LogDeviceIO.new(Fluent.windows? ? worker_id_suffixed_path(worker_id, @path) : @path, diff --git a/test/test_logger_initializer.rb b/test/test_logger_initializer.rb new file mode 100644 index 0000000000..55f4c49e82 --- /dev/null +++ b/test/test_logger_initializer.rb @@ -0,0 +1,26 @@ +require_relative 'helper' +require 'fluent/supervisor' +require 'fileutils' + +class LoggerInitializerTest < ::Test::Unit::TestCase + TMP_DIR = File.expand_path(File.dirname(__FILE__) + "/tmp/logger_initializer#{ENV['TEST_ENV_NUMBER']}") + + teardown do + begin + FileUtils.rm_rf(TMP_DIR) + rescue => _ + end + end + + test 'when path is given' do + path = File.join(TMP_DIR, 'fluent_with_path.log') + + assert_false File.exist?(TMP_DIR) + logger = Fluent::Supervisor::LoggerInitializer.new(path, Fluent::Log::LEVEL_DEBUG, nil, nil, {}) + + assert_nothing_raised do + logger.init(:supervisor, 0) + end + assert_true File.exist?(TMP_DIR) + end +end