-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
54 lines (44 loc) · 1.03 KB
/
main.go
File metadata and controls
54 lines (44 loc) · 1.03 KB
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
package main
import (
"os"
"bitbucket.org/neiku/hlog"
"bitbucket.org/neiku/winornot"
"github.com/1set/starcli/cli"
"github.com/1set/starcli/config"
"github.com/1set/starcli/module/sys"
"github.com/1set/starcli/web"
"github.com/spf13/viper"
"go.uber.org/zap"
)
var (
log *zap.SugaredLogger
)
func init() {
// fix for Windows terminal output
winornot.EnableANSIControl()
}
func main() {
// parse args
args := cli.ParseArgs()
// set log level
initLogger(args.LogLevel)
// load config
if err := config.InitConfig(args.ConfigFile); err != nil {
log.Fatalw("fail to load config", zap.Error(err))
}
log.Debugw("config loaded", "config_file", viper.ConfigFileUsed(), "host_name", config.GetHostname())
// main
os.Exit(cli.Process(args))
}
func initLogger(level string) {
// build root logger
lg := hlog.NewSimpleLogger()
if err := lg.SetLevelString(level); err != nil {
lg.Error(err)
}
log = lg.SugaredLogger.With(zap.Int("pid", os.Getpid()))
// set log for sub-packages
cli.SetLog(log)
web.SetLog(log)
sys.SetLog(log)
}