mirror of
https://github.com/nonoo/kappanhang.git
synced 2025-12-06 08:02:00 +01:00
Add command line argument to turn off logging
This commit is contained in:
parent
0888eea5a6
commit
0eab91d9bf
5
args.go
5
args.go
|
|
@ -9,6 +9,7 @@ import (
|
|||
)
|
||||
|
||||
var verboseLog bool
|
||||
var quietLog bool
|
||||
var connectAddress string
|
||||
var username string
|
||||
var password string
|
||||
|
|
@ -23,6 +24,7 @@ var statusLogInterval time.Duration
|
|||
func parseArgs() {
|
||||
h := getopt.BoolLong("help", 'h', "display help")
|
||||
v := getopt.BoolLong("verbose", 'v', "Enable verbose (debug) logging")
|
||||
q := getopt.BoolLong("quiet", 'q', "Disable logging")
|
||||
a := getopt.StringLong("address", 'a', "IC-705", "Connect to address")
|
||||
u := getopt.StringLong("username", 'u', "beer", "Username")
|
||||
p := getopt.StringLong("password", 'p', "beerbeer", "Password")
|
||||
|
|
@ -36,13 +38,14 @@ func parseArgs() {
|
|||
|
||||
getopt.Parse()
|
||||
|
||||
if *h || *a == "" {
|
||||
if *h || *a == "" || (*q && *v) {
|
||||
fmt.Println(getAboutStr())
|
||||
getopt.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
verboseLog = *v
|
||||
quietLog = *q
|
||||
connectAddress = *a
|
||||
username = *u
|
||||
password = *p
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ const controlStreamPort = 50001
|
|||
const serialStreamPort = 50002
|
||||
const audioStreamPort = 50003
|
||||
|
||||
const reauthInterval = time.Minute
|
||||
const reauthTimeout = 3 * time.Second
|
||||
|
||||
type controlStream struct {
|
||||
common streamCommon
|
||||
serial serialStream
|
||||
|
|
@ -285,7 +288,7 @@ func (s *controlStream) loop() {
|
|||
s.reauthTimeoutTimer = time.NewTimer(0)
|
||||
<-s.reauthTimeoutTimer.C
|
||||
|
||||
reauthTicker := time.NewTicker(25 * time.Second)
|
||||
reauthTicker := time.NewTicker(reauthInterval)
|
||||
|
||||
for {
|
||||
select {
|
||||
|
|
@ -297,7 +300,7 @@ func (s *controlStream) loop() {
|
|||
}
|
||||
case <-reauthTicker.C:
|
||||
log.Debug("sending auth")
|
||||
s.reauthTimeoutTimer.Reset(3 * time.Second)
|
||||
s.reauthTimeoutTimer.Reset(reauthTimeout)
|
||||
if err := s.sendPktAuth(0x05); err != nil {
|
||||
reportError(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
)
|
||||
|
||||
type keyboardStruct struct {
|
||||
initialized bool
|
||||
}
|
||||
|
||||
var keyboard keyboardStruct
|
||||
|
|
@ -23,6 +24,10 @@ func (s *keyboardStruct) loop() {
|
|||
}
|
||||
|
||||
func (s *keyboardStruct) init() {
|
||||
if s.initialized {
|
||||
return
|
||||
}
|
||||
|
||||
if err := exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run(); err != nil {
|
||||
log.Error("can't disable input buffering")
|
||||
}
|
||||
|
|
@ -30,6 +35,8 @@ func (s *keyboardStruct) init() {
|
|||
log.Error("can't disable displaying entered characters")
|
||||
}
|
||||
|
||||
s.initialized = true
|
||||
|
||||
go s.loop()
|
||||
}
|
||||
|
||||
|
|
|
|||
2
log.go
2
log.go
|
|
@ -88,6 +88,8 @@ func (l *logger) Init() {
|
|||
var level zapcore.Level
|
||||
if verboseLog {
|
||||
level = zap.DebugLevel
|
||||
} else if quietLog {
|
||||
level = zap.FatalLevel
|
||||
} else {
|
||||
level = zap.InfoLevel
|
||||
}
|
||||
|
|
|
|||
4
main.go
4
main.go
|
|
@ -105,10 +105,6 @@ func main() {
|
|||
osSignal := make(chan os.Signal, 1)
|
||||
signal.Notify(osSignal, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
if statusLog.isRealtimeInternal() {
|
||||
keyboard.init()
|
||||
}
|
||||
|
||||
var retries int
|
||||
var requireWait bool
|
||||
var shouldExit bool
|
||||
|
|
|
|||
|
|
@ -491,7 +491,7 @@ func (s *statusLogStruct) loop() {
|
|||
}
|
||||
|
||||
func (s *statusLogStruct) isRealtimeInternal() bool {
|
||||
return statusLogInterval < time.Second
|
||||
return keyboard.initialized
|
||||
}
|
||||
|
||||
func (s *statusLogStruct) isRealtime() bool {
|
||||
|
|
@ -552,8 +552,10 @@ func (s *statusLogStruct) initIfNeeded() {
|
|||
return
|
||||
}
|
||||
|
||||
if !isatty.IsTerminal(os.Stdout.Fd()) && statusLogInterval < time.Second {
|
||||
if quietLog || (!isatty.IsTerminal(os.Stdout.Fd()) && statusLogInterval < time.Second) {
|
||||
statusLogInterval = time.Second
|
||||
} else {
|
||||
keyboard.init()
|
||||
}
|
||||
|
||||
c := color.New(color.FgHiWhite)
|
||||
|
|
|
|||
Loading…
Reference in a new issue