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

View File

@@ -2,6 +2,10 @@ package main
import (
"crypto/tls"
"fmt"
"log"
"os"
"time"
"layeh.com/barnard/uiterm"
"layeh.com/gumble/gumble"
@@ -14,6 +18,10 @@ type Barnard struct {
Address string
TLSConfig tls.Config
Debug bool
Logger *log.Logger
TreeWidth int
LogFile *os.File
Stream *gumbleopenal.Stream
@@ -24,3 +32,16 @@ type Barnard struct {
UiTree uiterm.Tree
UiInputStatus uiterm.Label
}
func (b *Barnard) debugf(format string, args ...interface{}) {
if b.Debug && b.Logger != nil {
b.Logger.Printf(format, args...)
}
}
func (b *Barnard) logMessage(line string) {
if b.LogFile != nil {
now := time.Now()
fmt.Fprintf(b.LogFile, "[%s] %s\n", now.Format("2006-01-02 15:04:05"), line)
}
}