如何在同一台Web服务器上使用多个Django WSGI进程+ celery进行日志记录 [英] How to do logging with multiple django WSGI processes + celery on the same webserver

查看:187
本文介绍了如何在同一台Web服务器上使用多个Django WSGI进程+ celery进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一VM上有一个具有5个进程和celery worker队列(其中2个)的mod_wsgi服务器设置.我遇到了一个问题,即记录器之间会互相踩踏,而如果您使用的是python多处理,则似乎有一些解决方案,但我看不到它如何适用于与芹菜进程结合使用的mod_wsgi进程.

I've got a mod_wsgi server setup with 5 processes and a celery worker queue (2 of them) all on the same VM. I'm running into problems where the loggers are stepping on each other and while it appears there are some solutions if you are using python multiprocessing, I don't see how that applies to mod_wsgi processes combined also with celery processes.

其他人都在处理这个问题吗? celery任务使用的代码与Web服务器代码登录的文件相同.

What is everyone else doing with this problem? The celery tasks are using code that logs in the same files as the webserver code.

我是否必须以某种方式在日志文件名中添加一个pid?似乎很多具有唯一名称的日志文件可能会很快变得混乱,并且没有真正一致的方式将它们重新组合在一起.

Do I somehow have to add a pid to the logfilename? That seems like it could get messy fast with lots of logfiles with unique names and no real coherent way to pull them all back together.

我是否必须编写一个允许所有进程登录的日志守护程序?如果是这样,那么在哪里启动它,以便为可能要记录的所有进程做好准备.....

Do I have to write a log daemon that allows all the processes to log to it? If so, where do you start it up so that it is ready for all of the processes that might want to log.....

肯定有某种理智的模式可以解决这个问题,我只是不知道它是什么.

Surely there is some kind of sane pattern out there for this, I just don't know what it is yet.

推荐答案

As mentioned in the docs, you could use a separate server process which listens on a socket and logs to different destinations, and has whatever logging configuration you want (in terms of files, console and so on). The other processes just configure a SocketHandler to send their events to the server process. This is generally better than separate log files with pids in their filenames.

日志记录文档包含套接字服务器实现示例可以满足您的需求.

The logging docs contain an example socket server implementation which you can adapt to your needs.

这篇关于如何在同一台Web服务器上使用多个Django WSGI进程+ celery进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆