我的 twisted reactor 下运行着 3 个进程:Orbited、WSGI(运行 django)和 Twisted 本身。
我正在使用
log.startLogging(sys.stdout)
当所有日志都指向同一个地方时,泛洪过多。
我在 WSGI 的日志中有一行是这样的:
2010-08-16 02:21:12-0500 [-] 127.0.0.1 - - [16/Aug/2010:07:21:11 +0000] "GET /statics/js/monitor_rooms.js HTTP/1.1" 304 - "http://localhost:11111/chat/monitor_rooms" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100723 Ubuntu/10.04 (lucid) Firefox/3.6.8"
时间基本重复两次。我想我应该使用我自己的格式化程序,但不幸的是我在 twisted 的文档中找不到它(那里没有任何关于日志记录的信息)
- 处理来自 3 个来源的日志记录的最佳方法是什么?
- 我将什么 kwargs 传递给 twisted.log 中的哪个函数来设置我自己的格式化程序(startLogging 不包含答案)
- 有什么比我建议的更好的解决方案? (我真的没有设置记录器的经验。)
最佳答案
您可以使用 system
关键字参数到 twisted.python.log.msg
来自定义消息。
假设你有:
log.msg("Service ready for eBusiness!", system="enterprise")
你会得到这样的日志输出:
2010-08-16 02:21:12-0500 [enterprise] Service ready for eBusiness!
然后您可以让您的每个服务将 system="wsgi/orbited/..."
添加到它们的 log.msg
和 log.err
调用。
我找到了 this上次我在使用 Twisted 时挖掘源代码。
关于python - 扭曲的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3491294/