From 83fb697f80350af24b30fbbf4dae9b51dcd93c02 Mon Sep 17 00:00:00 2001
From: Leonard Lyubich <leonard@nspcc.ru>
Date: Tue, 29 Mar 2022 12:39:49 +0300
Subject: [PATCH] [#380] cmd/s3-gw: Write app name and version once on startup

It's redundant to write app name and version in each log message, a
single entry at the start is enough.

Make `App.Wait` to write app name as `neofs-s3-gw` in `application
started` message. Do not add `app_name` and `app_version` fields to the
logger returned by `newLogger`.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
---
 cmd/s3-gw/app.go  | 9 ++++++++-
 cmd/s3-gw/main.go | 8 +-------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/cmd/s3-gw/app.go b/cmd/s3-gw/app.go
index 3e3aa82..bbd2eca 100644
--- a/cmd/s3-gw/app.go
+++ b/cmd/s3-gw/app.go
@@ -189,8 +189,15 @@ func newApp(ctx context.Context, l *zap.Logger, v *viper.Viper) *App {
 }
 
 // Wait waits for application to finish.
+//
+// Pre-logs a message about the launch of the application mentioning its
+// version (version.Version) and name (neofs-s3-gw). At the end writes to the
+// log about the stop.
 func (a *App) Wait() {
-	a.log.Info("application started", zap.String("version", version.Version))
+	a.log.Info("application started",
+		zap.String("name", "neofs-s3-gw"),
+		zap.String("version", version.Version),
+	)
 
 	<-a.webDone // wait for web-server to be stopped
 
diff --git a/cmd/s3-gw/main.go b/cmd/s3-gw/main.go
index 41f2e1a..bac6bb6 100644
--- a/cmd/s3-gw/main.go
+++ b/cmd/s3-gw/main.go
@@ -6,7 +6,6 @@ import (
 	"os/signal"
 	"syscall"
 
-	"github.com/nspcc-dev/neofs-s3-gw/internal/version"
 	"github.com/spf13/viper"
 	"go.uber.org/zap"
 	"go.uber.org/zap/zapcore"
@@ -19,8 +18,6 @@ import (
 //  * parameterized level (debug by default)
 //  * console encoding
 //  * ISO8601 time encoding
-//  * app_name field set to neofs-s3-gw
-//  * app_version field set to version.Version
 //
 // Logger records a stack trace for all messages at or above fatal level.
 //
@@ -55,10 +52,7 @@ func newLogger(v *viper.Viper) *zap.Logger {
 		panic(fmt.Sprintf("build zap logger instance: %v", err))
 	}
 
-	return l.With(
-		zap.String("app_name", "neofs-s3-gw"),
-		zap.String("app_version", version.Version),
-	)
+	return l
 }
 
 func main() {