add the ability to force debug logs with GIRC_DEBUG

This commit is contained in:
Liam Stanley 2019-07-04 15:05:28 -04:00
parent e71da9d979
commit f62ce57a2f

@ -12,8 +12,10 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"runtime" "runtime"
"sort" "sort"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -247,9 +249,19 @@ func New(config Config) *Client {
c.Config.PingDelay = 600 * time.Second c.Config.PingDelay = 600 * time.Second
} }
envDebug, _ := strconv.ParseBool(os.Getenv("GIRC_DEBUG"))
if c.Config.Debug == nil { if c.Config.Debug == nil {
c.debug = log.New(ioutil.Discard, "", 0) if envDebug {
c.debug = log.New(os.Stderr, "debug:", log.Ltime|log.Lshortfile)
} else {
c.debug = log.New(ioutil.Discard, "", 0)
}
} else { } else {
if envDebug {
if c.Config.Debug != os.Stdout && c.Config.Debug != os.Stderr {
c.Config.Debug = io.MultiWriter(os.Stderr, c.Config.Debug)
}
}
c.debug = log.New(c.Config.Debug, "debug:", log.Ltime|log.Lshortfile) c.debug = log.New(c.Config.Debug, "debug:", log.Ltime|log.Lshortfile)
c.debug.Print("initializing debugging") c.debug.Print("initializing debugging")
} }