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

Switch to deactivate color output #51

Closed
buhtz opened this issue Oct 17, 2017 · 7 comments
Closed

Switch to deactivate color output #51

buhtz opened this issue Oct 17, 2017 · 7 comments

Comments

@buhtz
Copy link
Contributor

buhtz commented Oct 17, 2017

There should be a switch to deactivate the color output. Most of the time for debug purpose.

I use my code on Linux (bash) and Windwos10 (Thonny Pythton GUI). The latter is not able to handle the color codes and output all the escape characters. This is ugly.

I just want to deactivate the color-escape sequences but not the other settings (e.g. format).

@naggie
Copy link

naggie commented Oct 24, 2017

Have you tried colorlog.TTYColoredFormatter? This should disable the codes if not running inside a TTY.

@buhtz
Copy link
Contributor Author

buhtz commented Oct 24, 2017

Oh, I wasn't aware of that class. Great. Haven't tried it yet but I think this will fix the problem.

@buhtz buhtz closed this as completed Oct 24, 2017
@buhtz
Copy link
Contributor Author

buhtz commented Oct 25, 2017

It is not working with Thonny-IDE under Windows10. Looking at stackoverflow I can see there is no generalizable solution for that problem.

os.environ give some hints, too.

@buhtz buhtz reopened this Oct 25, 2017
@borntyping
Copy link
Owner

You're probably better off just configuring a different formatter on Windows machines, with something like the following:

import platform
import logging
import colorlog

handler = logging.StreamHandler()
if platform.system() == 'Windows':
     handler.setFormatter(colorlog.ColoredFormatter('%(log_color)s%(levelname)s:%(name)s:%(message)s'))
else:
     handler.setFormatter(logging.Formatter('%(levelname)s:%(name)s:%(message)s'))

logger = colorlog.getLogger('example')
logger.addHandler(handler)

@buhtz
Copy link
Contributor Author

buhtz commented Jan 5, 2018

It is a workaround but not a solution for this Issue. :)

@borntyping
Copy link
Owner

If you wanted to make a PR for this, I'd suggest looking at merging the functionality from TTYColoredFormatter into ColoredFormatter and adding a parameter that toggled it. The TTYColoredFormatter could then be simplified into a class that just sets that parameter.

@eblis
Copy link

eblis commented Mar 15, 2022

This issue doesn't mention this but now you can disable colors by setting the no_color flag to True.

I was about to create a MR but noticed that the functionality is already there :)

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

4 participants