Delgan / loguru

Python logging made (stupidly) simple

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't enqueue=True be used with multiple gunicorns?

liuqijie6 opened this issue · comments

When I set enqueue=True, my gunicron cannot start.

logger.add(log_path,
                   rotation=CONFIG.get('Log', 'rotation'),
                   encoding="utf-8",
                   enqueue=True,
                   retention=CONFIG.get('Log', 'retention'),
                   # compression=CONFIG.get('Log', 'compression'),
                   format=CONFIG.get("Log", "format"),
                   level="DEBUG",
                   # diagnose=True,
                   serialize=True
                   )

gunicron.conf.py

from config import CONFIG
from config.log_info import PORT

host, port = CONFIG.get("web_server", "host"), CONFIG.get("web_server", "port")
bind = f"{host}:{port}"
PORT["port"] = port
cpu_count = multiprocessing.cpu_count()
daemon = False
worker_class = 'eventlet'  # 'gevent' sync  eventlet
workers = cpu_count
threads = cpu_count if worker_class == "sync" else 1
capture_output = True  # 打印存入error日志
accesslog = "-"

supervisord.log

2024-05-04 22:42:17,957 INFO success: CheckIn2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-05-04 22:43:46,437 INFO waiting for CheckIn to stop
2024-05-04 22:43:48,437 INFO waiting for CheckIn to stop
2024-05-04 22:43:50,437 INFO waiting for CheckIn to stop
2024-05-04 22:43:52,437 INFO waiting for CheckIn to stop
2024-05-04 22:43:54,437 INFO waiting for CheckIn to stop
2024-05-04 22:43:56,437 WARN killing 'CheckIn' (33945) with SIGKILL
2024-05-04 22:43:56,437 INFO waiting for CheckIn to stop
2024-05-04 22:43:56,441 INFO stopped: CheckIn (terminated by SIGKILL)
2024-05-04 22:43:56,443 INFO waiting for CheckIn2 to stop
2024-05-04 22:43:58,443 INFO waiting for CheckIn2 to stop
2024-05-04 22:44:00,443 INFO waiting for CheckIn2 to stop
2024-05-04 22:44:02,443 INFO waiting for CheckIn2 to stop
2024-05-04 22:44:04,443 INFO waiting for CheckIn2 to stop
2024-05-04 22:44:06,442 WARN killing 'CheckIn2' (33967) with SIGKILL
2024-05-04 22:44:06,443 INFO waiting for CheckIn2 to stop
2024-05-04 22:44:06,446 INFO stopped: CheckIn2 (terminated by SIGKILL)
2024-05-04 22:46:42,368 INFO spawned: 'CheckIn' with pid 37788
2024-05-04 22:46:43,724 INFO success: CheckIn entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-05-04 22:49:45,086 INFO waiting for CheckIn to stop
2024-05-04 22:49:47,086 INFO waiting for CheckIn to stop
2024-05-04 22:49:49,086 INFO waiting for CheckIn to stop
2024-05-04 22:49:51,086 INFO waiting for CheckIn to stop
2024-05-04 22:49:53,086 INFO waiting for CheckIn to stop
2024-05-04 22:49:55,086 WARN killing 'CheckIn' (37788) with SIGKILL
2024-05-04 22:49:55,087 INFO waiting for CheckIn to stop
2024-05-04 22:49:55,089 INFO stopped: CheckIn (terminated by SIGKILL)
2024-05-04 22:49:55,093 INFO spawned: 'CheckIn' with pid 40555
2024-05-04 22:49:56,456 INFO success: CheckIn entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2024-05-04 22:49:56,458 INFO spawned: 'CheckIn2' with pid 40592
2024-05-04 22:49:57,835 INFO success: CheckIn2 entered RUNNING state, process has stayed up for > than 1 seconds (startsecs

What I want to solve is to run multiple gunincorns, and then the log output can be in the same file, and the log order is not lost.
截屏2024-05-04 23 00 07
The difference between them is that the ports are different。

Can you help me?

The enqueue=True does not interoperate well with Gunicorn workers. This is because the workers does not inherit the logger from the parent process.

For now, until a better solution is implemented, it's advised to use one different file per worker.