Different behavior of python logging module when using mod_python
Question: We have a nasty problem where we see that the python logging module is
behaving differently when running with mod_python on our servers. When
executing the same code in the shell, or in django with the runserver command
or with mod_wsgi, the behavior is correct:

    
    
    import logging
    logger = logging.getLogger('site-errors')
    logging.debug('logger=%s' % (logger.__dict__))
    logging.debug('logger.parent=%s' % (logger.parent.__dict__))
    logger.error('some message that is not logged.')
    

We then the following logging:

> 2009-05-28 10:36:43,740,DEBUG,error_middleware.py:31,[logger={'name': 'site-
> errors', 'parent': <logging.RootLogger instance at 0x85f8aac>, 'handlers':
> [], 'level': 0, 'disabled': 0, 'manager': <logging.Manager instance at
> 0x85f8aec>, 'propagate': 1, 'filters': []}]
>
> 2009-05-28 10:36:43,740,DEBUG,error_middleware.py:32,[logger.parent={'name':
> 'root', 'parent': None, 'handlers': [<logging.StreamHandler instance at
> 0x8ec612c>, <logging.handlers.RotatingFileHandler instance at 0x8ec616c>],
> 'level': 10, 'disabled': 0, 'propagate': 1, 'filters': []}]

As one can see, no handlers or level is set for the child logger 'site-
errors'.

The logging configuration is done in the settings.py:

    
    
    MONITOR_LOGGING_CONFIG = ROOT + 'error_monitor_logging.conf'
    
    import logging
    import logging.config
    
    logging.config.fileConfig(MONITOR_LOGGING_CONFIG)
    
    if CONFIG == CONFIG_DEV:
       DB_LOGLEVEL = logging.INFO
    else:
       DB_LOGLEVEL = logging.WARNING
    

The second problem is that we also add a custom handler in the __init__.py
that resides that in the folder as error_middleware.py:

    
    
    import logging
    from django.conf import settings
    from db_log_handler import DBLogHandler
    
    handler = DBLogHandler()
    handler.setLevel(settings.DB_LOGLEVEL)
    logging.root.addHandler(handler)
    

The custom handler cannot be seen in the logging!

If someone has idea where the problem lies, please let us know! Don't
hesistate to ask for additonal information. That will certainly help to solve
the problem.


Answer: It may be better if you do not configure logging in `settings.py`.

We configure your logging in our root `urls.py`. This seems to work out
better. I haven't read enough Django source to know why, precisely, it's
better, but it's working out well for us. I would add custom handlers here,
also.

Also, look closely at [mod_wsgi](http://code.google.com/p/modwsgi/). It seems
to behave much better than mod_python.

