I have a very good question, which I would like an expert to comment on for me, please. (maybe Graham Dumpleton)
So, I have a Django web application (developed on ubuntu 16.04) that logs some crashes, as shown below, on / var / log / apache 2 / APPNAME.log.
since all the files in / var / log / apache 2 have root: adm owner, I granted ownership of my log file in the same way, and I made sure www-data is a member of the adm group. Then I provided rwx to the adm group for the owners group, and I tested that everything was working fine.
After 24 hours, the permission of the file and the parent folder changed, and I see that the write permission was canceled from the log file, and the parent directory causing the error rejected the error because the log file could not be written.
Here are my questions, if you could kindly help:
1) where do I need to place the Django log files?
2) What process under what user permission does the file write?
3) What process resets permissions in / var / log / apache and why?
Thank you very much,
I hope this question helps others as well.
Cheers, Mike
views.py
from django.shortcuts import render from django.shortcuts import render from django.http import HttpResponse, HttpResponseRedirect from django import forms from django.core.mail import send_mail, EmailMessage from StudioHanel.forms import ContactForm import traceback import time
settings.py
LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'filters': { 'require_debug_false': { '()': 'django.utils.log.RequireDebugFalse' } }, 'handlers': { 'mail_admins': { 'level': 'ERROR', 'filters': ['require_debug_false'], 'class': 'django.utils.log.AdminEmailHandler' }, 'applogfile': { 'level':'DEBUG', 'class':'logging.handlers.RotatingFileHandler', 'filename': os.path.join('/var/log/apache2', 'APPNAME.log'), 'maxBytes': 1024*1024*15, 15MB 'backupCount': 10, }, }, 'loggers': { 'django.request': { 'handlers': ['mail_admins'], 'level': 'ERROR', 'propagate': True, }, 'APPNAME': { 'handlers': ['applogfile',], 'level': 'DEBUG', }, } }