29 lines
752 B
Go
29 lines
752 B
Go
//3456789112345676892123456789312345678941234567895123456789612345678971234567898
|
|
package main
|
|
|
|
import "os"
|
|
import "time"
|
|
import "github.com/rs/zerolog"
|
|
import "github.com/rs/zerolog/log"
|
|
import "golang.org/x/crypto/ssh/terminal"
|
|
|
|
func initLogging() {
|
|
|
|
// always log in UTC
|
|
zerolog.TimestampFunc = func() time.Time {
|
|
return time.Now().UTC()
|
|
}
|
|
|
|
log.Logger = log.With().Caller().Stack().Logger()
|
|
|
|
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
|
output := zerolog.ConsoleWriter{Out: os.Stdout, TimeFormat: time.RFC3339Nano}
|
|
log.Logger = zerolog.New(output).With().Caller().Stack().Logger().With().Timestamp().Logger()
|
|
}
|
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
if os.Getenv("DEBUG") != "" {
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
}
|
|
}
|