-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Structured logging #26632
Structured logging #26632
Conversation
remove a dead code file too
Inject hclog as the default logger in the main binary.
This is unused and leads to confusion
make sure plugins get hcloggers configured to match core
Use a single log writer instance for all std library logging. Setup the std log writer in the logging package, and remove boilerplate from test packages.
We want to always be using the hclogger to filter whenever possible
Codecov Report
|
😱 THIS IS AWESOME! I did notice that a warning got printed twice when I used BUT LOOK AT THE FILTERING ITS SO GOOD!!!
|
} | ||
|
||
if out == nil { | ||
out = ioutil.Discard | ||
if logPath := os.Getenv(EnvLogFile); logPath != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think I even knew this was an option, very nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! I was going to ask about documentation but (in case anyone else is wondering the same thing) we never documented that TRACE
was effectively the only option anyway: https://www.terraform.io/docs/internals/debugging.html
Yes, that message gets printed each time we check the level, but it will be removed or come from a new location (to indicate the situation only applies to certain providers) once the upstream changes are in place. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Take the first steps towards end-to-end structured logging in core. The primary goal of this PR is to remove the
LevelFilter
which attempted to filter log output based on theTF_LOG
setting, and use the capabilities ofhclog.Logger
directly. We do this by injecting a wrappedhclog.Logger
into the std lib log output, which can more correctly infer the log level as it gets the entire message as a single argument, rather thanLevelFilter
which can only guess or set a default level when encountering multiple unstructured and untagged lines.The global loggers are initialized in the
github.com/hashicorp/terraform/internal/logging
package. If proper filtering is needed by a package for testing using the std librarylog
package, importinggithub.com/hashicorp/terraform/internal/logging
is sufficient to setup the global logger with the requested level.If a package wishes to use
hclog
directly, a globalhclog.Logger
can be obtained via thelogging.HCLogger
function, or a new logger can be create withlogging.NewHCLogger
. This is used to setup the plugin clients for example, as they can accept anhclog.Logger
instance directly.There are still some upstream changes that will need to be made in
go-plugin
andterraform-plugin-sdk
in order to maintain structured end-to-end logging from providers, but these changes set us up in core to accept and filter the logs correctly.