background
If the log files generated by tomcat are not processed in segmentation, they will often lead to larger and larger files, affecting efficiency. At the same time, if you need to find log files, it is also difficult to find in such a large log file. It is best to divide the log files by day. Here is a way to split the log file using cronolog
method
Install cronolog-1.6.
Download address:cronolog-1.6.
tar -zxvf cronolog-1.6. cd cronolog-1.6.2 ./configre # --prefix=/opt/cronolog , you can specify the installation directory, by default in /usr/local/sbin/cronologmake make install
Tomcat configuration
Previous versions of Tomcat7:
vim tomcat/bin/ # Comment out (#)touch “$CATALINA_BASE”/logs/ # Modify two files in tomcat bin directory “$@” start \ >> “$CATALINA_BASE”/logs/ 2>&1 & # for "$@" start 2>&1 \ | /usr/local/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-% >> /dev/null &
After completing it, restart Tomcat and you can see the logs in the logs file with style .2015-09-13.
Versions after Tomcat7:
vi tomcat/bin/ #first stepWill if [ -z "$CATALINA_OUT" ] ; then CATALINA_OUT="$CATALINA_BASE"/logs/ fi Modified to if [ -z "$CATALINA_OUT" ] ; then CATALINA_OUT="$CATALINA_BASE"/logs/catalina.%Y-%m-% fi # Step 2Will touch "$CATALINA_OUT" Change to #touch "$CATALINA_OUT" echi "$CATALINA_OUT" # Step 3Will "$@" start \ >> "$CATALINA_OUT" 2>&1 & Modified to "$@" start 2>&1 \ | /usr/local/sbin/cronolog "$CATALINA_OUT" >> /dev/null &
After completing it, restart Tomcat and you can see that the logs with style .2021-09-01 exists in the logs file.
This is the end of this article about Tomcat8 using cronolog for log splitting. For more related Tomcat cronolog log splitting content, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!