Question

I'm attempting to diagnose why my app is not finding it's settings file.
The settings are displayed on the bottom of the Django toolbar, but the traceback shows the error:

UndefinedError: 'settings' is undefined

I added the following to my code to get see why the settings weren't found because they are visable from the shell and on on the Python path.

import logging  
logging.debug("settings.LANGUAGE_CODE: " settings.LANGUAGE_CODE)  

Nothing showed up in the log file defined in the settings.py file.

Here is how the settings are defined:

LOG_FILENAME = 'askbot.log'
logging.basicConfig(
    filename=os.path.join(os.path.dirname(__file__), 'log', LOG_FILENAME),
    level=logging.CRITICAL,
    format='%(pathname)s TIME: %(asctime)s MSG: %(filename)s:%(funcName)s:%(lineno)d %(message)s',
)

I attempted to log a message directly from the shell:

>> import logging  
>> logging.debug("does this show up in log file") 

Nothing showed up in the log file.

I attempted to view the logging configuration via the shell.

>> logging.__dict__
>> logging.basicConfig.__dict__

LOG_FILENAME was never displayed.

How can I figure out why the logging messages are not being displayed in the LOG_FILENAME?
Can logging messages be sent from the shell to test the configuration?

Was it helpful?

Solution

Your logging is configured to log only critical messages. You might want to use logging.critical instead of logging.debug as a short term approach, or lower the level of messages to be logged, using level=logging.DEBUG in the configuration.

Also, logging.* methods use root-level logger. You might want to add granularity by providing more loggers in the configuration and using something like

logger = logging.getLogger(logger_name) #logger name is often just __name__
logger.debug(whatever)

Refer to logging documentation for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top