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

Panic when logging func within struct #960

Closed
mickeyreiss opened this issue May 7, 2019 · 3 comments
Closed

Panic when logging func within struct #960

mickeyreiss opened this issue May 7, 2019 · 3 comments

Comments

@mickeyreiss
Copy link

In #870, logrus added support for gracefully avoiding logging funcs. However, this solution did not cover func values nested within structs.

This has caused panics in our staging and production environments when inadvertently passing in complex structs as fields.

cc/ @smacker
cc/ @dgsb

@dgsb dgsb added the bug label May 18, 2019
@dgsb
Copy link
Collaborator

dgsb commented May 18, 2019

@mickeyreiss if you are using the JSONFormatter, a simple fix woul be to add empty json tag to your structure for this field.
The func would be then skipped by the standard library json encoder.

@mickeyreiss
Copy link
Author

@dgsb That would work if every dev understood what is and is not allowed to be logged in logrus.Fields values (which are typed as an interface{}.) Unfortunately that limitation is not well understood (for example because it doesn't follow the same rules as fmt.Printf), and then panic recovery code inadvertently writes logs and panics again.

Another issue I've faced: Some third-party libraries (e.g. pubsub) may define such struct types without json tags.

@dgsb
Copy link
Collaborator

dgsb commented May 26, 2019

@mickeyreiss we completely rely on the standard library for the json encoding. There is not so many things we can do here to fix this. I can think of two options here, either you add tag to skip such fields or you wrap the structure itself in another one which implements the MarshalJSON interface.
You can find more information here https://golang.org/pkg/encoding/json/#Marshal

@dgsb dgsb added invalid and removed bug labels May 26, 2019
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