Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print logrus output in logfmt format #121

Merged
merged 2 commits into from
Sep 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func Setup(logLevel string) error {
}
logrus.SetOutput(os.Stderr)
logrus.SetLevel(level)
logrus.SetFormatter(&textFormatter{})
logrus.AddHook(hook)
SetGlobal(Logrus(logrus.StandardLogger()))
return nil
Expand Down
22 changes: 0 additions & 22 deletions logging/logrus.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package logging

import (
"bytes"
"fmt"
"os"
"strings"

"github.com/sirupsen/logrus"
)
Expand All @@ -14,7 +11,6 @@ func NewLogrus(level Level) Interface {
log := logrus.New()
log.Out = os.Stderr
log.Level = level.Logrus
log.Formatter = &textFormatter{}
return logrusLogger{log}
}

Expand Down Expand Up @@ -54,21 +50,3 @@ func (l logrusEntry) WithFields(fields Fields) Interface {
Entry: l.Entry.WithFields(map[string]interface{}(fields)),
}
}

type textFormatter struct{}

// Based off logrus.TextFormatter, which behaves completely
// differently when you don't want colored output
func (f *textFormatter) Format(entry *logrus.Entry) ([]byte, error) {
b := &bytes.Buffer{}

levelText := strings.ToUpper(entry.Level.String())[0:4]
timeStamp := entry.Time.Format("2006/01/02 15:04:05.000000")
fmt.Fprintf(b, "%s: %s %s", levelText, timeStamp, entry.Message)
if len(entry.Data) > 0 {
b.WriteString(" " + fieldsToString(entry.Data))
}

b.WriteByte('\n')
return b.Bytes(), nil
}