Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 287133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:41:55+00:00 2026-05-12T05:41:55+00:00

I am using python’s logging module in a django project. I am performing the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:41:55+00:00Added an answer on May 12, 2026 at 5:41 am

    Found a reasonably “DRY” solution that worked. Thanks to Python logging in Django

    I now have a log.py which looks something like this:

    import logging, logging.handlers
    from django.conf import settings
    
    LOGGING_INITIATED = False
    LOGGER_NAME = 'project_logger'
    
    def init_logging():
        logger = logging.getLogger(LOGGER_NAME)
        logger.setLevel(logging.INFO)
        handler = logging.handlers.TimedRotatingFileHandler(settings.LOG_FILENAME, when = 'midnight')
        formatter = logging.Formatter(LOG_MSG_FORMAT)
        handler.setFormatter(formatter)
        logger.addHandler(handler)
    
    if not LOGGING_INITIATED:
        LOGGING_INITIATED = True
        init_logging()
    

    My settings.py now contains

    LOG_FILENAME = '/path/to/log/file/in/development/environment
    

    and production.py contains:

    from settings import *
    LOG_FILENAME = '/path/to/log/file/in/production/environment'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 162k
  • Answers 162k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's some pretty basic reasons. (1) If a query (insert,… May 12, 2026 at 11:55 am
  • Editorial Team
    Editorial Team added an answer If you only expect there to be a single PrimaryCategory… May 12, 2026 at 11:55 am
  • Editorial Team
    Editorial Team added an answer Lee Holmes (one of the senior developers on the powershell… May 12, 2026 at 11:55 am

Related Questions

I am using python 2.6 on XP. I have just installed py2exe, and I
I am using Python to read in data in a user-unfriendly format and transform
I am using python-ldap to try to authenticate against an existing Active Directory, and
I am using Python 2.5.2. How can I tell whether it is CPython or
I am using Python with psycopg2 and I'm trying to run a full VACUUM

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.