logger/slog: close writer, and sleep
All checks were successful
lint / lint (pull_request) Successful in 1m7s
test / test (pull_request) Successful in 3m27s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-12-22 22:09:45 +03:00
parent d9604f7922
commit 86d99f086e

View File

@ -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)
}