Merge pull request #10 from pushrax/add-forced-colors

Add option to force TextFormatter to use colors
This commit is contained in:
Simon Eskildsen 2014-03-16 16:17:15 -07:00
commit f9af352362
2 changed files with 5 additions and 1 deletions

View File

@ -170,6 +170,8 @@ The built-in logging formatters are:
* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise
without colors.
* *Note:* to force colored output when there is no TTY, set the `ForceColors`
field to `true`.
* `logrus.JSONFormatter`. Logs fields as JSON.
Third party logging formatters:

View File

@ -18,12 +18,14 @@ const (
)
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) {
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]
levelColor := blue