Skip to content

Commit

Permalink
version: log charon version info on startup (#1276)
Browse files Browse the repository at this point in the history
Adds a common function to log charon version information on startup.

category: feature
ticket: #1194
  • Loading branch information
xenowits authored Oct 12, 2022
1 parent fb37bba commit 9ebcc6b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
7 changes: 1 addition & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,7 @@ func Run(ctx context.Context, conf Config) (err error) {
return err
}

gitHash, gitTimestamp := version.GitCommit()
log.Info(ctx, "Charon starting",
z.Str("version", version.Version),
z.Str("git_commit_hash", gitHash),
z.Str("git_commit_time", gitTimestamp),
)
version.LogInfo(ctx, "Charon starting")

// Wire processes and their dependencies
life := new(lifecycle.Manager)
Expand Down
18 changes: 17 additions & 1 deletion app/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@

package version

import "runtime/debug"
import (
"context"
"runtime/debug"

"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/app/z"
)

// Version is the release version of the codebase.
// Usually overridden by tag names when building binaries.
Expand All @@ -40,3 +46,13 @@ func GitCommit() (hash string, timestamp string) {

return hash, timestamp
}

// LogInfo logs charon version information along-with the provided message.
func LogInfo(ctx context.Context, msg string) {
gitHash, gitTimestamp := GitCommit()
log.Info(ctx, msg,
z.Str("version", Version),
z.Str("git_commit_hash", gitHash),
z.Str("git_commit_time", gitTimestamp),
)
}
3 changes: 3 additions & 0 deletions cmd/bootnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/app/version"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/p2p"
)
Expand Down Expand Up @@ -94,6 +95,8 @@ func RunBootnode(ctx context.Context, config BootnodeConfig) error {
return err
}

version.LogInfo(ctx, "Charon bootnode starting")

key, err := p2p.LoadPrivKey(config.DataDir)
if errors.Is(err, os.ErrNotExist) {
if !config.AutoP2PKey {
Expand Down
3 changes: 3 additions & 0 deletions cmd/createdkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/app/version"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/cluster"
"github.com/obolnetwork/charon/eth2util"
Expand Down Expand Up @@ -92,6 +93,8 @@ func runCreateDKG(ctx context.Context, conf createDKGConfig) (err error) {
}
}()

version.LogInfo(ctx, "Charon create DKG starting")

if _, err := os.Stat(path.Join(conf.OutputDir, "cluster-definition.json")); err == nil {
return errors.New("existing cluster-definition.json found. Try again after deleting it")
}
Expand Down
3 changes: 3 additions & 0 deletions dkg/dkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/obolnetwork/charon/app/errors"
"github.com/obolnetwork/charon/app/log"
"github.com/obolnetwork/charon/app/version"
"github.com/obolnetwork/charon/app/z"
"github.com/obolnetwork/charon/cluster"
"github.com/obolnetwork/charon/core"
Expand Down Expand Up @@ -68,6 +69,8 @@ func Run(ctx context.Context, conf Config) (err error) {
return err
}

version.LogInfo(ctx, "Charon DKG starting")

def, err := loadDefinition(ctx, conf)
if err != nil {
return err
Expand Down

0 comments on commit 9ebcc6b

Please sign in to comment.