-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: FTL_LOG_COLOR env to override tty detection #1508
Conversation
internal/log/plain.go
Outdated
@@ -21,7 +21,9 @@ var _ Sink = (*plainSink)(nil) | |||
|
|||
func newPlainSink(w io.Writer, logTime bool) *plainSink { | |||
var isaTTY bool | |||
if f, ok := w.(*os.File); ok { | |||
if os.Getenv("FTL_LOG_COLOR") != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this a Kong flag in log.Config
, and pass it down into this function to avoid global state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented this, but my main reason for this feature is in running tests and it now doesn't work with tests because ContextWithNewDefaultLogger
doesn't go through log.Config
. I did make a env check in there which is only checked when running tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍
Good idea BTW! |
be01cce
to
2fef0b4
Compare
1f17bde
to
238c08d
Compare
@@ -66,5 +66,7 @@ func ContextWithLogger(ctx context.Context, logger *Logger) context.Context { | |||
} | |||
|
|||
func ContextWithNewDefaultLogger(ctx context.Context) context.Context { | |||
return ContextWithLogger(ctx, Configure(os.Stderr, Config{Level: Debug})) | |||
// Matches LOG_COLOR in log.Config. This is a special case for the default logger in testing. | |||
color := os.Getenv("LOG_COLOR") != "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
LOG_COLOR=1 LOG_LEVEL=trace go test -v ./buildengine -run TestEngine
238c08d
to
f98e769
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing
LOG_COLOR env to override tty detection
eg
LOG_COLOR=1 LOG_LEVEL=trace go test -v ./buildengine -run TestEngine