Disable stderr logging unless logfile is selected
This commit is contained in:
committed by
Brandon McGinty
parent
29dde07337
commit
d2e94c76b5
@@ -137,7 +137,7 @@ func main() {
|
|||||||
toneTestOutput := flag.String("tone-out", "incoming.pcm", "file to save incoming audio to in tone-test mode")
|
toneTestOutput := flag.String("tone-out", "incoming.pcm", "file to save incoming audio to in tone-test mode")
|
||||||
tcpOnly := flag.Bool("tcp", false, "disable UDP, force audio through TCP tunnel")
|
tcpOnly := flag.Bool("tcp", false, "disable UDP, force audio through TCP tunnel")
|
||||||
logLevel := flag.String("log", "warn", "log level: debug, info, warn, error")
|
logLevel := flag.String("log", "warn", "log level: debug, info, warn, error")
|
||||||
logFile := flag.String("logfile", "", "write logs to this file (in addition to stderr)")
|
logFile := flag.String("logfile", "", "write logs to this file (logging is disabled when omitted)")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
@@ -155,17 +155,17 @@ func main() {
|
|||||||
default:
|
default:
|
||||||
level = barnlog.LevelWarn
|
level = barnlog.LevelWarn
|
||||||
}
|
}
|
||||||
// Default: log to stderr
|
// Logging is opt-in. Select /dev/stderr explicitly when terminal logging is
|
||||||
var writer io.Writer = os.Stderr
|
// desired; otherwise library diagnostics must not corrupt terminal output.
|
||||||
|
barnlog.SetLogger(nil)
|
||||||
if *logFile != "" {
|
if *logFile != "" {
|
||||||
f, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
f, err := os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "cannot open log file %s: %v\n", *logFile, err)
|
fmt.Fprintf(os.Stderr, "cannot open log file %s: %v\n", *logFile, err)
|
||||||
} else {
|
} else {
|
||||||
writer = io.MultiWriter(os.Stderr, f)
|
barnlog.SetLogger(barnlog.NewWriterLogger(f, level))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
barnlog.SetLogger(barnlog.NewWriterLogger(writer, level))
|
|
||||||
|
|
||||||
if *profile == true {
|
if *profile == true {
|
||||||
go func() {
|
go func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user