Quick guide to Logging in different files using Python

This is for quick setup of a file logging system 

Step 1: importing the logging module.

import logging

Step 2: Create a logger for yourself. 

logger = logging.getLogger(__name__)

Step 3: Set Logger level


Step 4: Create a handler. 

hdlr = logging.FileHandler(settings.BASE_LOG_FILE, mode='w')

Step 5: Create a formatter

formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')

Step 6: Set formatter and handler

>>> hdlr.setFormatter(formatter)
>>> logger.addHandler(hdlr)

Popular posts from this blog

Why should you visit Kashmir sooner?

Rajasthan: The Best backpacking destination in India

CNTLM in Office