commit | 22ddf55578b140ef202a33aa0490be37bed356d4 | [log] [tgz] |
---|---|---|
author | Mislav Marohnić <mislav.marohnic@gmail.com> | Tue Feb 09 23:24:35 2016 |
committer | Mislav Marohnić <mislav.marohnic@gmail.com> | Tue Feb 09 23:24:35 2016 |
tree | f1cda5b76ec3aa73bc847b64be34e183a308786b | |
parent | 4af63d73f5bea08b682ad2cd198b1e607afd6be0 [diff] |
Add a generic `NewColorable()` constructor The generic constructor accepts any `os.File` pointer. This is useful when this library is used to support a generic colorable writer stream whose destination (stdout, stderr, log file, etc.) is determined dynamically at runtime.
Colorable writer for windows.
For example, most of logger packages doesn‘t show colors on windows. (I know we can do it with ansicon. But I don’t want.) This package is possible to handle escape sequence for ansi color on windows.
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
logrus.SetOutput(colorable.NewColorableStdout())
logrus.Info("succeeded")
logrus.Warn("not correct")
logrus.Error("something error")
logrus.Fatal("panic")
You can compile above code on non-windows OSs.
$ go get github.com/mattn/go-colorable
MIT
Yasuhiro Matsumoto (a.k.a mattn)