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

turning on color support for custom terminals #5

Open
ayinger1 opened this issue Jan 24, 2017 · 1 comment
Open

turning on color support for custom terminals #5

ayinger1 opened this issue Jan 24, 2017 · 1 comment

Comments

@ayinger1
Copy link

in the docs, it says if chromalog detects non-color supporting terminal, it will fall back on monochrome. but i have a custom terminal (written in java) where i would like to launch a python process (using chromalog) and have it continue to output ansi color codes, even though chromalog thinks the python process is running in non-ansi environment.

so, is there a way to turn off this auto-detecting ansi terminal behavior, so that it always logs with ansi codes?

(looking thru the code i see that in stream.py, function stream_has_color_support checks for color support:
getattr(stream, 'isatty', lambda: False)()

is there a simple way to initialize logging with a stream where the 'isatty' is set to True?)

@ayinger1
Copy link
Author

ayinger1 commented Feb 1, 2017

here is my current solution to this issue:

# proxy class to fool chromalog into thinking we are *always* isatty:
class PseudoTTY(object):
	def __init__(self, underlying):
		self.__underlying = underlying
	def __getattr__(self, name):
		return getattr(self.__underlying, name)
	def isatty(self):
		return True
# wrap PseudoTTY proxy around sys.stderr and use like so:
   chromalog.basicConfig(format=logformat, level=logging.INFO, stream=PseudoTTY(sys.stderr))

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

No branches or pull requests

1 participant