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