diff --git a/cmd/main.go b/cmd/main.go index 9bc377e6..52cd7444 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -78,6 +78,8 @@ func start(cliCtx *cli.Context) error { setupLog(c.Log) + log.Infof("Starting application...\n%s", agglayer.GetVersionInfo()) + // 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() 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 }