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

isatty should force usage of the colored formatter #95

Closed
wants to merge 2 commits into from
Closed

isatty should force usage of the colored formatter #95

wants to merge 2 commits into from

Conversation

bitranox
Copy link

some terminals (like travis and jupyter) can not have colored output, because the terminal is checked again with humanfriendly.terminal_supports_colors(stream)

this leads to no coloured output on travis and jupyter.

the 'isatty' keyword is triadic :

isatty = None  # autodetect if we can use color
isatty = False  # dont  use color

at the Moment You treat isatty = True the same way like it would be None - but isatty=True should force the use of the ColoredFormatter !

If You dont like it for a reason, You also can put a new keyword like force_color but from my point of view it should not be neccessary.

However, with that patch the colored output is possible now for Jupyter (on stdout) and Travis (on stderr) !

please consider it, until then I need to host my own fork on pypi to get the wheels ....

yours sincerely

Robert

@coveralls
Copy link

coveralls commented Jul 17, 2020

Coverage Status

Coverage increased (+0.4%) to 91.909% when pulling 26eceb3 on bitranox:master into 3935774 on xolox:master.

@bitranox
Copy link
Author

Dear Peter,
I quickly forked it, since I need it urgently.

here the link to a binder on jupyter what shows the issue nicely :

https://mybinder.org/v2/gh/bitranox/bitranox_coloredlogs/master?filepath=bitranox_coloredlogs.ipynb

@bitranox bitranox mentioned this pull request Aug 9, 2020
@xolox
Copy link
Owner

xolox commented Dec 10, 2020

Thanks for the feedback and sorry for the messy behavior. As mentioned in #92:

This (bad) experience was never intended, the override was always intended to bypass any auto detection check. Today I published coloredlogs release 14.1 which fixes the override to bypass the auto detection check (as well as the bug that confused stdout versus stderr).

I hope the new release resolves the issues (and downright confusing behavior) that have been reported.

@xolox xolox closed this Dec 10, 2020
@joooeey
Copy link

joooeey commented Jun 7, 2021

When running the binder linked above, I can see that this has been resolved. However I haven't managed to get it to work in Jupyter. I'm using coloredlogs 15.0.

@joooeey
Copy link

joooeey commented Jun 7, 2021

I solved it now. It's important to set isatty=True and if you don't want the red background you also have to set stream=sys.stdout

@thoughtfuldata
Copy link

@joooeey where do you set isatty=True?

@joooeey
Copy link

joooeey commented Nov 23, 2021

@thoughtfuldata when you call coloredlogs.install. I.e.

import coloredlogs, logging
coloredlogs.install(level='DEBUG', isatty=True)
logger = logging.getLogger('some.module.name')
logger.info("this is an informational message")

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.

None yet

5 participants