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 version := flag.Bool("version", false, "print version and exit")
25 logLevel := flag.String("log-level", "info", "Log level")
26 logFile := flag.String("log-file", "", "output logs to file")
31 fmt.Printf("v%s\n", hotline.VERSION)
35 zapLvl, ok := zapLogLevel[*logLevel]
37 fmt.Printf("Invalid log level %s. Must be debug, info, warn, or error.\n", *logLevel)
42 db := &hotline.DebugBuffer{
43 TextView: tview.NewTextView(),
46 cores := []zapcore.Core{newZapCore(zapLvl, db)}
48 // Add file logger if optional log-file flag was passed
50 f, err := os.OpenFile(*logFile,
51 os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
59 cores = append(cores, newZapCore(zapLvl, f))
62 l := zap.New(zapcore.NewTee(cores...))
63 defer func() { _ = l.Sync() }()
65 logger.Infow("Started Mobius client", "Version", hotline.VERSION)
69 logger.Infow("Stopping client", "signal", sig.String())
73 cfgPath := defaultConfigPath()
75 client := hotline.NewClient(cfgPath, logger)
81 func newZapCore(level zapcore.Level, syncer zapcore.WriteSyncer) zapcore.Core {
82 encoderCfg := zap.NewProductionEncoderConfig()
83 encoderCfg.TimeKey = "timestamp"
84 encoderCfg.EncodeTime = zapcore.ISO8601TimeEncoder
86 return zapcore.NewCore(
87 zapcore.NewConsoleEncoder(encoderCfg),
93 var zapLogLevel = map[string]zapcore.Level{
94 "debug": zap.DebugLevel,
95 "info": zap.InfoLevel,
96 "warn": zap.WarnLevel,
97 "error": zap.ErrorLevel,
100 func defaultConfigPath() (cfgPath string) {
104 cfgPath = "mobius-client-config.yaml"
106 cfgPath = "/usr/local/etc/mobius-client-config.yaml"
108 cfgPath = "/usr/local/etc/mobius-client-config.yaml"
110 fmt.Printf("unsupported OS")