-
Notifications
You must be signed in to change notification settings - Fork 315
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
hab-sup --no-color doesn't strip color from all output #997
Comments
Is this color from the argument parser, or elsewhere? Because if it's from the argument parser, there's a slightly hacky workaround that you can use. Keep in mind that I haven't dug through the What you can do is have your code that builds the CLI (but doesn't call There are two ways to do this, option A is to check for the Option A (preferred)
A very simplified version looks like this: fn cli() -> App<'static, 'static> {
let mut app = App::new("test")
.arg(Arg::with_name("nocolor")
.short("n")
.long("no-color")
.help("Disables color"));
app = if env::args().any(|arg| arg == "--no-color") {
app.setting(AppSettings::ColorNever)
} else {
app
};
app
}
fn main() {
let matches = cli().get_matches();
// All else like normal...
} Option B
fn cli() -> App<'static, 'static> {
App::new("test")
.arg(Arg::with_name("nocolor")
.short("n")
.long("no-color")
.help("Disables color"))
}
fn main() {
let res = cli().get_matches_safe();
let matches = if env::args().any(|arg| arg == "--no-color") {
cli().setting(AppSettings::ColorNever).get_matches()
} else {
res.unwrap_or_else(|e| e.exit())
};
// All else like normal...
} Notice we actually leave the In Option B, we have to change the call for Hope this helps some! |
Another update: this is certainly not a workaround as it appears the above PR actually just implements the --no-color option as an env var |
It looks like this does not work at all in the supervisor: You get the same result with I'd say the correct behavior should be that the output from the supervisor ( |
While not a fix, I have identified a workaround for syslog messages so that the message output is preserved and control characters are not mutated. My workaround however is probably platform specific, and assumes the system syslog daemon is rsyslog. /etc/rsyslog.d/10-habitat:
The rsyslog config assumes your init method prepends the log lines with the application identifier of
You will probably want to make a logrotate file if you use this:
|
OK I've been doing a bit hacking round with this for an internal usecase we have. I've got the colour turned off for the most part - but the problem comes when people Three options I can see:
|
At the risk of discussing this with myself, I think option 1 is best. I also implemented JSON output and even if the service creates coloured logs you don't really want that in JSON. I'll write a regex function which strips the controls and then all the paint option can be left as is im the code. Unless someone else has some thoughts? |
This also seems to be an issue for a systemd-managed Supervisor when we set It really seems to me that colorless output should be the default behavior, with colored output being available via some environment variable that a user can set in their local dev environment. cc: @mspringfeldt |
--no-color
cli arg parsing was fixed in #996, but not all text is stripped of color.The text was updated successfully, but these errors were encountered: