From 86d99f086ec64df34c5d3e8ddc023b6955a2e717 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Sun, 22 Dec 2024 22:09:45 +0300 Subject: [PATCH] logger/slog: close writer, and sleep Signed-off-by: Vasiliy Tolstov --- logger/slog/slog.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/logger/slog/slog.go b/logger/slog/slog.go index 3965efb6..63cc20bf 100644 --- a/logger/slog/slog.go +++ b/logger/slog/slog.go @@ -2,6 +2,7 @@ package slog import ( "context" + "io" "log/slog" "os" "reflect" @@ -10,6 +11,7 @@ import ( "strconv" "sync" "sync/atomic" + "time" "go.unistack.org/micro/v3/logger" "go.unistack.org/micro/v3/semconv" @@ -224,6 +226,10 @@ func (s *slogLogger) Error(ctx context.Context, msg string, attrs ...interface{} func (s *slogLogger) Fatal(ctx context.Context, msg string, attrs ...interface{}) { s.printLog(ctx, logger.FatalLevel, msg, attrs...) + if closer, ok := s.opts.Out.(io.Closer); ok { + closer.Close() + } + time.Sleep(1 * time.Second) os.Exit(1) }