[英]How to create rolling logs for Filebeat within a docker container
I'm new to log4j2 and the elastic stack. 我是log4j2和弹性堆栈的新手。
I have a filebeat docker container that doesn't work exactly how I want and now I want to take a look at the logs. 我有一个filebeat docker容器,该容器无法完全按照我的要求运行,现在我想看看日志。 But when I do
docker-compose logs
I get a lot debug messages and json objects. 但是当我做
docker-compose logs
我得到了很多调试消息和json对象。 It's unreadable how much there is. 有多少是不可读的。
How can I create a log4j2 properties setup to create some rolling log files. 如何创建log4j2属性设置来创建一些滚动日志文件。 Maybe put the old logs into a monthly based folder or something?
也许将旧日志放在每月的文件夹中? and where do I put this
log4j2.properties
file? 并将该
log4j2.properties
文件放在log4j2.properties
?
It's generating a lot of logs because you're running docker-compose logs
, which will get the logs for all containers in your docker compose file. 它会生成大量日志,因为您正在运行
docker-compose logs
,它将获取docker compose文件中所有容器的日志。
What you want is probably: 您想要的可能是:
docker logs <name-of-filebeat-container>
. docker logs <name-of-filebeat-container>
。 The name of the filebeat container can be found doing a docker ps
. docker ps
找到filebeat容器的名称。 docker compose logs <name-of-filebeat-service>
. docker compose logs <name-of-filebeat-service>
。 The name of the service can be found on your docker-composer.yml file. Regarding the JSON outputs, you can query your Docker engine default logging driver with: 关于JSON输出,您可以使用以下命令查询Docker引擎默认日志记录驱动程序:
# docker info | grep 'Logging Driver'
Logging Driver: json-file
If your container have a different Logging Driver you can check with: 如果您的容器具有其他日志记录驱动程序,则可以使用以下命令进行检查:
docker inspect -f '{{.HostConfig.LogConfig.Type}}' <name-or-id-of-the-container>
You can find all log drivers in this link 您可以在此链接中找到所有日志驱动程序
To run containers with a different log-driver you can do: 要使用其他日志驱动程序运行容器,您可以执行以下操作:
docker run -it --log-driver <log-driver> alpine ash
docker run -it --log-driver <log-driver> alpine ash
With docker-compose: 使用docker-compose:
`logging: driver: syslog options: syslog-address: "tcp://192.168.0.42:123"`
Regarding your log rotation questio, I'd say the easyest way is to configure the logging driver with the syslog driver, configure it to your local machine (or your syslog server) and then logrotate the files. 关于日志轮换问题,我想说最简单的方法是使用syslog驱动程序配置日志记录驱动程序,将其配置到本地计算机(或syslog服务器),然后对文件进行logrotate。
You can find several logrotate articles for Linux (which I assume you're using), for example this one 您可以找到几本关于Linux的logrotate文章(我假设您正在使用),例如, 这篇文章
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.