Cronolog cutting tomcat logs and logging export methods

Source: Internet
Author: User

Tomcat logs for existing machines over time, the accumulated log reaches several G or more (all of a machine's logs are all together), want to export a time period of the log, through the export script to find the speed is very slow, and the server pressure will be very large.

WORKAROUND: Use the log cutting tool Cronolog to save the log as a different file according to the output per day. When you export the log, the export will be very fast as long as you specify the date.

Steps:

1, Cronolog installation (the installation method is very simple)

#tar-ZXVF cronolog-1.6.2.tar.gz

#cd cronolog-1.6.2

#./configure

#make && make Install

#which Cronolog

/usr/local/sbin/cronolog

The installation to this cronolog is complete and the validation is successful

2. Configure the application of Tomcat cutting to Cronolog

Note: To facilitate the management of multiple Tomcat logs together (the following path is just a reference)

#cd/data/install/tomcat7cluster/tomcats/tomcat_8181/

#cd bin/

#vim catalina.sh

touch  "$CATALINA _out"   if [  "$"  =  "-security"  ] ; then     if [  $have _tty -eq 1 ]; then       echo  "Using security manager"     fi     shift    eval  "\" $_runjava\ " " \ "$LOGGING _config\" "  $LOGGING _manager $ java_opts  $CATALINA _opts       -djava.endorsed.dirs= "\" $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  "[email protected]"   start       >>  "$CATALINA _out"  2>&1  "&"   else    eval  "\" $_runjava\ ""   "\" $LOGGING _config\ ""   $LOGGING _ manager  $JAVA _opts  $CATALINA _opts       -djava.endorsed.dirs= "\" $ Java_endorsed_dirs\ ""  -classpath  "\" $CLASSPATH \ ""        - Dcatalina.base= "\" $CATALINA _base\ ""        -dcatalina.home= "\" $CATALINA _home \ "       -djava.io.tmpdir=" \ "$CATALINA _tmpdir\" "        org.apache.catalina.startup.Bootstrap  "[email protected]"  start 2> &1 | /usr/local/sbin/cronolog /data/install/tomcat7cluster/logs/test81.%Y-%m-%d.log  >> /dev/null&    #  >>  "$CATALINA _out"  2>&1  "&"   fi 

The above 23 lines of modified sections include the path to the Cronolog, and the log storage path, note: 25 lines of code commented out.

After the configuration is complete, restart Tomcat

#./startup.sh

View the path where the log is stored, and whether to generate logs for the current day

#cd /data/install/tomcat7cluster/logs

#ls

Test81.2016-05-20.log

To this log split complete

3. Simple log viewing and export scripts

A. Easy to view, directly execute the script to view the currently refreshed log

#cd/data/install/tomcat7cluster

#vim tail-log.sh (script name)

#!/bin/sh log_dir= "/data/install/tomcat7cluster/logs" log_file= ' Date ' +test81.%y-%m-%d.log ' tail-f ${log_dir}/$ {Log_file}


Save exit, you can try the effect oh.

B. Log Export script

The script location is arbitrary, the exported log location is also arbitrary, here logs in the root of the logs

#vim get-log.sh

    #!/bin/bash    echo -e  "Which day do you  want to log,such as \033[31m2016-05-20\033[0m "    read -p   "please enter: "  a    echo    echo -e  " please enter start time,such as \033[31m16-01-27 14:51:27\033[0m "     read -p  "write down your answers: "  b     echo -e  "please enter stop time,such as \033[31m16-01-27 14:51:27\033[ 0m "    read -p " write down your answers:  " c     echo    read -p  "What name do you want  to save:  " d    tomcat_dir="/data/install/tomcat7cluster/"     log_dir= "${tomcat_dir}/logs/test81. $a. Log "    sednum1= ' grep -n " $b " ${log_dir} |  head -1 | awk -F  ': '   ' {print $1} '     sednum2= ' grep -n  "$c"  ${log_dir} | tail -1 | awk -F  ': '   ' {print  $1} '     sed -n  ' ${sednum1},${sednum2}p '  ${log_dir} > / root/logs/${d}    echo -e  "\033[31m####### #check  logs###########\033[0m"     cho -e  "\033[34mhead\033[0m"     head /root/logs/${d }    sleep 5    echo -e  "\033[34mtail\033[0m"      TAIL /ROOT/LOGS/${D}


#bash get-log.sh
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/80/60/wKiom1c-xR-yKZ7rAAA6ivnNWPA729.jpg "title=" ED7C.tmp.jpg "alt=" Wkiom1c-xr-ykz7raaa6ivnnwpa729.jpg "/>

Note: The different log formats for the Tomcat version will vary, depending on the actual situation.

After the execution is complete, you can go to the saved directory to view it. This concludes the transformation of the Tomcat log.

This article is from the "I Am 喳喳" blog, please be sure to keep this source http://mydnjm.blog.51cto.com/11317639/1775438

Cronolog cutting tomcat logs and logging export methods

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.