log: align pterm prefix-printer badge widths#5
Merged
Conversation
The console logger's own level tags already render at a uniform 5 columns via pterm's %-5s, but pterm's global PrefixPrinter singletons (pterm.Info/Warning/Error/... that a consumer prints directly) ship at mixed widths: INFO is a 4-wide cyan block while WARNING/SUCCESS/ERROR/ FATAL/DEBUG are 7. Their background-colored badges stagger. Normalize them to one width, centered, set once alongside the existing pterm-global color config in consoleHandler. pterm's printers are process-global singletons, so this holds for every consumer that calls Logger() with no extra action on their part -- the same fleet-wide consistency side effect the package already applies to color. The pass is idempotent, so repeated Logger() calls don't drift the width.
There was a problem hiding this comment.
Pull request overview
This PR normalizes the visual width/labeling of pterm’s process-global PrefixPrinter badges (pterm.Info, pterm.Warning, etc.) so consumer-facing badge blocks align consistently when using the signals console logger.
Changes:
- Add
alignPrefixBadges()(withcenterPad) and call it fromconsoleHandlerto normalize pterm global badge labels/widths. - Add
TestBadgesas a manual/visual exercise for the aligned prefix printers plus a background-color palette preview. - Add a
badgessubcommand to./bin/testto run the new badge print test with forced color.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pretty_test.go | Adds TestBadges to print/inspect aligned pterm prefix-printer badges and a palette sample. |
| log.go | Normalizes pterm global prefix-printer badge texts via alignPrefixBadges() and a centerPad helper. |
| bin/test | Adds a badges command to run TestBadges with CLICOLOR_FORCE=1. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The console logger's own level tags already render at a uniform 5 columns (pterm's
%-5s), but pterm's globalPrefixPrintersingletons —pterm.Info,pterm.Warning,pterm.Error, etc., which a consumer prints directly — ship at mixed widths:INFOis a 4-wide cyan block whileWARNING/SUCCESS/ERROR/FATAL/DEBUGare 7. Their background-colored badges stagger.This normalizes the set to one width (7), centered:
Only
INFOactually changes; every other badge is already 7.How
alignPrefixBadges()(plus acenterPadhelper) runs once inconsoleHandler, alongside the existing pterm-global color config. pterm's printers are process-global singletons, so this reaches every consumer that callsLogger()— no extra action on their part, the same fleet-wide side effect the package already applies to color. The pass is idempotent, so repeatedLogger()calls don't drift the width.