Skip to content

Instantly share code, notes, and snippets.

@sri-teja
Last active October 31, 2019 14:26
Show Gist options
  • Save sri-teja/1eae459ab151d573e1281c45dbf8a51a to your computer and use it in GitHub Desktop.
Save sri-teja/1eae459ab151d573e1281c45dbf8a51a to your computer and use it in GitHub Desktop.
## Reference: https://medium.com/@trstringer/logging-flask-and-gunicorn-the-manageable-way-2e6f0b8beb2f
## in wsgi.py (gunicorn base file)
## this is to mainitain sync between the levels of logging module and gunicorn logger.
import logging
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
## print logs using
app.logger.info("Hello this will be saved in log file with [INFO] tag.")
## set gunicorn log-level to debug to get all levels of logs.
## DEBUG, INFO, WARNING, ERROR, CRITICAL is the log level hierarchy.
## gunicorn command
## <path_to_gunicorn> --workers 2 --bind unix:running.sock --log-file <path to log file> --log-level debug --capture-output -m 007 wsgi:app --preload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment