This is for setting up of a file logging system using Logging module
Step 1: Import the logging module.
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)
No comments:
Post a Comment