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

Colorize output to terminal #4

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

merlin83
Copy link

@merlin83 merlin83 commented Oct 8, 2014

No description provided.

@coderanger
Copy link
Owner

This definitely needs to be conditional at am minimum. Most of my use of this project is in a 12-factor environment where the output is going to a log file and shouldn't have colors. At a minimum I would check that stdout is a TTY, and that has a TERM that probably supports color, and probably offer an env var or other config option to disable it.

@merlin83
Copy link
Author

merlin83 commented Oct 8, 2014

Agreed. I've added in a check to determine if we should used colorized output. I don't think it is possible to add it as a configuration option in supervisor for eventlisteners, so an env var might be the way to go.

@merlin83
Copy link
Author

merlin83 commented Oct 8, 2014

There are two general purposes where I use this tool.

  1. Output directly to terminal for monitoring
  2. A log in cases where the output is consumed by another application and then displayed to a terminal. E.g. tail or docker logs

Unfortunately, a single envvar will not suffice. In the latter, even though it does not output to a terminal or has a tty, we still want the colorized format. Thus, I have introduced two env variables "STDOUT_ALWAYS_ENABLE_COLOR_OUTPUT" and "STDOUT_DISABLE_COLOR_OUTPUT".


def supports_color():
"""
Taken from https://github.com/django/django/blob/master/django/core/management/color.py
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will require copyright attribution and a license statement for the copied code. Just something like "This code is copyright X and is used under the terms of the Y license".

@merlin83
Copy link
Author

merlin83 commented Oct 9, 2014

Updated with copyright attribution and license statement.

@coderanger
Copy link
Owner

Roger, I'm on a plane tomorrow but will try to look at this once I get back to real networking. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants