Skip to content

feat: expose --log_file flag to customize the log destination - #679

Open
PratikDhanave wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
PratikDhanave:feat/configurable-log-file
Open

feat: expose --log_file flag to customize the log destination#679
PratikDhanave wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
PratikDhanave:feat/configurable-log-file

Conversation

@PratikDhanave

Copy link
Copy Markdown

What

Exposes the klog log_file flag so users can customize where kubectl-ai writes its log, instead of it always being <tmpdir>/kubectl-ai.log.

Why

Fixes #428. The log destination was hard-set in cmd/main.go:

klogFlags.Set("log_file", filepath.Join(os.TempDir(), "kubectl-ai.log"))

…but the log_file flag was never added to the command, so there was no way to change it. v and alsologtostderr are already surfaced the same way; this just adds log_file alongside them.

Change

rootCmd.PersistentFlags().AddGoFlag(klogFlags.Lookup("log_file"))
  • Default is unchanged (<tmpdir>/kubectl-ai.log).
  • Users can now set --log_file=/path/to/kubectl-ai.log, or --log_file=/dev/null to disable file logging (as the issue requests).

Testing

go build ./... and go vet ./... pass. kubectl-ai --help now lists:

--log_file string   If non-empty, use this log file ... (default ".../kubectl-ai.log")

The klog log_file was hard-set to <tmpdir>/kubectl-ai.log and never surfaced to
users. Expose it as a persistent flag (the same way `v` and `alsologtostderr`
are already exposed) so the log path is configurable; the default is unchanged,
and `--log_file=/dev/null` disables file logging.

Fixes GoogleCloudPlatform#428
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Supports customizing the log_filepath

1 participant