I'd really like to use Logging to make sure my application is working correctly, but I can't get it to work reliably.
I've only noticed the issue after I delete all the existing lines from the log file and I'm not sure if it happens at other times or not, but sometimes the requested information is successfully added to my log file, and other times nothing is and the file remains blank.
I've got it set up like so, logger = logging.getLogger(__name__)
and am using logger.info("Log This!")
Is this caused by manually deleting things from the log file? Or perhaps something is wrong with my configuration?
LOGGING = {'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'logs/GeniusLogs.log'),
'formatter': 'verbose'
},
},
'loggers': {
'': {
'handlers': ['file'],
'level': 'INFO',
'propagate': True
},
'django': {
'handlers':['file'],
'propagate': True,
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
},
}
}
Edit
After playing with it, it seems that manually editing the log file is what is causing the issue. After I edit the file, I have to make some sort of material change in the logging settings to get it to work again. (Usually commenting out the Django app and loading a page will get it to work).
It's best to clear a log from the command line:
with open('AlmondKing/logs/GeniusLogs.log', 'w'):
pass