E
E
eifory2019-07-19 15:20:03
Python
eifory, 2019-07-19 15:20:03

How to get logs from flask + ngnix + gunicorn?

I use flask + nginx + gunicorn.
this one gets into the log: guni_logger.info('info from GET')
but this one doesn't: guni_logger.info('info from POST')
At the same time, the post request goes through and all the logic works.
From what source can I get info in the log in a POST request?
Perhaps it has something to do with the gunicorn workers?

...
import logging

app.logger.setLevel(logging.INFO)
handler = logging.FileHandler('standart.log')
handler.setLevel(logging.INFO)
app.logger.addHandler(handler)

if __name__ != '__main__':
    guni_logger = logging.getLogger('gunicorn.error')
    guni_logger.setLevel(logging.INFO)
    guni_handler = logging.FileHandler('guni.log')
    guni_handler.setLevel(logging.INFO)
    guni_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    guni_handler.setFormatter(guni_formatter)
    guni_logger.addHandler(guni_handler)

@app.route('/', methods=['GET'])
def index():
    ...
    guni_logger.info('info  from GET')
    ...
    return send_from_directory('front', 'index.html')

@app.route('/uploader/<num>', methods = ['POST'])
def uploader(num):
    if request.method == 'POST':
        ...
        guni_logger.info('info from POST')
        ...

if __name__ == '__main__':
    app.run(host='0.0.0.0')

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question