Flask Web App on Ubuntu 19.10 Linode, IOError: [Errno 13] Permission denied: '/app.log'
I'm trying to get logging working on a flask web app on my Ubuntu 19.10 linode server.
logging setup in webApp.wsgi:
I have tried putting a more specific file path
I have checked the log files in both directories have permissions 'rw-r--r--'
I have also tried elevating the permissions of the log file but get the same issue.
-rw-rw-rw- 1 root root 0 Apr 26 23:22 app.log
The file structure of my linode server:
--app.log <- LOG
----app.log <- LOG
The apache2 error log:
File "/var/www/webApp/webapp.wsgi", line 5, in <module>,
File "/usr/lib/python2.7/logging/init__.py", line 1554, in basicConfig, hdlr = FileHandler(filename, mode), File "/usr/lib/python2.7/logging/_init_.py", line 920, in _init_, StreamHandler._init_(self, self._open()), File "/usr/lib/python2.7/logging/__init.py", line 950, in _open,
stream = open(self.baseFilename, self.mode),
IOError: [Errno 13] Permission denied: '/app.log', </module>
Your flask app is likely running with the effective uid/gid of the web server (www-data on Debian/Ubuntu) while /var/log is owned by root; ergo, the permissions violation.
What you need to do is one of the following:
Change the location of the flask log from /var/log to someplace the web server has permission to write; or
Change the flask logging setup to use the syslog service.
My plan of attack would be to the first thing and log to /tmp while I figured out the 2nd thing. The 2nd thing is really what you want.
I don't know anything about python and even less about flask but I do know that python has a syslog logging handler:
I have no idea if this is helpful to you or not but it should get you pointed in the right direction.