0

I am trying to diagnose some mysterious Internal Server Errors, so I added logging to the flask app. After digging through many explanations, I found this answer which I am using below, along with the suggestion to put everything inside a @app.before_first_request decorator.

Locally this works as expected and werkzeuglog.log contains exactly what is printed to the screen.

But on the server:

  1. The log file is created.
  2. Nothing is written to it.
  3. No errors are thrown, at least not to the user
@app.before_first_request
def initialize():
    logger = logging.getLogger('werkzeug')
    logger.setLevel(logging.DEBUG)
    handler = logging.FileHandler('werkzeuglog.log')
    logger.addHandler(handler)

if __name__ == '__main__':
    #run app
    app.run(
        host="0.0.0.0",
        port=int("80"),
        debug=False
    )

Am I doing something wrong or is this some server issue that is beyond my scope? Gentle answers appreciated!

EDIT: Some context: An internal server error is caused when the user uploads a file and I am trying to figure out what's going wrong using the log.
I don't think it can be an issue with permissions since the script definitely creates the file. I checked that the disk is not full.

EDIT 2 I reran the run.fcgi file which starts the WSGI Server. Now the manual entries to the log file via logger.info('blah blah') show up but not the others i.e. GET POST etc.

I don't have access to /var/log/nginx. It's a student-volunteer run server so I would like to give them as much info as I can. But this is all I have so far.

A. Roy
  • 366
  • 3
  • 12
  • 1
    Say details about the server. Are you sure your script has permission writing a new file in the server? – arshovon Jun 06 '18 at 07:42
  • Script belongs to the user and does create the file successfully. I changed the log file permissions to -rw-rw-rw- to no effect. – A. Roy Jun 06 '18 at 07:50
  • Maybe the logs are redirected to the server logs, what server are you using ? Apache, nginx ? – PRMoureu Jun 06 '18 at 10:38
  • I know is that it is wrapped in WSGI and all I can do at my end is edit the run.fcgi file. – A. Roy Jun 06 '18 at 12:24
  • Try to manually write something (at least at the debug level!) on every request, perhaps you're only logging at an info level which is ignored? `logger.debug('This is a debug statement')` or `logger.warning('This is a warning')` – lennyklb Jun 06 '18 at 13:06
  • Could you check the server logs or ask the guy-who-can? When you say it works locally, is it with the flask development server ? – PRMoureu Jun 06 '18 at 16:55
  • Yes locally means with the flask development server. Again manually writing to the logger works locally but not on the server. – A. Roy Jun 06 '18 at 17:25
  • could you check some files on the server ? don't know if the server is Apache or nginx, but look at the default paths, like `/var/log/apache2/` or `/var/log/nginx/error.log`, maybe the server configuration customize that. Look at this [doc](http://flask.pocoo.org/docs/dev/logging/#default-configuration) – PRMoureu Jun 06 '18 at 17:38
  • Correction: manual entries show up (see edit in post). Honestly the flask logging docs are too much for me, so I would appreciate an explicit suggestion. – A. Roy Jun 06 '18 at 18:14

0 Answers0