我正在尝试配置logstash。在wiki中,我发现我们可以读取apache或其他系统日志。读取tomcat日志的配置和步骤是什么。
答案 0 :(得分:2)
Tomcat使用Java-Util-Logging。
您可以使用直接GELF appender将日志从Tomcat提交到logstash。
您的启动脚本和记录器配置(以及两个罐子)需要进行一些更改:
<强> /conf/logging.properties 强>:
handlers = 1catalina.org.apache.juli.FileHandler, 2localhost.org.apache.juli.FileHandler, 3manager.org.apache.juli.FileHandler, 4host-manager.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler, biz.paluch.logging.gelf.jul.GelfLogHandler
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler, biz.paluch.logging.gelf.jul.GelfLogHandler
biz.paluch.logging.gelf.jul.GelfLogHandler.host=udp:localhost
biz.paluch.logging.gelf.jul.GelfLogHandler.port=12201
biz.paluch.logging.gelf.jul.GelfLogHandler.level=INFO
<强> /bin/catalina.sh 强>:
if [ -r "$CATALINA_BASE/bin/logstash-gelf-1.4.2.jar" ] ; then
CLASSPATH=$CLASSPATH:$CATALINA_BASE/bin/logstash-gelf-1.4.2.jar:$CATALINA_BASE/bin/json-simple-1.1.jar:$CATALINA_BASE/bin/jedis-2.5.1.jar:$CATALINA_BASE/bin/commons-pool2-2.0.jar
fi
<强> logstash-GELF 强>: logstash-gelf-1.5.2-logging-module.zip
答案 1 :(得分:1)
这可能取决于Java日志框架的选择以及日志框架的输出是如何格式化的。
logstash文档提供了示例log4j输入解析器:http://logstash.net/docs/1.1.9/inputs/log4j
input {
log4j {
add_field => ... # hash (optional), default: {}
charset => ... # string, one of ["ASCII-8BIT", "UTF-8", "US-ASCII", ...] (optional), default: "UTF-8"
data_timeout => ... # number (optional), default: 5
debug => ... # boolean (optional), default: false
format => ... # string, one of ["plain", "json", "json_event"] (optional)
host => ... # string (optional), default: "0.0.0.0"
message_format => ... # string (optional)
mode => ... # string, one of ["server", "client"] (optional), default: "server"
port => ... # number (required)
tags => ... # array (optional)
type => ... # string (required)
}
}
答案 2 :(得分:0)
如文档here所示,您可以使用任何日志文件,它来自哪个来源无关紧要。您必须将输入用作文件并相应地配置其他内容!
input {
file {
## Your configuration goes here like file path
## and other config, check documentation
}
}