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

Fix parsing of log-levels by removing date/time prefix #440

Merged
merged 1 commit into from
Jul 8, 2021
Merged

Fix parsing of log-levels by removing date/time prefix #440

merged 1 commit into from
Jul 8, 2021

Conversation

bengesoff
Copy link
Contributor

The TF_LOG and TF_LOG_PROVIDER environment variables should be able to filter the provider logs based on the log level (DEBUG, INFO, WARN, ERROR etc). However, the default logger in the log package prepends the date and time to each log line. This breaks the parsing of the logs in Terraform core, as it expects each line to start with the log level in square brackets. Instead, it finds the date and defaults every line to INFO regardless of the intended severity. An example of how this line is outputed is as follows:

2021-07-08T10:41:00.615+0100 [INFO]  provider.terraform-provider-fastly_v0.32.0-5-gba6a3dbd: 2021/07/08 10:41:00 [DEBUG] Refreshing WAFs for (1F5jhDFJKHKhdfjDF0On28Pj7): timestamp=2021-07-08T10:41:00.615+0100

Here you can see that we intended to log as a DEBUG level, but it ended up coming out as INFO. The timestamp is also duplicated everywhere.

To fix this, the default logger can be configured to skip prepending the timestamp using log.SetFlags(0). With this change, the log line now becomes:

2021-07-08T10:48:23.189+0100 [DEBUG] provider.terraform-provider-fastly_v0.32.0-6-g6e80f288: Refreshing WAFs for (1F5jhDFJKHKhdfjDF0On28Pj7): timestamp=2021-07-08T10:48:23.189+0100

Setting the TF_LOG environment variable to INFO also means that this line prevented from being outputted. This should help to filter the logs better in some situations.

@Integralist Integralist added the bug label Jul 8, 2021
@Integralist Integralist merged commit c07e33c into fastly:main Jul 8, 2021
@bengesoff bengesoff deleted the fix-log-levels branch July 8, 2021 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants