From 0f38c477ee24de3dd7e36be8fe078880a35fdcba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Sun, 28 Apr 2024 09:40:52 +0200 Subject: [PATCH 1/2] Include version info in the logs --- cmd/main.go | 3 +++ log/log.go | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/main.go b/cmd/main.go index 9bc377e6..03199c75 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -78,6 +78,9 @@ func start(cliCtx *cli.Context) error { setupLog(c.Log) + agglayer.PrintVersion(os.Stdout) + log.Info("Starting application...") + // Prepare DB pg, err := dbConf.NewSQLDB(c.DB) if err != nil { diff --git a/log/log.go b/log/log.go index c616281d..50184dad 100644 --- a/log/log.go +++ b/log/log.go @@ -9,6 +9,8 @@ import ( "github.com/hermeznetwork/tracerr" "go.uber.org/zap" "go.uber.org/zap/zapcore" + + "github.com/0xPolygon/agglayer" ) // LogEnvironment represents the possible log environments. @@ -74,7 +76,8 @@ func newLogger(cfg Config) (*zap.SugaredLogger, error) { zapCfg.Level = level zapCfg.OutputPaths = cfg.Outputs zapCfg.InitialFields = map[string]interface{}{ - "pid": os.Getpid(), + "version": agglayer.Version, + "pid": os.Getpid(), } logger, err := zapCfg.Build() From 6a2e60698004cdcc11d974cdc80f7876e651ee4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= Date: Sun, 28 Apr 2024 10:54:43 +0200 Subject: [PATCH 2/2] Minor change --- cmd/main.go | 3 +-- version.go | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 03199c75..52cd7444 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -78,8 +78,7 @@ func start(cliCtx *cli.Context) error { setupLog(c.Log) - agglayer.PrintVersion(os.Stdout) - log.Info("Starting application...") + log.Infof("Starting application...\n%s", agglayer.GetVersionInfo()) // Prepare DB pg, err := dbConf.NewSQLDB(c.DB) diff --git a/version.go b/version.go index 40464fdd..6681c660 100644 --- a/version.go +++ b/version.go @@ -16,10 +16,16 @@ var ( // PrintVersion prints version info into the provided io.Writer. func PrintVersion(w io.Writer) { - fmt.Fprintf(w, "Version: %s\n", Version) - fmt.Fprintf(w, "Git revision: %s\n", GitRev) - fmt.Fprintf(w, "Git branch: %s\n", GitBranch) - fmt.Fprintf(w, "Go version: %s\n", runtime.Version()) - fmt.Fprintf(w, "Built: %s\n", BuildDate) - fmt.Fprintf(w, "OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) + fmt.Fprint(w, GetVersionInfo()) +} + +// GetVersionInfo returns version information as a formatted string. +func GetVersionInfo() string { + versionInfo := fmt.Sprintf("Version: %s\n", Version) + versionInfo += fmt.Sprintf("Git revision: %s\n", GitRev) + versionInfo += fmt.Sprintf("Git branch: %s\n", GitBranch) + versionInfo += fmt.Sprintf("Go version: %s\n", runtime.Version()) + versionInfo += fmt.Sprintf("Built: %s\n", BuildDate) + versionInfo += fmt.Sprintf("OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH) + return versionInfo }