从枪支中的多名工人登记

发布于 2025-02-06 07:51:41 字数 488 浏览 3 评论 0原文

我正在使用内置的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别想她 2025-02-13 07:51:41

我想出的一个解决方法只是使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文