Question

Disable HTTP logs in apps platform

Posted February 18, 2021 766 views
PythonDigitalOcean App PlatformFlask

I have a flask application running in gunicorn in the app platform.
Run command:

gunicorn --config gconfig.py --worker-tmp-dir /dev/shm --log-level error wsgi:app

gconfig.py:

bind = '0.0.0.0:8080'
workers = 2
worker_class = 'gevent'
worker_connections = 1000

flask init:

if logging.getLogger('gunicorn.error').handlers:
    app.logger.handlers.clear()
    app.logger.handlers.extend(
        logging.getLogger('gunicorn.error').handlers)
    app.logger.setLevel(logging.INFO)

But the logs contain http requests:

app-name | 2021-02-18 19:28:13 10.244.8.44 - - [18/Feb/2021:17:28:13 +0000] "POST /route HTTP/1.1" 200 322 "-" "Apache-HttpClient/4.5.7 (Java/1.8.0_212)"

I want the logs to contain only errors and the messages that I send myself:

current_app.logger.info('some log message')

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

The log messages you’ve referenced aren’t generated by App Platform. I suspect they’re being emitted by either gunicorn or flask. In gunicorn I believe you can disable the access log by setting accesslog = False. https://docs.gunicorn.org/en/stable/settings.html#settings

  • accesslog sets the source to where the access logs will route and should be a string. I tried redirecting this to a file:

    accesslog = 'gunicorn.log'
    

    Then I changed the configuration of the logger:

    logging.basicConfig(
        handlers=[logging.StreamHandler(sys.stdout)],
        level=logging.INFO,
        format='[%(asctime)s] [%(process)d] [%(levelname)s]: %(message)s'
    )
    logging.getLogger('werkzeug').disabled = True
    logging.getLogger('gunicorn.error').setLevel(logging.ERROR)
    

    This works locally as needed, including with gunicorn, but it does not work in digitalocean. The HTTP logs are still here.