Logger Configuration for Python Projects
20:41 01 Dec 2025

I am wondering how I am supposed to setup a logger for python projects.

It makes sense that I can setup a logger for the main file in a project Example:

# main.py
logger = logging.getLogger('spam_application')
logger.setLevel(logging.DEBUG)

fh = logging.FileHandler('spam.log')
fh.setLevel(logging.DEBUG)

logger.addHandler(fh)

I noticed this does not apply to logs when I run a module. Is there a way to make the formatting apply when i do python -m my_pckg.foo

python logging