Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Django logging skips log entries?

Tags:

This is my settings module:

LOGGING = {   'version': 1,   'disable_existing_loggers': False,   'handlers': {     'file': {         'level': 'DEBUG',         'class': 'logging.FileHandler',         'filename': '/django-python/django/testapp/testapp.log',     },   },   'loggers': {     'django': {         'handlers': ['file'],         'level': 'DEBUG',         'propagate': True,     },   }, } 

and this is my code in a view file:

import logging logger = logging.getLogger(__name__) logger.info("this is an error message!!") 

I am getting the previous logs from various modules but not the above log entry "this is an error message".

like image 451
Teja Reddy Avatar asked Apr 12 '16 10:04

Teja Reddy


People also ask

How do I keep my Django log in?

Configuring logging. Python's logging library provides several techniques to configure logging, ranging from a programmatic interface to configuration files. By default, Django uses the dictConfig format. In order to configure logging, you use LOGGING to define a dictionary of logging settings.

How do you disable verbose error handling and logging in Django?

If you don't want to configure logging at all (or you want to manually configure logging using your own approach), you can set LOGGING_CONFIG to None . This will disable the configuration process for Django's default logging.

Is logging blocking in Python?

Sometimes you have to get your logging handlers to do their work without blocking the thread you're logging from. This is common in Web applications, though of course it also occurs in other scenarios. So, although not explicitly mentioned yet logging does seem to be blocking. For details see Python Docs.


1 Answers

Your logging configuration only captures logs within the django namespace.

This line:

logger = logging.getLogger(__name__) 

... tells the logger to use your module's name as the namespace for these logs (docs). If your module is called mymodule, then you can catch these logs by adding something like this to your logging configuration:

'loggers': {    'django' : {...},    'mymodule': {         'handlers': ['file'],         'level': 'DEBUG',         'propagate': True,     }, }, 
like image 50
solarissmoke Avatar answered Sep 19 '22 20:09

solarissmoke