Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop application logs from logging into catalina.out in Tomcat

Tags:

java

tomcat

The application is running in tomcat and has it own logger using org.apache.commons.logging.Log and org.apache.commons.logging.LogFactory. The logs are getting logged at location specified in log4j.properties file, the location is as follows.

log4j.appender.logger.File=${catalina.base}/logs/applicationlogs.log

The logs are simultaneously added in following file.

/opt/apache-tomcat-8.0.26/logs/catalina.out

How to stop the application logs from getting logged in catalina.out ?

like image 841
rajb Avatar asked Jan 07 '16 06:01

rajb


People also ask

How to stop the application from logging in to Catalina?

To stop the application to log into catalina.out, you can do it by removing the handler. This can be achieved by editting conf/logging.properties and changing:

How do I log a web application running on Apache Tomcat?

A web application running on Apache Tomcat can: Use any logging framework of its choice. Use system logging API, java.util.logging. Use the logging API provided by the Java Servlets specification, javax.servlet.ServletContext.log(...)

How to block writing to Catalina in Tomcat?

Don't forget to restart tomcat. And as suggested in comments, to block writing to catalina.out entirely, set CATALINA_OUT=/dev/null in catalina.sh. Show activity on this post. If your application is using a console appender, then those logs will go to catalina.out. You might want to check that in your application.

Why are my console logs going to Catalina?

If your application is using a console appender, then those logs will go to catalina.out. You might want to check that in your application. To disable logging to catalina.out, you can check discussion: here


5 Answers

You can try to do this:

  1. Edit "$CATALINA_BASE"/bin/catalina.sh file
  2. Find CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
  3. Replace with new path.

Don't forget to restart tomcat.

And as suggested in comments, to block writing to catalina.out entirely, set CATALINA_OUT=/dev/null in catalina.sh.

like image 51
m.aibin Avatar answered Sep 30 '22 05:09

m.aibin


I believe the recommended way to "augment" catalina.sh (catalina.bat on Windows) is to:

  1. Create or update a script in ${CATALINA_BASE}/bin called setenv.sh (setenv.bat)
  2. Add a line to set: CATALINA_OUT=/dev/null as noted above.
  3. This script will be executed before executing catalina.sh/bat which will use any vars set. This is also the correct way to add to the CLASSPATH, add JAVA_OPTS, etc. without messing with catalina.sh/bat directly, which may be updated (overriden) with each tomcat upgrade.
like image 37
PST Avatar answered Sep 30 '22 04:09

PST


If your application is using a console appender, then those logs will go to catalina.out. You might want to check that in your application. To disable logging to catalina.out, you can check discussion: here

like image 23
VivekJ Avatar answered Sep 30 '22 04:09

VivekJ


  1. Find CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out in catalina.sh $CATALINA_BASE/bin
  2. Set CATALINA_OUT=/dev/null
  3. Restart Tomcat

You will see log file created as per your log configuration.

like image 29
jprism Avatar answered Sep 30 '22 06:09

jprism


I'm using tomcat 7.0.50 and I've done following configuration. To stop the application to log into catalina.out, you can do it by removing the handler. This can be achieved by editting conf/logging.properties and changing:

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

to

.handlers = 1catalina.org.apache.juli.FileHandler

Hope this helps. Let me know if I'm missing something.

like image 28
Nikunj Avatar answered Sep 30 '22 06:09

Nikunj