add debug logging flag
This commit is contained in:
19
main.go
19
main.go
@@ -4,6 +4,7 @@ import (
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
@@ -23,6 +24,9 @@ func main() {
|
||||
passwordPrompt := flag.Bool("password-prompt", false, "prompt for server password on stdin")
|
||||
insecure := flag.Bool("insecure", false, "skip server certificate verification")
|
||||
certificate := flag.String("certificate", "", "PEM encoded certificate and private key")
|
||||
debug := flag.Bool("debug", false, "enable debug logging to stderr")
|
||||
treeWidth := flag.Int("tree-width", 20, "width of the channel tree pane")
|
||||
logFile := flag.String("log", "", "write chat messages to file")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
@@ -56,6 +60,21 @@ func main() {
|
||||
|
||||
b.Config.Username = *username
|
||||
b.Config.Password = pass
|
||||
b.TreeWidth = *treeWidth
|
||||
b.Debug = *debug
|
||||
if b.Debug {
|
||||
b.Logger = log.New(os.Stderr, "barnard: ", log.Ltime)
|
||||
b.debugf("connecting to %s as %q", addr, *username)
|
||||
}
|
||||
if *logFile != "" {
|
||||
f, err := os.OpenFile(*logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer f.Close()
|
||||
b.LogFile = f
|
||||
}
|
||||
|
||||
if *insecure {
|
||||
b.TLSConfig.InsecureSkipVerify = true
|
||||
|
||||
Reference in New Issue
Block a user