从枪支中的多名工人登记
我正在使用内置的Python伐木库来监视我的烧瓶应用程序中发生的事情,并使用Gunicorn使用它来旋转多个工人,从而在后端微服务上工作。
理想情况下,我想创建一个父logger(logging.getLogger('service'')
),每个工作人员都会使用子记录器(logging.getlogger('service.worker1')< /code>,<代码> logging.getLogger('service.worker2')
等)。但是,我不确定是否有区分工作流程的方法。
我可以为每个新枪手工人以某种方式通过不同的论点吗?
现在,当我在每个工人中使用相同的记录器(logging.getLogger('service'')
all)时,我无法分辨哪个工人创建了日志。这可能不是问题,但是如果我使用logging.filehandler
,那么单独的进程可能会碰撞。
I'm working on a backend microservice, using the built in python logging library to monitor what is happening in my Flask app, and using Gunicorn to spin up multiple workers with it.
Ideally I would like to create a parent logger (logging.GetLogger('Service')
), and each worker would use a child logger (logging.GetLogger('Service.Worker1')
, logging.GetLogger('Service.Worker2')
, etc.). However, I'm not sure if I have a way to differentiate worker processes.
Can I pass somehow different arguments for each new gunicorn worker?
Right now when I'm using the same logger in each worker (logging.GetLogger('Service')
for all), I have no way to tell which worker created the log. This might not be an issue, but if I'm using a logging.FileHandler
then separate processes may collide.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想出的一个解决方法只是使用
os.getPid()
,这在每个工人中都是唯一的。虽然这可以完成工作,并允许我创建唯一的登录名称,但我仍然想知道是否有更好的方法。One workaround that I came up with is simply using
os.getpid()
, which will be unique in each worker. While this does the job and allows me to create unique names for logging, I'm still wondering if there is a better way.