Gunicorn gevent worker logging issues

亡梦爱人 提交于 2020-01-06 07:21:42

问题


I have a gunicorn server running with 1 worker. I user the logging module during the request. None of them appear in stdout. I know that gevent workers monkey patch all so I would assume any loggin done during the request should appear on the mainthread stdout.

The app parse to gunicorn is the application wsgi from django.

gunicorn -c gunicorn.py core.wsgi:application

In gunicorn.py I have:

bind = '0.0.0.0:8080'
backlog = 2048
workers = 1
worker_class = 'gevent'
worker_connections = 1000
timeout = 60
keepalive = 2

proc_name = None

def post_fork(server, worker):
    server.log.info("Worker spawned (pid: %s)", worker.pid)


def pre_fork(server, worker):
    pass


def pre_exec(server):
    server.log.info("Forked child, re-executing.")


def when_ready(server):
    server.log.info("Server is ready. Spawning workers")


def worker_int(worker):
    worker.log.info("Worker received INT or QUIT signal")

    import threading, sys, traceback
    id2name = dict([(th.ident, th.name) for th in threading.enumerate()])
    code = []
    for thread_id, stack in sys._current_frames().items():
        code.append("\n# Thread: %s(%d)" % (id2name.get(thread_id, ""),
                                            thread_id))
        for filename, line_no, name, line in traceback.extract_stack(stack):
            code.append('File: "%s", line %d, in %s' % (filename,
                                                        line_no, name))
            if line:
                code.append("  %s" % (line.strip()))
    worker.log.debug("\n".join(code))


def worker_abort(worker):
    worker.log.info("Worker received SIGABRT signal")

Within on of the request functions I simply put

import logging
logging.error('test'))

It only executes this log after the worker has finished its request. And some of the other logs don't even show up like so.

import logging
logger = logging.getLogger('test_logger'))
logger.setLevel(logging.DEBUG)
logger.error('test')

If you need anything else from me to possibly help me towards resolving this issue ask away.


回答1:


Simply needed to add this to the gunicorn.py

errorlog = '-'
loglevel = 'info'
accesslog = '-'


来源:https://stackoverflow.com/questions/49428770/gunicorn-gevent-worker-logging-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!