From 81087bf96c3544741da80e95bd5ee1d5ffa664b0 Mon Sep 17 00:00:00 2001 From: WhiteFoRest <72013920+whiteforestever@users.noreply.github.com> Date: Sun, 10 Mar 2024 19:27:54 +0300 Subject: [PATCH] Update README.md add error handling for `logger.Sync()` --- README.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a17035cb6..d1ef39d62 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,12 @@ packages and includes both structured and `printf`-style APIs. ```go logger, _ := zap.NewProduction() -defer logger.Sync() // flushes buffer, if any +defer func(logger *zap.Logger) { + err := logger.Sync() + if err != nil { + log.Fatal(err) + } +}(logger) // flushes buffer, if any sugar := logger.Sugar() sugar.Infow("failed to fetch URL", // Structured context as loosely typed key-value pairs. @@ -42,7 +47,12 @@ structured logging. ```go logger, _ := zap.NewProduction() -defer logger.Sync() +defer func(logger *zap.Logger) { + err := logger.Sync() + if err != nil { + log.Fatal(err) + } +}(logger) logger.Info("failed to fetch URL", // Structured context as strongly typed Field values. zap.String("url", url),