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

ansi char stripping does not work in logging #372

Open
fopina opened this issue Feb 23, 2023 · 0 comments
Open

ansi char stripping does not work in logging #372

fopina opened this issue Feb 23, 2023 · 0 comments

Comments

@fopina
Copy link

fopina commented Feb 23, 2023

Using init(strip=True) to disable colors works for print statements, such as:

>>> from colorama import init, Fore
>>> print(f'{Fore.RED}test{Fore.RESET}')
test (COLORED)
>>> init(strip=True)
>>> print(f'{Fore.RED}test{Fore.RESET}')
test (NO COLOR)

But it does not for logging statements

>>> from colorama import init, Fore
>>> init(strip=True)
>>> import logging
>>> logging.error(f'{Fore.RED}oi{Fore.RESET}')
ERROR:root:oi (STILL COLORED)

I'm currently using this workaround in my CLI main/parser entrypoint:

        # FIXME: colorama strip fails in logging...!
        # monkeypatch Fore
        class FakeFore:
            def __getattribute__(self, __name: str):
                return ''

        Fore.__class__ = FakeFore

But it would be nice to have stripping actually working...

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