如何在系统日志中禁用logstash错误日志记录

unftdfkk  于 2023-09-28  发布在  Logstash
关注(0)|答案(3)|浏览(224)

所有Logstash错误都记录在/var/log/logstash/* 中,但Logstash的所有错误日志也记录在/var/log/syslog中。有什么方法可以在/var/log/syslog中禁用Logstash的日志记录错误吗?

t8e9dugd

t8e9dugd1#

我假设你从systemd运行logstash。由于未知原因,logstash打印它的日志在stdout/stderr上,所以journald将控制台输出转发到syslog。重定向systemd单元文件中的stdout/err,如下所示:

[Service]
Type=simple
Restart=always
WorkingDirectory=/data/logstash
ExecStart=/usr/bin/sudo -u logstashuser bash -c "/opt/logstash/bin/logstash --path.settings /opt/logstash/conf >/dev/null 2>/logs/logstash/logstash.error.log"

然后

systemctl daemon-reload

systemctl stop logstash.service
systemctl start logstash.service
yjghlzjz

yjghlzjz2#

另一种解决方案是修改/etc/systemd/system/logstash.service并将这两个选项更改为如下所示

StandardOutput=null
StandardError=null
# cat /etc/systemd/system/logstash.service
[Unit]
Description=logstash

[Service]
Type=simple
User=logstash
Group=logstash
# Load env vars from /etc/default/ and /etc/sysconfig/ if they exist.
# Prefixing the path with '-' makes it try to load, but if the file doesn't
# exist, it continues onward.
EnvironmentFile=-/etc/default/logstash
EnvironmentFile=-/etc/sysconfig/logstash
ExecStart=/usr/share/logstash/bin/logstash "--path.settings" "/etc/logstash"
StandardOutput=null
StandardError=null
Restart=always
WorkingDirectory=/
Nice=19
LimitNOFILE=16384

# When stopping, how long to wait before giving up and sending SIGKILL?
# Keep in mind that SIGKILL on a process can cause data loss.
TimeoutStopSec=infinity

[Install]
WantedBy=multi-user.target

那么当然

#systemctl daemon-reload
#systemctl restart logstash
wn9m85ua

wn9m85ua3#

打开/etc/logstash/log4j2.properties并注解掉此行

rootLogger.appenderRef.console.ref = ${sys:ls.log.format}_console

相关问题