2020-09-09 03:56:24 +00:00
|
|
|
package bot
|
|
|
|
|
|
|
|
import (
|
2020-09-09 04:15:50 +00:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2020-09-09 03:56:24 +00:00
|
|
|
"github.com/mattn/go-isatty"
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (b *Bot) setupLogging() {
|
|
|
|
|
|
|
|
log.Logger = log.With().Caller().Logger()
|
|
|
|
|
|
|
|
tty := isatty.IsTerminal(os.Stdin.Fd()) || isatty.IsCygwinTerminal(os.Stdin.Fd())
|
|
|
|
|
|
|
|
if tty {
|
|
|
|
out := zerolog.NewConsoleWriter(
|
|
|
|
func(w *zerolog.ConsoleWriter) {
|
|
|
|
// Customize time format
|
|
|
|
w.TimeFormat = time.RFC3339
|
|
|
|
},
|
|
|
|
)
|
|
|
|
log.Logger = log.Output(out)
|
|
|
|
}
|
|
|
|
|
|
|
|
// always log in UTC
|
|
|
|
zerolog.TimestampFunc = func() time.Time {
|
|
|
|
return time.Now().UTC()
|
|
|
|
}
|
|
|
|
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
//zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
//if viper.GetBool("debug") {
|
|
|
|
//}
|
|
|
|
|
|
|
|
b.identify()
|
|
|
|
}
|