Hi
I used Django Latest version 5.0.7 and following is my logging configurations in settings.py file
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_true": {"()": "django.utils.log.RequireDebugTrue"},
},
"formatters": {
"default": {
"format": (
"[%(asctime)s][%(levelname)s]"
"[PID:%(process)d][Thread:%(thread)d]"
"[%(name)s][%(funcName)s:%(lineno)s][%(message)s]"
),
},
},
"handlers": {
"console": {
"filters": ["require_debug_true"],
"class": "logging.StreamHandler",
"formatter": "default",
},
},
"loggers": {
"": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
},
}
Django is not automatically picking it I have to write
from logging import config
config.dictConfig(LOGGING)
after the LOGGING configurations to make it work. Moreover, in file am using the following code to use logging in my view.
# finance/views.py
import logging
logger = logging.getLogger(__name__)
def finance_view(request):
logger.info("Finance view called")
import logging
logger = logging.getLogger({logger name})
def finance_view(request):
logger.info("Finance view called")
Hi @white-seolpyo,
Thanks for the response
Its the same thing write a custom name or use name it supposed to work.
logger = logging.getLogger("Finance View")
In previous versions it was working fine.
“Finance View” is not in your logger in settings.py.
LOGGING = {
...
"loggers": {
"": {
"handlers": ["console"],
"level": "DEBUG",
"propagate": False,
},
},
}
Issue is i cannot specify each files logger name specifically, it should pick it automatically when i write rule as “”.
We need a generic solution, in previous versions I had this and every files logs where displaying.
What version of Python are you using?
Hi @KenWhitesell, I am using Python 3.12
I am unable to recreate the symptoms you are describing here.
I created a copy of the tutorial polls project, set it up under Python 3.12 with Django 5.0.7, and added the logging configuration you posted above to my settings.
I then added the logging code into my polls/views.py
file, with a logger.info
function call in the index
view.
I then ran the server, invoked the index view, and saw the log message with your defined format in the console.
I did not need to add the dictConfig
function call in my settings.
This leads me to believe that there may be some other configuration issue involved.
I might try creating a new virtual environment to ensure something hasn’t gotten messed up in your original environment. (This can happen when you upgrade base components and don’t upgrade a virtual environment. It can also happen if your pycache files end up out-of-sync. There are other causes as well.)
I might also try running this with the -v
parameter to see the order of the imports being executed. (In particular, you would probably want to look for the logging module being imported to ensure that it’s coming from the right location.)
I have the same issue. No logs are printed with or without LOGGING variable set. In development and production setup.
Welcome @sorenwacker !
If this is a specific issue with which you are requesting assistance, I suggest you open a new topic for it, to avoid confusion among questions being asked and answers given.
1 Like
@KenWhitesell, I would, but the website displays no option to create a new post. I can only reply to other peoples posts.
If you don’t have this button available to you, please let me know.
From the home page on the site:
(That button should also be available on the “Latest” page. You go to either of these pages by clicking on the word “django” / “dj” on the top left of that menu bar.)
If debug = false this could be the problem.
remove or change require_debug_false
.
"filters": ["require_debug_true"],