github.com/pingcap/br@v5.3.0-alpha.0.20220125034240-ec59c7b6ce30+incompatible/pkg/version/build/info.go (about) 1 // Copyright 2021 PingCAP, Inc. Licensed under Apache-2.0. 2 3 package build 4 5 import ( 6 "bytes" 7 "fmt" 8 "runtime" 9 10 "github.com/pingcap/log" 11 "github.com/pingcap/tidb/util/israce" 12 "go.uber.org/zap" 13 ) 14 15 // Version information. 16 var ( 17 ReleaseVersion = "v5.0.0-master" 18 BuildTS = "None" 19 GitHash = "None" 20 GitBranch = "None" 21 goVersion = runtime.Version() 22 ) 23 24 // AppName is a name of a built binary. 25 type AppName string 26 27 var ( 28 // BR is the name of BR binary. 29 BR AppName = "Backup & Restore (BR)" 30 // Lightning is the name of Lightning binary. 31 Lightning AppName = "TiDB-Lightning" 32 ) 33 34 // LogInfo logs version information. 35 func LogInfo(name AppName) { 36 oldLevel := log.GetLevel() 37 log.SetLevel(zap.InfoLevel) 38 defer log.SetLevel(oldLevel) 39 40 log.Info(fmt.Sprintf("Welcome to %s", name), 41 zap.String("release-version", ReleaseVersion), 42 zap.String("git-hash", GitHash), 43 zap.String("git-branch", GitBranch), 44 zap.String("go-version", goVersion), 45 zap.String("utc-build-time", BuildTS), 46 zap.Bool("race-enabled", israce.RaceEnabled)) 47 } 48 49 // Info returns version information. 50 func Info() string { 51 buf := bytes.Buffer{} 52 fmt.Fprintf(&buf, "Release Version: %s\n", ReleaseVersion) 53 fmt.Fprintf(&buf, "Git Commit Hash: %s\n", GitHash) 54 fmt.Fprintf(&buf, "Git Branch: %s\n", GitBranch) 55 fmt.Fprintf(&buf, "Go Version: %s\n", goVersion) 56 fmt.Fprintf(&buf, "UTC Build Time: %s\n", BuildTS) 57 fmt.Fprintf(&buf, "Race Enabled: %t", israce.RaceEnabled) 58 return buf.String() 59 }