From ce574f83674a03c1517574ac48dfd9d848facc9f Mon Sep 17 00:00:00 2001 From: Alexey Zapparov Date: Wed, 17 Jul 2024 02:58:37 +0200 Subject: [PATCH] fix: Use correct varname for closed appenders Regression: f7d54bf --- CHANGELOG.md | 2 ++ lib/semantic_logger/appenders.rb | 2 +- test/appenders_test.rb | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ff009ae..55b44329 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [unreleased] +- Fix regression in `SemanticLogger::Appenders#close` + ## [4.16.0] - Add appender for Honeybadger Insights using the events API diff --git a/lib/semantic_logger/appenders.rb b/lib/semantic_logger/appenders.rb index 3f5f8872..1a35256f 100644 --- a/lib/semantic_logger/appenders.rb +++ b/lib/semantic_logger/appenders.rb @@ -49,9 +49,9 @@ def close closed_appenders = [] each do |appender| logger.trace "Closing appender: #{appender.name}" - appenders << appender appender.flush appender.close + closed_appenders << appender rescue Exception => e logger.error "Failed to close appender: #{appender.name}", e end diff --git a/test/appenders_test.rb b/test/appenders_test.rb index 6ffdc01b..9b9c05cd 100644 --- a/test/appenders_test.rb +++ b/test/appenders_test.rb @@ -100,5 +100,16 @@ class AppendersTest < Minitest::Test # assert_instance_of SemanticLogger::Appender::Async, appender # end end + + describe "#close" do + it "closes appenders" do + appender = appenders.add(file_name: "test.log") + + appenders.close + + assert_equal 0, capture_logger.events.count { |it| it.message.match?(/failed/i) } + assert_equal 0, appenders.size + end + end end end