Only include ANSI color output if a user is logging to a terminal#4
Merged
Only include ANSI color output if a user is logging to a terminal#4
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds conditional ANSI color output to the console logger, enabling colored output only when logging directly to a terminal and disabling colors when output is redirected or piped. This improves compatibility with log aggregation tools and file redirection scenarios.
- Added terminal detection using
golang.org/x/term.IsTerminal()to conditionally enable/disable ANSI colors - Updated dependencies to include
golang.org/x/termpackage - Added comprehensive test script and sample program to verify color behavior in different output scenarios
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| log.go | Implements terminal detection to conditionally disable ANSI colors in ConsoleWriter based on stdout file descriptor type |
| go.mod | Updates Go version and adds golang.org/x/term dependency along with updated golang.org/x/sys version |
| go.sum | Adds checksums for new golang.org/x/term and updated golang.org/x/sys dependencies |
| cmd/testlog/main.go | Adds test program demonstrating various logging methods for manual verification |
| cmd/testlog/test.sh | Adds shell script to test color output behavior in different scenarios (terminal, piped, redirected, JSON mode) |
💡 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.
No description provided.