Skip to content
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

how to prevent logging with color? #941

Closed
nhooyr opened this Issue Mar 6, 2019 · 6 comments

Comments

3 participants
@nhooyr
Copy link

nhooyr commented Mar 6, 2019

Don't want colored logs for the agent on GKE as the logs go to stackdriver and you see the raw escape codes everywhere.

screen shot 2019-03-05 at 8 12 09 pm

@lox

This comment has been minimized.

Copy link
Contributor

lox commented Mar 6, 2019

Did you check our docs? There is a no-color option.

@lox lox closed this Mar 6, 2019

@nhooyr

This comment has been minimized.

Copy link
Author

nhooyr commented Mar 6, 2019

I did, must have missed it.

Why not automatically enable color based on whether stderr is a tty or not?

@lox

This comment has been minimized.

Copy link
Contributor

lox commented Mar 6, 2019

All good! Apologies for terse reply.

Why not automatically enable color based on whether stderr is a tty or not?

Good question, seems like a good idea! Things get a bit complicated with tty support cross-platform, but we could probably do that for linux/mac.

@keithpitt

This comment has been minimized.

Copy link
Member

keithpitt commented Mar 6, 2019

Why not automatically enable color based on whether stderr is a tty or not?

We do!

agent/logger/log.go

Lines 51 to 63 in 6f4f790

func ColorsAvailable() bool {
// Color support for windows is set in init
if runtime.GOOS == "windows" && !windowsColors {
return false
}
// Colors can only be shown if STDOUT is a terminal
if terminal.IsTerminal(int(os.Stdout.Fd())) {
return true
}
return false
}

buildkite-agent start --config .buildkite-agent.cfg &> no-color.log

I looked at the output in no-color.log and it didn't have any colours. Where as if I run buildkite-agent start in a terminal, I get colours.

Sounds like maybe the thing on your end @nhooyr is reporting itself as a TTY. As far as the agent is concerned, I think it's doing the right thing!

@nhooyr

This comment has been minimized.

Copy link
Author

nhooyr commented Mar 11, 2019

Interesting. Thanks for looking into this for me.

@nhooyr

This comment has been minimized.

Copy link
Author

nhooyr commented Mar 11, 2019

Ah, kubernetes runs each app with a TTY so that when you run kubectl logs mypod in a terminal, you can see colors.

I guess that does make sense. Unfortunate with Stackdriver though, I think I'll file an issue with them to remove the escape codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.