prashanth
prashanth

Reputation: 445

How to read tomcat logs with logstash

I am trying to configure logstash. In the wiki I found we can read apache or other systems logs. What is the configuration and steps to read tomcat logs.

Upvotes: 5

Views: 7949

Answers (3)

mp911de
mp911de

Reputation: 18119

Tomcat uses Java-Util-Logging.

You can use a direct GELF appender to submit logs from Tomcat to logstash.

You need some changes in your startup-script and the logger config (and two jars):

/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

See also Changes for logstash-gelf with Tomcat

Upvotes: 2

Casey Watson
Casey Watson

Reputation: 52682

This will likely depend on choice of Java logging framework and how the output from the logging framework is formatted.

The logstash docs give an example log4j input parser: 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)
  }
}

Upvotes: 1

Vishal Biyani
Vishal Biyani

Reputation: 4407

As documented here, you can use ANY log file, it does not matter what source it comes from. You will have to use the input as file and configure other things accordingly!

input {
  file {
## Your configuration goes here like file path 
## and other config, check documentation
}
}

Upvotes: 0

Related Questions