Quick guide to Logging in different files using Python

This is for quick setup of a logging system . 


Step 1: import logging 


Logging is the build-in module for implementing logging in Python.

Step 2: Create a logger for yourself. 


logger = logging.getLogger(__name__)

Step 3: Set Logger level


logger.setLevel(logging.DEBUG)

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)



Total Pageviews