Skip to content

Instantly share code, notes, and snippets.

@iKunalChhabra
Created October 5, 2022 12:28
Show Gist options
  • Save iKunalChhabra/f2ccf54e171547ab5bebd77fe67e25f0 to your computer and use it in GitHub Desktop.
Save iKunalChhabra/f2ccf54e171547ab5bebd77fe67e25f0 to your computer and use it in GitHub Desktop.
Print colored logs
from colorama import Fore, Back, Style
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logging.basicConfig(
format='%(asctime)s %(levelname)-8s %(message)s',
level=logging.INFO,
datefmt='%Y-%m-%d %H:%M:%S')
def warning(msg):
logger.warning(Fore.YELLOW + msg + Style.RESET_ALL)
def error(msg):
logger.error(Fore.RED + msg + Style.RESET_ALL)
def info(msg):
logger.info(Fore.GREEN + msg + Style.RESET_ALL)
def debug(msg):
logger.debug(Fore.CYAN + msg + Style.RESET_ALL)
def critical(msg):
logger.critical(Fore.MAGENTA + msg + Style.RESET_ALL)
def highlight(msg):
logger.info(Fore.BLACK + Back.YELLOW + msg + Style.RESET_ALL)
if __name__ == '__main__':
warning('This is a warning')
error('This is an error')
info('This is info')
debug('This is debug')
critical('This is critical')
highlight('This is highlighted info')
@iKunalChhabra
Copy link
Author

colored_logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment