Mergifyio / daiquiri

Python library to easily setup basic logging functionality
Apache License 2.0
333 stars 25 forks source link

Uses no color in Jupyter (may need to force TTY) #28

Open Gerenuk opened 6 years ago

Gerenuk commented 6 years ago

Daiquiri would also be great to use in Jupyter. Unfortunately, it seems in Jupyter one usually has to enforce TTY mode in order to make color work.

There does not seem to be an option for that in daiquiri?

jd commented 6 years ago

I never tried. Do you have some links or code sample you can share that can help understanding the issue and how to solve it?

Gerenuk commented 6 years ago

I'm using the standard

import logging import daiquiri daiquiri.setup(level=logging.INFO, outputs=[daiquiri.output.STDOUT]) logger = daiquiri.getLogger(name) logger.info("It works and log to stderr by default with color!")

in Jupyter notebook. The STDOUT is needed since Jupyter uses a red background for stderr. It works correctly in consoles, but uses no color in Jupyter.

I noticed in some other terminal color libraries that enforcing TTY is important. For example

import coloredlogs, logging, sys logger = logging.getLogger(name) coloredlogs.install(level='DEBUG', stream=sys.stdout, isatty=True)

That isatty is key to really have colors in Jupyter. Somehow Jupyter does not identify itself as a proper TTY. Not sure what that means though.