Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

logging python color

import logging

class CustomFormatter(logging.Formatter):

    grey = "x1b[38;20m"
    yellow = "x1b[33;20m"
    red = "x1b[31;20m"
    bold_red = "x1b[31;1m"
    reset = "x1b[0m"
    format = "%(asctime)s - %(name)s - %(levelname)s - %(message)s (%(filename)s:%(lineno)d)"

    FORMATS = {
        logging.DEBUG: grey + format + reset,
        logging.INFO: grey + format + reset,
        logging.WARNING: yellow + format + reset,
        logging.ERROR: red + format + reset,
        logging.CRITICAL: bold_red + format + reset
    }

    def format(self, record):
        log_fmt = self.FORMATS.get(record.levelno)
        formatter = logging.Formatter(log_fmt)
        return formatter.format(record)
      
# create logger with 'spam_application'
logger = logging.getLogger("My_app")
logger.setLevel(logging.DEBUG)

# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

ch.setFormatter(CustomFormatter())

logger.addHandler(ch)
Comment

color logging python

pip install colorlog
Comment

PREVIOUS NEXT
Code Example
Shell :: how to create a github tag 
Shell :: rmdir directory not empty windows 
Shell :: composer change version 
Shell :: command to check pip3 version on linux 
Shell :: link folder to github repo 
Shell :: allow ping using cmd 
Shell :: starting apache2 server 
Shell :: show conflicts git 
Shell :: install scala using brew 
Shell :: react route install 
Shell :: linux signals 
Shell :: d3 install 
Shell :: how to list all the available versionb for installation ubuntu 
Shell :: next js npm install 
Shell :: how to set default editor in git 
Shell :: where is tomcat installed on mac 
Shell :: grep search text in folder 
Shell :: kubectl top pod 
Shell :: open calculator from command line MacOS 
Shell :: run jar file on the background on ubuntu 
Shell :: linux auto suspensd stop 
Shell :: E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root? 
Shell :: Delete all running and stopped containers 
Shell :: ls with file size 
Shell :: how to kill a process with linux 
Shell :: Can I deploy a branch in netlify 
Shell :: installing a downloaded package in ubuntu 
Shell :: how to run debian on docker 
Shell :: how do i make a gif from youtube 
Shell :: cmake set build type from command line 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =