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

Broken LOG15_ERROR messages #68

Open
tg opened this issue Nov 27, 2015 · 1 comment
Open

Broken LOG15_ERROR messages #68

tg opened this issue Nov 27, 2015 · 1 comment

Comments

@tg
Copy link
Contributor

tg commented Nov 27, 2015

I've been reading the section about error handling and tried to play with some mistyped keys (to see LOG15_ERROR reports), but it didn't work very well.

Here is the code and corresponding output:

log15.Info("one empty error", 1)
// Output:
// t=2015-11-27T19:57:07+0100 lvl=info msg="one empty error" LOG15_ERROR= LOG15_ERROR="Normalized odd number of arguments by adding nil"

log15.Info("empty error", 1, 2)
// Output:  
// t=2015-11-27T19:57:07+0100 lvl=info msg="empty error" LOG15_ERROR=

log15.Info("two empty errors", 1, 2, 3, 4)
// Output:  
// t=2015-11-27T19:57:07+0100 lvl=info msg="two empty errors" LOG15_ERROR= LOG15_ERROR=
@tg
Copy link
Contributor Author

tg commented Nov 28, 2015

The problem with empty LOG15_ERROR is due to this code in logfmt:

k, ok := ctx[i].(string)
v := formatLogfmtValue(ctx[i+1])
if !ok {
    k, v = errorKey, formatLogfmtValue(k) // oops, k is empty here!
}

I think the code tried to include key name of invalid field, but this is empty because of the failed conversion to string. One possible solution could be to include field ID in error string, i.e. something like:

v = fmt.Printf("field %d is not a string", i)

I'm happy to provide a patch once the intended behaviour is confirmed.

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

No branches or pull requests

1 participant