kranthi
kranthi

Reputation: 55

How to retrieve the tomcat log file using java

I want to get the log file form tomcat .How to retrieve and get it downloaded from tomcat using java. I am using Java6 and Tomcat7

Upvotes: 2

Views: 2229

Answers (2)

DeepNightTwo
DeepNightTwo

Reputation: 4951

If security is not an issue, you can add tomcat log dir to tomcat web dir and enable file listing. and tomcat will play as an http server and log files are static files. you can list and download the log files.


Back to your original requirements, you want to download tomcat log files ( very likely via http) using java as client.

1) So first there should be a http server. you can use python. go into tomcat log dir and run nohup python -m SimpleHTTPServer 8000 > /dev/null & it will start a http server on current dir using port 8000

2) using your browser to open HOST_IP:8000 and check if the http server works. it should list all log files in the dir.

3) write your java code to connect to the http server and download the file. apache http client should do this job.

Upvotes: 0

Aashutosh Shrivastava
Aashutosh Shrivastava

Reputation: 399

You can retrieve log file using System.getProperty("catalina.base") + "/logs".

Upvotes: 2

Related Questions