Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

setup logger python

# Logger setup in python
def get_logger(self) -> logging.RootLogger:
    """instance of logger module, will be used for logging operations"""
    
    # logger config
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.DEBUG)

    # log format
    lg_format = "%(levelname)s|%(filename)s:%(lineno)d|%(asctime)s|%(message)s"
    log_format = logging.Formatter(lg_format)

    # file handler
    file_handler = logging.FileHandler("log/monitor_model.log")
    file_handler.setFormatter(log_format)

    logger.handlers.clear()
    logger.addHandler(file_handler)
    return logger
Comment

logger levels python

# Note: Only levels on or above the current chosen level are outputted

Logging Levels  -> Numeric Value

CRITICAL -> 50
ERROR -> 40
WARNING -> 30
INFO -> 20
DEBUG -> 10
NOTSET -> 0
Comment

python log file

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
Comment

python logger format

FORMAT = '%(asctime)s %(clientip)-15s %(user)-8s %(message)s'
logging.basicConfig(format=FORMAT)
d = {'clientip': '192.168.0.1', 'user': 'fbloggs'}
logger = logging.getLogger('tcpserver')
logger.warning('Protocol problem: %s', 'connection reset', extra=d)
Comment

python fme logger

logger = fmeobjects.FMELogFile()
logger.logMessageString("{}".format('Error'), fmeobjects.FME_ERROR)
Comment

PREVIOUS NEXT
Code Example
Python :: numpy split 
Python :: formatting strings in python 
Python :: python string: .replace() 
Python :: how to read frame width of video in cv2 
Python :: np.vstack python 
Python :: python bot 
Python :: python selenium print xpath of element 
Python :: how to send a command to cmd using python 
Python :: how to read a excel file in python 
Python :: if we use list in the dictionary 
Python :: Fill in the empty function so that it returns the sum of all the divisors of a number, without including it. A divisor is a number that divides into another without a remainder. 
Python :: python list max value 
Python :: mapping in python 
Python :: Issue AttributeError: ‘numpy.ndarray’ object has no attribute ‘index’ 
Python :: add key value in each dictonary in the list 
Python :: what does tuple mean in python 
Python :: python elif 
Python :: how to join two tuples in python 
Python :: best python programs 
Python :: Python match.re and match.string 
Python :: python update dict if key not exist 
Python :: python palindrome program 
Python :: python rabbitmq 
Python :: diccionario python 
Python :: python 3.4 release date 
Python :: how to make window pygame 
Python :: remove timezone from column pandas 
Python :: propositional logic python 
Python :: inverse matrix gauss python 
Python :: how to make hidden folders python 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =