Docker日志中的Python异常标记为流:stdout [英] Python exceptions in Docker logs marked as stream: stdout

查看:167
本文介绍了Docker日志中的Python异常标记为流:stdout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want parse and handle all errors from docker container, but python exceptions marked as stdout, when I expect stderr.

例如简单的 app.py

raise Exception("!")

然后我在docker容器中运行此文件。
但是在 / var / lib / docker / containers /.../...- json.log 中:

Then I run this file in docker container. But in /var/lib/docker/containers/.../...-json.log:

{"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"}


推荐答案

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

I had a misconception. I thought that the command of docker CLI does not affect the main logs (/var/lib/docker/containers/.../...-json.log)

但如果出现以下情况:

docker run -it my_python python /var/app.py

json.log内容:

json.log content:

{"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:

But if I run container in background, stream become stderr:

docker run -d my_python python /var/app.py

{"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"}

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

I think this behavior implicitly.

这篇关于Docker日志中的Python异常标记为流:stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆