mirror of https://github.com/sirupsen/logrus.git
Merge pull request #10 from pushrax/add-forced-colors
Add option to force TextFormatter to use colors
This commit is contained in:
commit
f9af352362
|
@ -170,6 +170,8 @@ The built-in logging formatters are:
|
||||||
|
|
||||||
* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise
|
* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise
|
||||||
without colors.
|
without colors.
|
||||||
|
* *Note:* to force colored output when there is no TTY, set the `ForceColors`
|
||||||
|
field to `true`.
|
||||||
* `logrus.JSONFormatter`. Logs fields as JSON.
|
* `logrus.JSONFormatter`. Logs fields as JSON.
|
||||||
|
|
||||||
Third party logging formatters:
|
Third party logging formatters:
|
||||||
|
|
|
@ -18,12 +18,14 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type TextFormatter struct {
|
type TextFormatter struct {
|
||||||
|
// Set to true to bypass checking for a TTY before outputting colors.
|
||||||
|
ForceColors bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
func (f *TextFormatter) Format(entry *Entry) ([]byte, error) {
|
||||||
var serialized []byte
|
var serialized []byte
|
||||||
|
|
||||||
if ttyutils.IsTerminal(os.Stdout.Fd()) {
|
if f.ForceColors || ttyutils.IsTerminal(os.Stdout.Fd()) {
|
||||||
levelText := strings.ToUpper(entry.Data["level"].(string))[0:4]
|
levelText := strings.ToUpper(entry.Data["level"].(string))[0:4]
|
||||||
|
|
||||||
levelColor := blue
|
levelColor := blue
|
||||||
|
|
Loading…
Reference in New Issue