Skip to content

textlogger: optionally turn off header#430

Merged
k8s-ci-robot merged 1 commit intokubernetes:mainfrom
pohly:textlogger-optional-header
Feb 24, 2026
Merged

textlogger: optionally turn off header#430
k8s-ci-robot merged 1 commit intokubernetes:mainfrom
pohly:textlogger-optional-header

Conversation

@pohly
Copy link
Copy Markdown

@pohly pohly commented Dec 1, 2025

What this PR does / why we need it:

Turning off the header is useful for converting structured log parameters (e.g. error + message + key/value pairs from the Kubernetes ErrorHandler API) into a single string.

See

Which issue(s) this PR fixes:
Fixes #429

Special notes for your reviewer:

Needed for https://github.com/kubernetes/kubernetes/pull/135419/files#r2576981852

Release note:

textlogger: WithHeader option enables suppression of the header.

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 1, 2025
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 1, 2025
@pohly
Copy link
Copy Markdown
Author

pohly commented Dec 1, 2025

/assign @harshanarayana

@dgrisonnet
Copy link
Copy Markdown
Member

/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Dec 12, 2025
@tallclair
Copy link
Copy Markdown
Member

/assign

Copy link
Copy Markdown

@nojnhuh nojnhuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

Left a couple non-blocking comments.
/hold In case you want to make any changes here still.

Comment thread textlogger/textlogger.go Outdated
Comment on lines 95 to 96
// Determine caller.
// +1 for this frame, +1 for Info/Error.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should we keep this comment immediately above l.callDepth + 2?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fixed.

)
logger := textlogger.NewLogger(config)

logger.Error(errors.New("fake error"), "Something broke", "id", 42)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth also checking that these other methods don't somehow lose the withHeader? Maybe in a separate test if this is too busy for an example?

logger.WithName("name").WithValues("key", "value").WithCallDepth(0).Info("Still no header")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more lines seem fine.

While looking at this again I started wondering why I was redirecting to a buffer - no good reason, so now I am using os.Stdout directly, which saves some lines again.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's because WithHeader was meant to be used in combination with buffer as a general-purpose "structured" -> "string" converter.

I've added a comment to the docs and kept the example with bytes.Buffer.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 23, 2026
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 23, 2026
This is useful for converting structured log parameters (e.g. error + message +
key/value pairs from the Kubernetes ErrorHandler API) into a single string.
@pohly pohly force-pushed the textlogger-optional-header branch from 1d414ff to 36bc4ff Compare February 24, 2026 11:15
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 24, 2026
Copy link
Copy Markdown

@nojnhuh nojnhuh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/hold cancel

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Feb 24, 2026
@k8s-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: nojnhuh, pohly

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

textlogger: optional header

6 participants