add debug logging flag

This commit is contained in:
Username
2026-02-24 09:25:20 +01:00
parent bbd809c73f
commit fc1aaf354b
3 changed files with 49 additions and 0 deletions

19
main.go
View File

@@ -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