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

Simpler color syntax #69

Closed
ghost opened this issue May 18, 2019 · 2 comments
Closed

Simpler color syntax #69

ghost opened this issue May 18, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented May 18, 2019

It seems this is the simplest for color output:

import colorlog, logging
q = logging.StreamHandler()
q.setFormatter(colorlog.ColoredFormatter(
   "%(log_color)s%(levelname)s%(reset)s %(message)s",
   log_colors = {'INFO': 'green', 'WARNING': 'yellow', 'ERROR': 'red'}
))
z = logging.getLogger()
z.addHandler(q)
z.warning('abcde')

https://github.com/borntyping/python-colorlog/blob/master/doc/example.py

other projects have simpler syntax:

from logzero import logger
logger.warning('abcde')
@borntyping
Copy link
Owner

borntyping commented May 18, 2019

Using logging or colorlog, you can do the following:

import colorlog
colorlog.basicConfig()
colorlog.warning("abcde")
import logging
logging.basicConfig()
logging.warning("abcde")

Like you can with logging, importing the library and calling logging methods should have the same effect:

import colorlog
colorlog.warning("abcde")

(See colorlog/logging.py)

@ghost
Copy link
Author

ghost commented May 18, 2019

@borntyping that is perfect! thanks

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