Last active
October 7, 2019 17:31
-
-
Save AndreKR/64af06c9da83d31b2e759beea9387efc to your computer and use it in GitHub Desktop.
Initializing logrus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The state of Go logging libraries is disheartening... | |
import ( | |
"github.com/mattn/go-colorable" // not ansicolor because github.com/mgutz/ansi recommends colorable | |
log "github.com/sirupsen/logrus" | |
"github.com/x-cray/logrus-prefixed-formatter" | |
"golang.org/x/crypto/ssh/terminal" | |
"os" | |
) | |
func init() { | |
log.SetFormatter(&prefixed.TextFormatter{ | |
ForceColors: true, | |
ForceFormatting: terminal.IsTerminal(int(os.Stderr.Fd())), | |
}) | |
log.SetOutput(ansicolor.NewAnsiColorWriter(os.Stderr)) | |
log.SetLevel(log.DebugLevel) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment