Docker日志中的Python异常标记为流:stdout

我想解析并处理docker容器中的所有错误,但是当我期望stderr时,将python异常标记为stdout。

例如简单的

raise Exception("!")

然后我在docker容器中运行此文件。但是在 :

{"log":"Traceback (most recent call last):\n","stream":"stdout","time":"2015-06-17T23:10:01.58636849Z"}

{"log":" File \"/var/app.py\", line 1, in \u003cmodule\u003e\n","stream":"stdout","time":"2015-06-17T23:10:01.586581081Z"}

{"log":" raise Exception(\"!\")\n","stream":"stdout","time":"2015-06-17T23:10:01.586842665Z"}

{"log":"Exception: !\n","stream":"stdout","time":"2015-06-17T23:10:01.587373678Z"}

回答:

我有一个误解。我认为Docker CLI的命令不会影响主日志(/var/lib/docker/containers/…/…-json.log)

但在以下情况下:

json.log内容:

{"log":"Traceback (most recent call last):\n","stream":"stdout","time":"2015-06-18T10:02:55.842010241Z"}

{"log":" File \"/var/app.py\", line 1, in \u003cmodule\u003e\n","stream":"stdout","time":"2015-06-18T10:02:55.842252975Z"}

{"log":" raise Exception(\"error\")\n","stream":"stdout","time":"2015-06-18T10:02:55.842423153Z"}

{"log":"Exception: error\n","stream":"stdout","time":"2015-06-18T10:02:55.842754372Z"}

但是,如果我在后台运行容器,流将成为stderr:

{"log":"Traceback (most recent call last):\n","stream":"stderr","time":"2015-06-18T10:02:18.905673576Z"}

{"log":" File \"/var/app.py\", line 1, in \u003cmodule\u003e\n","stream":"stderr","time":"2015-06-18T10:02:18.90575399Z"}

{"log":" raise Exception(\"error\")\n","stream":"stderr","time":"2015-06-18T10:02:18.905802834Z"}

{"log":"Exception: error\n","stream":"stderr","time":"2015-06-18T10:02:18.90616668Z"}

我认为这种行为是隐性的。

以上是 Docker日志中的Python异常标记为流:stdout 的全部内容, 来源链接: utcz.com/qa/413587.html

回到顶部