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

LogstashFormatter doesn't perform an error type check when setting fields so some errors are not correctly serialised. #377

Closed
jonoradich opened this issue Jun 30, 2016 · 2 comments
Assignees

Comments

@jonoradich
Copy link

This is essentially the same issue as #137 but with the LogstashFormatter.

LogstashFormatter:

func (f *LogstashFormatter) Format(entry *logrus.Entry) ([]byte, error) {
    fields := make(logrus.Fields)
    for k, v := range entry.Data {
        fields[k] = v
    }
        ....

JSONFormatter:

func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
    data := make(Fields, len(entry.Data)+3)
    for k, v := range entry.Data {
        switch v := v.(type) {
        case error:
            // Otherwise errors are ignored by `encoding/json`
            // https://github.com/Sirupsen/logrus/issues/137
            data[k] = v.Error()
        default:
            data[k] = v
        }
    }
        ...

The resulting error field, using golangs url.Error as an example (https://golang.org/pkg/net/url/#Error), is serialised like so:

"error":{"Op":"Get","URL":"http://example.com","Err":{}}
@aarongreenlee
Copy link
Collaborator

Thank you for reporting.

@jonoradich
Copy link
Author

Solved by bshuster-repo/logrus-logstash-hook#6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants