0

I'm wondering what the simplest way to enable debugging/verbose mode outputs in a project that involves multiple classes/files. The answer given here: Easier way to enable verbose logging works well in a single script but what might be the best implementation across multiple classes?

I've thought to use the Singleton design pattern to set a single instance of a "Debugger" which will have a Debugger.log("message"). Is there a better way to accomplish this?

Community
  • 1
  • 1
Matt Stokes
  • 4,618
  • 9
  • 33
  • 56

1 Answers1

1

This already exists. this is logging.root which is a logging.Logger instance. You just need to set it up before using it. A simple example:

>>> import logging
>>>
>>> logging.root.setLevel('INFO')
>>> logging.root.info('Info message')
INFO:root:Info message

The logging functions for the root logger are also available from the logging module directly:

>>> logging.info('Info message')
INFO:root:Info message

For a full reference on how to setup a logger see the official python documentation.

Remco Haszing
  • 7,178
  • 4
  • 40
  • 83