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