Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View Tomcat log files in a browser

I need to somehow expose the Tomcat log files to a browser. I know that is not secure, but that's what's being requested.

I have considered making a hard link from the log location, such as tomcat/webapps/ROOT/html/catalina.out -> mydir/logs/catalina.out, but I don't think that's a good solution (even though it does work). Is there an established way of exposing Tomcat log files to a browser?

like image 509
Nova Avatar asked Aug 21 '13 21:08

Nova


People also ask

How do I view tomcat logs?

By default, the Tomcat HTTP Access Logs are stored in the dotserver/tomcat-X.x/logs/ folder within the dotCMS distribution, and the files are named dotcms_access. YYYY-MM-DD. log, where the YYYY-MM-DD in the file name is replaced by the date of the log file.

How do I view tomcat logs in Windows?

Apache Tomcat Logs Location in Windows By default, Apache Tomcat logs are stored in the install_dir/logs where the install_dir refers to the Apache Tomcat installation directory. The log files are stored in the logs directory.

How do I open tomcat in browser?

Have you installed Tomcat, you can launch Monitor Tomcat tool, and start the web service, Then open a web browser, and input in the address bar the URL http://localhost:8080, then you can view Tomcat documentation or start using Tomcat.

How do I view Catalina logs?

By default, the catalina. out file is located in the logs directory under Tomcat's root directory. For example, /opt/netiq/idm/apps/tomcat/logs/catalina.


1 Answers

This modification to distribution configurations will expose Tomcat logs over HTTP via the services of the Tomcat DefaultServlet. Confirmed with Tomcat distributions of 7.0.56, 8.0.24.

For purposes of this example, the canonical Tomcat distribution is given to be unpacked to /opt/tomcat.

In /opt/tomcat/conf/Catalina/localhost create the file logs.xml with this content:

<Context override="true" docBase="/opt/tomcat/logs" path="/logs" />

Restart Tomcat. Browse to a log file you know is there, e.g.

  • localhost:8080/logs/catalina.out

If you additionally desire to be able to browse the listing of logs, suggest this additional configuration change.

Edit /opt/tomcat/conf/web.xml. Where the listings parameter is configured, turn it on by setting its value to true:

...
<servlet>
...
<init-param>
<param-name>listings</param-name>
<param-value>true</param-value>
</init-param>
...

Restart your tomcat for changes to take effect. Expect to see a list of log files as clickable links when conducting this test in a browser

  • localhost:8080/logs/

These settings are likely not desirable for some production environments due to either security or performance/resource usage concerns.

In some senses a rephrasing of this item: Simplest way to serve static data from outside the application server in a Java web application

Learn more (at the ragged edges of this question)

  • Configure Symlinks for single directory in Tomcat
  • How to config Tomcat to serve images from an external folder outside webapps?

And the ever helpful docs

  • http://tomcat.apache.org/tomcat-7.0-doc/config/context.html
  • http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html
like image 173
David Fackler Avatar answered Sep 16 '22 21:09

David Fackler