From 2d94735bb105172a85ae68b58ed399dc82dccd1d Mon Sep 17 00:00:00 2001 From: Takuro Ashie Date: Mon, 2 Jan 2023 16:25:07 +0900 Subject: [PATCH] log/console_adapter: Add missing seek Signed-off-by: Takuro Ashie --- lib/fluent/log/console_adapter.rb | 1 + test/log/test_console_adapter.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/fluent/log/console_adapter.rb b/lib/fluent/log/console_adapter.rb index 53de0df05d..85948018ba 100644 --- a/lib/fluent/log/console_adapter.rb +++ b/lib/fluent/log/console_adapter.rb @@ -43,6 +43,7 @@ def call(subject = nil, *arguments, name: nil, severity: 'info', **options, &blo level = 'warn' end + @io.seek(0) @io.truncate(0) super @logger.send(severity, @io.string.chomp) diff --git a/test/log/test_console_adapter.rb b/test/log/test_console_adapter.rb index 0d8cbea50b..06d9d900ad 100644 --- a/test/log/test_console_adapter.rb +++ b/test/log/test_console_adapter.rb @@ -92,4 +92,19 @@ def test_block(level) ], @logdev.logs) end + + data(debug: :debug, + info: :info, + warn: :warn, + error: :error, + fatal: :fatal) + def test_multiple_entries(level) + @console_logger.send(level, "subject1") + @console_logger.send(level, "line2") + assert_equal([ + "#{@timestamp_str} [#{level}]: 0.0s: subject1\n", + "#{@timestamp_str} [#{level}]: 0.0s: line2\n" + ], + @logdev.logs) + end end