Gaurav Agarwal
Gaurav Agarwal

Reputation: 19102

Export Tomcat Catalina Logs to external server

I am using Tomcat 7.x as my web server and I am using java.util.logging and JULI for logging. This Tomcat server is hosted an Amazon EC2 instance which runs Ubuntu.

The Problem is whenever I wish to see the logs (in catalina.log file) I have go through a very time consuming process of copying, chowing and then downloading the files to my local machine before I can see them. (I can use utilities like nano or vi but they do not help much)

My Question Can I automatically exports the logs to some external server and view them straight away. Some thing similar to Bugsense for ACRA reports in Android.

Upvotes: 0

Views: 1698

Answers (3)

Ranjith MRK
Ranjith MRK

Reputation: 11

You could use logstash or fluentd to stream the logs and load into your prefered target, say Elastic Search. You could visualize or search through the logs from elasticsearch using visualization tools like Kibana or Graylog

Upvotes: 0

Guido Simone
Guido Simone

Reputation: 7952

You could create a servlet to run in Tomcat to read the logs and display them in your web browser. Or if the file is large, zip it up and allow you to download it.

Use the environment variable catalina.base to determine the base directory and then gather up logs/catalina.log.

[update]

The best approach would depend on your background. If you are comfortable doing a basic, no-frills servlet, start with the simplest design that could possibly work such as:

class LogServlet extends HttpServlet
{
   @Override
   protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
   {
      File logFile = new File(System.getProperty("catalina.base"), "logs/catalina.log");
      String contents = FileUtils.readFileToString(logFile);
      PrintWriter out = new PrintWriter(resp.getOutputStream());
      out.println(contents);
   }
}

I am using commons-io to simplify reading the log file, but otherwise it's just the Java servlet framework.

Upvotes: 2

xeye
xeye

Reputation: 1256

rsync then periodically use a cron job on the server you want or use some tool like collectd.

Upvotes: 0

Related Questions