I am using python's logging
module in a django project. I am performing the basic logging configuration in my settings.py
file. Something like this:
import logging
import logging.handlers
logger = logging.getLogger('project_logger')
logger.setLevel(logging.INFO)
LOG_FILENAME = '/path/to/log/file/in/development/environment'
handler = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, when = 'midnight')
formatter = logging.Formatter(LOG_MSG_FORMAT)
handler.setFormatter(formatter)
logger.addHandler(handler)
I have a separate settings file for production. This file (production.py
) imports everything from settings
and overrides some of the options (set DEBUG
to False
, for instance). I wish to use a different LOG_FILENAME
for production. How should I go about it? I can repeat the entire configuration section in production.py
but that creates problems if /path/to/log/file/in/development/environment
is not present in the production machine. Besides it doesn't look too "DRY".
Can anyone suggest a better way to go about this?