37👍
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,
},
},
11👍
you should add logger configuration due to your application name – something like
'your_app_name': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
By now you have declared only logger for django default messages (like system errors)
Notice that the level of logger messages is important so when you are using
logger.info("this is an error message!!")
method to print out message your logger’s level should be INFO or more strict
- [Django]-How to break "for loop" after 1 iteration in Django template
- [Django]-Django select max id
- [Django]-TypeError: data.forEach is not a function
10👍
You could add the “catch all” logger to the loggers section:
'loggers': {
'': {
'handlers': ['file'],
'level': 'DEBUG',
}
}
It will catch all the log messages which are not caught by Django’s default loggers.
- [Django]-Django.core.exceptions.ImproperlyConfigured: WSGI application 'application' could not be loaded
- [Django]-Django returning HTTP 301?
- [Django]-How can I force django to restart a database connection from the shell?
2👍
import logging
logger = logging.getLogger(__name__)
after add:
logging.basicConfig(
level = logging.DEBUG,
format = '%(name)s %(levelname)s %(message)s',
)
or just add settings.py :
import logging
logging.basicConfig(
level = logging.DEBUG,
format = '%(name)s %(levelname)s %(message)s',
)
we may change format to:
format = '"%(levelname)s:%(name)s:%(message)s" ',
or
format = '%(name)s %(asctime)s %(levelname)s %(message)s',
- [Django]-How to dynamically provide lookup field name in Django query?
- [Django]-How do you detect a new instance of the model in Django's model.save()
- [Django]-How do you use the django-filter package with a list of parameters?