fix(agent): Make sure the log-file directory exists#18818
fix(agent): Make sure the log-file directory exists#18818srebhan wants to merge 1 commit intoinfluxdata:masterfrom
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 |
| add("structured", func(cfg *Config) (sink, error) { | ||
| var writer io.Writer = os.Stderr | ||
| if cfg.Logfile != "" { | ||
| // Make sure the directory for the log-file exists |
There was a problem hiding this comment.
Could you add a small test in logger/text_logger_test.go and logger/structured_logger_test.go that points Logfile at filepath.Join(t.TempDir(), "subdir", "test.log") to lock in the new behavior? The existing tests already use t.TempDir() so it's a one-liner per file.
| func createTextLogger(cfg *Config) (sink, error) { | ||
| var writer io.Writer = os.Stderr | ||
| if cfg.Logfile != "" { | ||
| // Make sure the directory for the log-file exists |
There was a problem hiding this comment.
Optional: the four-line os.MkdirAll(...) block is identical in both sinks, small helper (e.g. ensureLogDir) in logger/registry.go would avoid duplication if a third sink is ever added.
Summary
This PR creates the log-file directory if necessary to ensure it exists.
Checklist
Related issues
resolves #16186