Django 5.1.3
Python 3.12.4
I have been instructed to get django logging operational for this POC . Seems straight forward. I’m having a couple of issues though. But I’m new to this so could be me as usual. Also 1 thing to note is all debug terminal feedback like print(‘’) etc. and pages loading all stop. no output to terminal. I have disable_existing_loggers set to False.
'disable_existing_loggers': False,
See below sample code from settings.py for .env
FYI path to error.log = .epsonVE\enoc_proj\error.log
1 - I see that it does create an error.log file. See path above. But it does not ever append anything to it.
2 - I get this weird info alert after running > python manage.py runserver . It all comes up and the project / apps work fine but I get the INFO alert below. 3 of them (2 are the same)
Seems to indicate I don’t have an .env file or in the right place. I know this to be incorrect because I have been using one for a long time and it’s loaded with all kinds of things:
i.e.: DJANGO SECRET KEY, ALL THE DATABASE CREDS AND HOSTING, API keys, DJANGO_DEBUG, DJANGO_ALLOWED_HOSTS
These things are all working fine. So not an .env issue. I think.
These INFO alerts only happen when I have this code in the loggers section:
'': { # **<-- root logger**
'level': 'INFO',
'handlers': ['console', 'file']
},
FYI: One thing I notice is the 3 INFO alerts mention 2 of my apps (console_app and Turnover_app). Why these 2 only? I have 6 apps in this project.
Alerts received :
INFO C:\Users\EAI24909\OneDrive - Epson America\Desktop\Python Projects\epson.epsonVE\enoc_proj\console_app.env doesn’t exist - if you’re not configuring your environment separately, create one.
INFO C:\Users\EAI24909\OneDrive - Epson America\Desktop\Python Projects\epson.epsonVE\enoc_proj*console_app*.env doesn’t exist - if you’re not configuring your environment separately, create one.
INFO C:\Users\EAI24909\OneDrive - Epson America\Desktop\Python Projects\epson.epsonVE\enoc_proj*turnover_app*.env doesn’t exist - if you’re not configuring your environment separately, create one.
settings.py (code placed at end of the file.)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
'json': {
'format': '{"timestamp": "%(asctime)s", "level": "%(levelname)s", "message": "%(message)s"}',
'style': '%',
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'formatter': 'simple',
},
'file': {
'level': 'ERROR',
'class': 'logging.FileHandler',
'filename': 'error.log',
'formatter': 'verbose',
},
},
'loggers': {
'': { # **<-- root logger**
'level': 'INFO',
'handlers': ['console', 'file']
},
'django': {
'handlers': ['console'],
'level': 'INFO',
'propagate': True,
},
'django.server': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': False,
},
'myapp': {
'handlers': ['file'],
'level': 'ERROR',
'propagate': False,
},
},
}
settings.py
DEBUG = env.bool("DJANGO_DEBUG", False)
# Allowed Hosts Definition
if DEBUG:
# If Debug is True, allow all.
ALLOWED_HOSTS = ['*']
else:
ALLOWED_HOSTS = env.list('DJANGO_ALLOWED_HOSTS', default=['example.com'])
SECRET_KEY = env("SECRET_KEY", default="unsafe-secret-key")