7 "github.com/jhalter/mobius/hotline"
8 "github.com/rivo/tview"
10 "go.uber.org/zap/zapcore"
19 _, cancelRoot := context.WithCancel(context.Background())
21 sigChan := make(chan os.Signal, 1)
22 signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, os.Interrupt)
24 configDir := flag.String("config", defaultConfigPath(), "Path to config root")
25 version := flag.Bool("version", false, "print version and exit")
26 logLevel := flag.String("log-level", "info", "Log level")
27 logFile := flag.String("log-file", "", "output logs to file")
32 fmt.Printf("v%s\n", hotline.VERSION)
36 zapLvl, ok := zapLogLevel[*logLevel]
38 fmt.Printf("Invalid log level %s. Must be debug, info, warn, or error.\n", *logLevel)
43 db := &hotline.DebugBuffer{
44 TextView: tview.NewTextView(),
47 cores := []zapcore.Core{newZapCore(zapLvl, db)}
49 // Add file logger if optional log-file flag was passed
51 f, err := os.OpenFile(*logFile,
52 os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
60 cores = append(cores, newZapCore(zapLvl, f))
63 l := zap.New(zapcore.NewTee(cores...))
64 defer func() { _ = l.Sync() }()
66 logger.Infow("Started Mobius client", "Version", hotline.VERSION)
70 logger.Infow("Stopping client", "signal", sig.String())
74 client := hotline.NewClient(*configDir, logger)
80 func newZapCore(level zapcore.Level, syncer zapcore.WriteSyncer) zapcore.Core {
81 encoderCfg := zap.NewProductionEncoderConfig()
82 encoderCfg.TimeKey = "timestamp"
83 encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
85 return zapcore.NewCore(
86 zapcore.NewConsoleEncoder(encoderCfg),
92 var zapLogLevel = map[string]zapcore.Level{
93 "debug": zap.DebugLevel,
94 "info": zap.InfoLevel,
95 "warn": zap.WarnLevel,
96 "error": zap.ErrorLevel,
99 func defaultConfigPath() (cfgPath string) {
103 cfgPath = "mobius-client-config.yaml"
105 cfgPath = "/usr/local/etc/mobius-client-config.yaml"
107 cfgPath = "/usr/local/etc/mobius-client-config.yaml"
109 fmt.Printf("unsupported OS")