-
Notifications
You must be signed in to change notification settings - Fork 13
Getting a Debug Log
Bill Deitrick edited this page Mar 13, 2019
·
1 revision
Sometimes it's helpful to get a debug log from Pypco to get a better idea of what's going on behind the scenes. Pypco uses the logging module from the standard Python library. This means that, if your application is already using the logging module from the standard library, you can simply adjust your code or logging config to make sure you're seeing debut messages from Pypco.
If you're not using the logging module in your application, you can use the following code to quickly enable logging and spit out a debug log for pypco in a "logs" folder of your current working directory (make sure you've created the "logs" sub directory first).
import logging
import logging.handlers
import os
log_dir = './logs'
# Build logger
log = logging.getLogger('pypco')
log.setLevel(logging.DEBUG)
# Build file handler
file_handler = logging.handlers.RotatingFileHandler(
"{}{}{}".format(log_dir, os.sep, "pypco.log"),
maxBytes=50000,
backupCount=10
)
file_handler.setLevel(logging.DEBUG)
# Build formatter
formatter = logging.Formatter(
'%(levelname)8s %(asctime)s [%(module)s|%(lineno)d] %(message)s'
)
file_handler.setFormatter(formatter)
# Add file handler to logger
log.addHandler(file_handler)