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".
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.
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.
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.
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, }, },
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With