python - 扭曲的记录

标签 python twisted

我的 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 的文档中找不到它(那里没有任何关于日志记录的信息)

  1. 处理来自 3 个来源的日志记录的最佳方法是什么?
  2. 我将什么 kwargs 传递给 twisted.log 中的哪个函数来设置我自己的格式化程序(startLogging 不包含答案)
  3. 有什么比我建议的更好的解决方案? (我真的没有设置记录器的经验。)

最佳答案

您可以使用 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.msglog.err 调用。

我找到了 this上次我在使用 Twisted 时挖掘源代码。

关于python - 扭曲的记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3491294/

相关文章:

python - 排序 Pandas DataFrame

python - Python/PySide/PyQt 中的多线程网页抓取

python - 使用 Twisted 和 Comet 将命令结果流式传输回浏览器

python - 扭曲的Python垃圾收集

python - 在 ubuntu/debian io.h 上使用 pip 时出现扭曲 iocpsupport 错误

python - 如何在Python中找出给定日期的周数?

python - 如何将 Pandas 数据框中的多列弹出到新的数据框中?

python - 在 Python 中通过 global 关键字从外部作用域访问变量

python - Twisted 无缘无故抛出 "Can only pass-through bytes on Python 2"

python - 如何: Twisted privmsg to accept non-ascii strings