Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Include version info in the logs (#129)
Browse files Browse the repository at this point in the history
* Include version info in the logs
  • Loading branch information
Stefan-Ethernal authored Apr 29, 2024
1 parent 29b09df commit 43c1cd7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 12 additions & 6 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 43c1cd7

Please sign in to comment.