简体   繁体   English

docker 日志 filebeat > file.log 不起作用

[英]docker logs filebeat > file.log don't work

With Docker version 18.09.5, build e8ff056 and filebeat:7.1.1 (by elasticsearch) when I type:使用 Docker 版本 18.09.5,当我键入时构建 e8ff056 和 filebeat:7.1.1(通过 elasticsearch):

$ docker logs filebeat > filebeat.log

I see the logs but the filebeat.log is empty.我看到了日志,但 filebeat.log 是空的。

If I try:如果我尝试:

$ docker logs logstash > logstash.log

I don't see the log to console but the file il full with the logs lines.我没有看到到控制台的日志,但是文件中充满了日志行。

The used OS is: Ubuntu 19.04使用的操作系统是: Ubuntu 19.04

The > redirects STDOUT, but you can also have STDERR output from containers. >重定向 STDOUT,但您也可以从容器获得 STDERR 输出。 To redirect that, you can use:要重定向,您可以使用:

 docker logs filebeat > filebeat.log 2> filebeat.err

or send both to the same file:或将两者发送到同一个文件:

 docker logs filebeat > filebeat.log 2>&1

You should run the container with the -t flag which will allocate a pseudo-tty for the container.您应该使用 -t 标志运行容器,该标志将为容器分配一个伪 tty。 Example:例子:

docker run -td --rm --name test store/elastic/filebeat:7.1.1

docker logs test > test.txt

This will store the output to the file.这会将输出存储到文件中。 When running without the -t flag it will simply dump the logs in your terminal在没有 -t 标志的情况下运行时,它只会将日志转储到您的终端中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM