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
chore(log): Restructure and cleanup logging code #15234
Conversation
Download PR build artifacts for linux_amd64.tar.gz, darwin_arm64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
Took an initial pass at this today:
TODO
|
FYI I accidently hit submit on the previous comment too soon, but I have updated it. For the goshim test, I grabed https://github.com/ssoroka/rand and added some logging: diff --git plugins/inputs/rand/rand.go plugins/inputs/rand/rand.go
index b5f6847..b3cf571 100644
--- plugins/inputs/rand/rand.go
+++ plugins/inputs/rand/rand.go
@@ -54,6 +54,10 @@ func (r *RandomNumberGenerator) Description() string {
}
func (r *RandomNumberGenerator) Gather(a telegraf.Accumulator) error {
+ r.Log.Error("error message")
+ r.Log.Warn("warn message")
+ r.Log.Info("info message")
+ r.Log.Debug("debug message")
r.sendMetric(a)
return nil Build the plugin and used this config: [agent]
debug = true
omit_hostname = true
[[inputs.execd]]
command = ["/home/powersj/rand/rand", "--config", "/home/powersj/rand/plugin.conf"]
signal = "none"
[[outputs.file]] Which produced:
This is the same as what I see from master currently. |
Built and installed it as a service and still looks good. Thanks! |
@powersj can you confirm that the last log line is now present in the eventlog? |
I only saw the first message about loading the config file. |
Here is my updated config:
Then in an admin powershell: > .\telegraf.exe --service install --config .\config.toml
> net stat telegraf
The Telegraf Data Collector Service service is starting.
The Telegraf Data Collector Service service was started successfully.
This is what I see in the Event Viewer: I get the same with your branch or master. Executable By HandIf I run the executable by hand with that same config, now all the messages go to the event log: And this is the final message: Invalid ConfigIf I do the same with an invalid config, nothing new shows up in the event viewer and I get this message on the CLI:
We never even get to the event viewer. Error in outputIf I update the config like that in #14144 with: [agent]
debug = true
logtarget = "eventlog"
[[inputs.cpu]]
[[outputs.file]]
[[inputs.nvidia_smi]]
bin_path = "C:\\Windows\\System32\\nvidia-smi.exe" The last message is: As opposed to the expected: 2024-05-08T20:50:08Z E! [telegraf] Error running agent: could not initialize input inputs.nvidia_smi: nvidia-smi not found in "C:\\Windows\\System32\\nvidia-smi.exe" and not in PATH; please make sure nvidia-smi is installed and/or is in PATH fwiw I don't see the following debug message in the event viewer either:
Thoughts? |
Yes! |
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.
Looks great! Excited to see how this turns out
Summary
This PR moves all logging code into the
logger
package and simplifies the code. It also exposes all required functions in thetelegraf.Logger
interface to provide an abstraction for changing the underlying logging implementation. This is in preparation to provide more fine-grained logging as requested in #6584 or adding structured logging as requested in #8815.Checklist
Related issues
resolves #10212