Tomcat--catalina-daemon.out log segmentation and Output level control

Source: Internet
Author: User

In order to be more secure, I prefer to use Tomcat to boot (daemon.sh) in a daemon way using jsvc in a production environment. This way, Tomcat itself will generate another log file (catalina-daemon.out) instead of the previous catalina.out. However, there are 2 problems: 1.catalina-daemon.out This file does not automatically cut, and will be wireless increase. 2.catalina-daemon.out log output level can not be changed, a large amount of info information occupies the disk. In order to focus on these two issues deliberately studied, the research process is not professional because of the skill is shallow, please understand.


One. Catalina-daemon.out automatic cutting problem.

The first time to see this problem, the first thought is similar to the Nginx log cutting method. It then found its output path from daemon.sh, about 136 lines.

Test ". $CATALINA _out" =. && catalina_out= "$CATALINA _base/logs/catalina-daemon.out"

Can be changed directly to the directory we specify, and is named in time mode

Test ". $CATALINA _out" =. && catalina_out= "/xxx/catalina-daemon%y-%m-%d.out"

However, using this method each time a change is required to restart Tomcat will not take effect. Tomcat does not have a smooth restart function like Nginx, each reboot requires a reload of the project will directly lead to project interruption, not suitable for online environment use, so pass off.


So Baidu a bit, but did not find too good solution. Online more is through the Cronlog this tool to catalina.out this file segmentation, dead Horse when live horse doctor then tried to imitate use, the file changed to

Test ". $CATALINA _out" =. && catalina_out= "|/usr/local/sbin/cronolog $CATALINA _base/logs/catalina-daemon%y-%m-%d.out"

But it did not come into effect, I do not know whether I used the wrong.


and want me to re-production into a catalina-daemon.out, the previous MV into 123.log (casual name, convenient later more intuitive explanation, the language did not learn) can solve this problem? But I found that without restarting, Tomcat would continue to output the file in 123.log. At that time Baidu had a Linux file marked knowledge, found that there is only inode, and will not produce a unique file identifier. Google a little bit about the idea is that Tomcat will map this file directly into memory, that is, when Tomcat starts the virtual machine, not according to the path + file name of the way to output. So I'm going to change it directly from the memory block? Because of the limited capacity, there is no further research.


Helpless under can only choose one of the most simple method of violence, is a temporary solution to the problem, found on the Internet to copy over, specifically as follows:


However, it is possible to lose a small number of logs, and do not know if there is a better solution. I also saw someone using logrotate, but there was no experiment here. If you have a better way, please feel free to advise.


Two. Catalina-daemon.out output level question

Catalina-daemon.out, like the Catalina.out file, is the log that stores the console output. But the default is the info level, a lot of info information is flooded with the entire file, so we should set the level to warning to block out the output information.

SEVERE (highest value) >warning >info >config >fine >finer >finest (lowest value)

When it comes to changing log the first reaction was to modify the Logging.properties file under Tomcat conf, but found that the change did not take effect.

Returned to read the deamon.sh, found the following 145 lines, log profile path:

If [-Z "$LOGGING _config"]; Then if [-R "$CATALINA _base/conf/logging.properties"];    Then logging_config= "-djava.util.logging.config.file= $CATALINA _base/conf/logging.properties" Else # Bugzilla 45585 Logging_config= "-dnop" Fifi

and line No. 200, start the configuration

     start   )         "$JSVC"  $ jsvc_opts        -java-home  "$JAVA _home"          -user  $TOMCAT _user        -pidfile  " $CATALINA _pid "        -wait  $SERVICE _start_wait_time"          -outfile  "$CATALINA _out"          -errfile  "&1"         -classpath  "$CLASSPATH"          "$LOGGING _config"   $JAVA _opts  $CATALINA _opts         -djava.endorsed.dirs= "$JAVA _endorsed_dirs"          -dcatalina.base= "$CATALINA _base"         - Dcatalina.home= "$CATALINA _homE "        -djava.io.tmpdir=" $CATALINA _tmp "          $CATALINA _main       exit $?

     When the discovery started, it did read the Logging.properties file, and also found that the standard output of the console was output to the $catalina_out below with the error output, but why didn't it take effect after the change? Helpless under can only bite the bullet to see Tomcat source.

     said the truth read the source is really deadly, but found that the source code read the JDK below the logging.properties, the change was found to be invalid. Continue to see

    650) this.width=650; "Src=" http://s5.51cto.com/wyfs02/M01/78/E0/ Wkiol1aenj3trc5haacc9dabzti682.png "title=" (~o@1[) 13u]%l ' Vzp (zvxxw.png "alt=" Wkiol1aenj3trc5haacc9dabzti682.png " />

Found in the source code has been set the log output level for info, can only go to modify the source code to recompile tomcat to take effect?

Later asked a great God to help me to decipher the source code, has found the problem, thanks to the big God small fruit son. Roughly as follows (personal understanding)

     first the Tomcat log has a target followed by a source, The same source can have more than one target output, and multiple sources can also correspond to one output. The configuration files we have changed have actually taken effect, but the corresponding output is not correct. the source of the catalina-deamon.out defined under Jsvc is under the Tomcat Project (WebApp), so you want to modify the output level of catalina-deamon.out only by changing the logging.properties file can take effect if there are multiple items that need to be modified under each item. by the way. Catalina.out the corresponding source is tomcat itself, so changing the configuration file under Tomcat can take effect.

Tomcat--catalina-daemon.out log segmentation and output level control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.