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

Add json format support for Traefik logs #2056

Merged
merged 4 commits into from
Sep 21, 2017

Conversation

m3co-code
Copy link
Contributor

@m3co-code m3co-code commented Sep 5, 2017

This PR adds the possibility to use JSON format for the traefik logs.

Also it aligns the configuration to the accessLogs and deprecates the traefikLogsFile option.

Sample log line:

{"level":"info","msg":"Traefik version dev built on I don't remember exactly","time":"2017-09-05T02:34:52+02:00"}

This fixes #780.

Copy link
Member

@juliens juliens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👏

@m3co-code
Copy link
Contributor Author

@juliens thanks for the review! I added one more commit in order to keep the colors when the logs are written to stdout :D :)

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @marco-jantke .

Great PR!

I just have one remark to do :
I think it can be great to modify and/or add a test in the access_log_test.go file.

WDYT about this suggestion?

@m3co-code
Copy link
Contributor Author

@nmengin it's not about access logs :-) I could, of course, add an integration test for the traefik log itself, but I am not sure on what to assert.. What I could is pick some lines and verify that they are valid JSON, without looking into the contents. Do you think this would help?

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marco-jantke

Sorry for the misunderstood 😉

Do you think this would help?

IMHO, if there are tests, the code is easier to maintain. Even if, of course, these modifications are not about the main code part.

LGTM 🗞️

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be sure because we've touched the subject recently: does the handling of the deprecated vs. new configuration options work as expected?

Also, have we documented which version takes precedence?

@m3co-code
Copy link
Contributor Author

This is certainly a good point Timo. I tested with all the different constellations with CLI and toml configuration. The behaviour is consistent and as expected. Given the new configuration traefikLog.filePath is specified, it will always be used. Only in case it is not specified the deprecated option will be used.

I now added a warning about the usage of the deprecated and documented at the deprecated option documentation, that the new option takes precedence.

To summarise shortly:

traefik --traefiklogsfile=./deprecated_log --traefiklog --traefiklog.filepath=./new_log --traefiklog.format="json" will write to ./new_log in JSON format.

traefik --traefiklogsfile=./deprecated_log --traefiklog --traefiklog.format="json" will write to ./deprecated_log in JSON format.

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for double checking @marco-jantke. LGTM.

@traefiker traefiker merged commit 837db9a into traefik:master Sep 21, 2017
@m3co-code m3co-code deleted the traefik-logs-json branch September 21, 2017 08:42
@ldez ldez added the kind/enhancement a new or improved feature. label Oct 25, 2017
@ldez ldez changed the title add json format support for traefik logs Add json format support for traefik logs Nov 28, 2017
@ldez ldez changed the title Add json format support for traefik logs Add json format support for Traefik logs Nov 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/logs kind/enhancement a new or improved feature. size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to log in json format
6 participants