Here is a quick snippet of setting up logging, which is a very useful thing to have when writing Libraries.
Setting up logging
The docs for
module are overwhelming, so to break this down a little easier, I wanted to give you a quick start example so that you can be on your way.
If you're writing a library, do this:
import logging logger = logging.getLogger('mylibrary') logger.addHandler(logging.NullHandler()) def do_stuff(): ... logger.debug('doing stuff')
If you're writing an application, start your
main with this:
import logging logging.basicConfig()
As you run your Python script, logger will constantly show you all of the messages necessary for debugging your application. This helps with bugs, unseen issues that would otherwise be painful and a nuisance to troubleshoot and detect.