'How to stop application logs from logging into catalina.out in 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 ?
Solution 1:[1]
You can try to do this:
- Edit
"$CATALINA_BASE"/bin/catalina.shfile - Find
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out - 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.
Solution 2:[2]
I believe the recommended way to "augment" catalina.sh (catalina.bat on Windows) is to:
- Create or update a script in ${CATALINA_BASE}/bin called setenv.sh (setenv.bat)
- Add a line to set: CATALINA_OUT=/dev/null as noted above.
- 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.
Solution 3:[3]
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
Solution 4:[4]
- Find CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out in catalina.sh $CATALINA_BASE/bin
- Set CATALINA_OUT=/dev/null
- Restart Tomcat
You will see log file created as per your log configuration.
Solution 5:[5]
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.
Solution 6:[6]
Just changing
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out
To
CATALINA_OUT= /dev/null
In catalina.sh is not enough because the CATALINA_OUT variable will be used later in the script and that will cause an error to be thrown (aborting the startup).
What I've done instead was, I went to the command lines themselves and edited them so that the output itself will be redirected to /dev/null
(In Tomcat 9 it's in the if block in line ~447)
$_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-classpath "\"$CLASSPATH\"" \
-Djava.security.manager \
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
I've set the stdout stream to /dev/null
$_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-D$ENDORSED_PROP="\"$JAVA_ENDORSED_DIRS\"" \
-classpath "\"$CLASSPATH\"" \
-Djava.security.manager \
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> /dev/null 2>&1 "&"
Solution 7:[7]
You can try following to disable writing to catalina.out :
- Locate and Edit File: {CATALINA_BASE}/bin/catalina.sh
Locate "CATALINA_OUT" and replace the path with "/dev/null":
/dev/null in Linux is a null device file. This will discard anything written to it.
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out // Original Location
CATALINA_OUT=/dev/null // replace path to /dev/null
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | PST |
| Solution 3 | VivekJ |
| Solution 4 | |
| Solution 5 | m.aibin |
| Solution 6 | svarog |
| Solution 7 | Du-Lacoste |

