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