Skip to content

Commit

Permalink
Include version info in the logs at the app startup (#88)
Browse files Browse the repository at this point in the history
* Output version to the logs

* Minor change
  • Loading branch information
Stefan-Ethernal committed May 15, 2024
1 parent d2cf833 commit 38433c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ func start(cliCtx *cli.Context) error {
}
setupLog(c.Log)

log.Infof("Starting application...\n%s", dataavailability.GetVersionInfo())

// Prepare DB
pg, err := db.InitContext(cliCtx.Context, c.DB)
if err != nil {
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 38433c7

Please sign in to comment.