Tomcat Catalina.ou Save log file splitting method by day

Source: Internet
Author: User

Ext.: http://tanrishou.blog.163.com/blog/static/1502502009924112045630/

The environment that this article is based on:

Operating systems: Linux (Redhat), Windows (XP, 2003)

JDK version: J2sdk1.4.2_04

Tomcat version: tomcat-5.0.28

Cronolog version: cronolog-1.6.2.tar.gz

Cronolog-1.6.1-win32.zip

The modified Tomcat in this article is saved by the day log file, file format such as: Catalina.2009-06-07.out

Ii. Introduction to Cronolog ( download Cronolog)

Cronolog is a log round-robin (rotation) tool that you can use to divide the logs that are output on Web servers such as Apache, Tomcat, into files saved on a daily or monthly basis.

Cronolog reads the log contents from the standard input and writes them to a log file named in the specified format. The name of the log file can be added to a date tag (such as Catalina.2009-06-07.out), and when the date changes cronolog the previous log file is closed and a log file containing the new date is opened (for example, Catalina.2009-06-08.out).

The Cronolog can be used to perfectly address the problem of catalina.out log files growing in Tomcat and not being removed during Tomcat.

One problem to note is that Cronolog does not switch log files immediately after a date change, but requires a new log output to trigger the Cronolog switch log file. So if you want to delete the 2009-06-07 log file in 2009-06-08, if there is no log output from 00:00 in 2009-06-08 until you perform the delete, the 2009-06-07 log file may still be occupied, causing the deletion to fail.

III. Use Cronolog round robin (rotating) Tomcat logs under Linux

(1) First install Cronolog (cronolog-1.6.2.tar.gz placed under/OPT)

Cd/opt

Gzip–d cronolog-1.6.2.tar.gz

TAR–XVF Cronolog-1.6.2.tar

CD cronolog-1.6.2

./configure--prefix=/usr/local/cronolog//Specify the installation path as you want, or do not specify

Make

Make install

(2) Modifying the Tomcat configuration file

Stop the Tomcat service first, and then modify the following files:

%catalina_home%/bin/catalina.sh

Will

Org.apache.catalina.startup.Bootstrap "[email protected]" start \

>> "$CATALINA _base"/logs/catalina.out 2>&1 &

To be replaced by:

Org.apache.catalina.startup.Bootstrap "[email protected]" Start 2>&1 \

| /usr/local/cronolog/sbin/cronolog "$CATALINA _base"/logs/catalina.%y-%m-%d.out >>/dev/null &

Also delete rows:

Touch "$CATALINA _base"/logs/catalina.out

Restart the Tomcat service after the modification is complete.

Iv. using Cronolog round robin (rotating) Tomcat logs under Windows

(1) Installation Cronolog

Unzip the Cronolog-1.6.1-win32.zip and copy the Cronolog.exe file to the Tomcat Bin directory.

(2) Modifying the Tomcat configuration

Under Windows, Tomcat defaults to outputting the log content directly to the console, not to the Catalina.out file, so it needs to be modified to output the log content to a file.

First modify the%catalina_home%/bin/startup.bat to

Call "%executable%" Start%cmd_line_args%

To be replaced by:

Call "%executable%" Run%cmd_line_args%

Then modify the%catalina_home%/bin/catalina.bat to

REM Execute Java with the applicable properties

If not "%jpda%" = = "goto DOJPDA

If not "%security_policy_file%" = = "goto dosecurity

%_execjava%%java_opts%%catalina_opts%%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "% classpath% "-dcatalina.base="%catalina_base% "-dcatalina.home="%catalina_home% "-djava.io.tmpdir="%CATALINA_ tmpdir% "%mainclass%%cmd_line_args%%action%

Goto END

:d osecurity

%_execjava%%java_opts%%catalina_opts%%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "% classpath% "-djava.security.manager-djava.security.policy=="%security_policy_file% "-Dcatalina.base="%CATALINA_ Base% "-dcatalina.home="%catalina_home% "-djava.io.tmpdir="%catalina_tmpdir% "%mainclass%%CMD_LINE_ARGS%%ACTION%

Goto END

:d OJPDA

If not "%security_policy_file%" = = "goto DOSECURITYJPDA

%_execjava%%java_opts%%catalina_opts%-xdebug-xrunjdwp:transport=%jpda_transport%,address=%jpda_address%,server =y,suspend=n%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "%CLASSPATH%"-Dcatalina.base= "% Catalina_base% "-dcatalina.home="%catalina_home% "-djava.io.tmpdir="%catalina_tmpdir% "%MAINCLASS%%CMD_LINE_ARGS% %action%

Goto END

:d OSECURITYJPDA

%_execjava%%java_opts%%catalina_opts%-xdebug-xrunjdwp:transport=%jpda_transport%,address=%jpda_address%,server =y,suspend=n%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "%CLASSPATH%"- djava.security.manager-djava.security.policy== "%security_policy_file%"-dcatalina.base= "%CATALINA_BASE%"- Dcatalina.home= "%catalina_home%"-djava.io.tmpdir= "%catalina_tmpdir%"%mainclass%%CMD_LINE_ARGS%%ACTION%

Goto END

To be replaced by:

REM Execute Java with the applicable properties

If not "%jpda%" = = "goto DOJPDA

If not "%security_policy_file%" = = "goto dosecurity

%_execjava%%java_opts%%catalina_opts%%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "% classpath% "-dcatalina.base="%catalina_base% "-dcatalina.home="%catalina_home% "-djava.io.tmpdir="%CATALINA_ tmpdir% "%mainclass%%cmd_line_args%%action% |%catalina_base%\bin\cronolog%catalina_base%\logs\catalina.%date:~ 0,10%.out >> Null (should be catalina.%%y-%%m-%%d.out)

Goto END

:d osecurity

%_execjava%%java_opts%%catalina_opts%%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "% classpath% "-djava.security.manager-djava.security.policy=="%security_policy_file% "-Dcatalina.base="%CATALINA_ Base% "-dcatalina.home="%catalina_home% "-djava.io.tmpdir="%catalina_tmpdir% "%mainclass%%CMD_LINE_ARGS%%ACTION% | %catalina_base%\bin\cronolog%catalina_base%\logs\catalina.%date:~0,10%.out >> Null (should be catalina.%%y-%%m-%% D.out)

Goto END

:d OJPDA

If not "%security_policy_file%" = = "goto DOSECURITYJPDA

%_execjava%%java_opts%%catalina_opts%-xdebug-xrunjdwp:transport=%jpda_transport%,address=%jpda_address%,server =y,suspend=n%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "%CLASSPATH%"-Dcatalina.base= "% Catalina_base% "-dcatalina.home="%catalina_home% "-djava.io.tmpdir="%catalina_tmpdir% "%MAINCLASS%%CMD_LINE_ARGS% %action% |%catalina_base%\bin\cronolog%catalina_base%\logs\catalina.%date:~0,10%.out >> null (should be catalina.%% Y-%%m-%%d.out)

Goto END

:d OSECURITYJPDA

%_execjava%%java_opts%%catalina_opts%-xdebug-xrunjdwp:transport=%jpda_transport%,address=%jpda_address%,server =y,suspend=n%debug_opts%-djava.endorsed.dirs= "%java_endorsed_dirs%"-classpath "%CLASSPATH%"- djava.security.manager-djava.security.policy== "%security_policy_file%"-dcatalina.base= "%CATALINA_BASE%"- Dcatalina.home= "%catalina_home%"-djava.io.tmpdir= "%catalina_tmpdir%"%mainclass%%CMD_LINE_ARGS%%ACTION% |% Catalina_base%\bin\cronolog%catalina_base%\logs\catalina.%date:~0,10%.out >> Null (should be catalina.%%y-%%m-%% D.out)

Goto END

Restart Tomcat When you are finished modifying it.

Additions to the Windows environment (2009-06-13):

Writing this article, the configuration under Windows has not been tested, in fact, the above is the wrong wording! Before the log file name under Windows uses "catalina.%y-%m-%d.out" to generate log files like "Catalina.md.out", not the date! However, using the "catalina.%date:~0,10%.out" above to derive the filename is "Catalina.2009-06-13.out", where the date is the date Tomcat started, But the log file does not turn round as the date changes (rotating)!

In fact, regardless of whether it is under Linux or Windows, Cronolog accepts the format of the date as "%y%m%d%h%m". %y table year,%m table month,%d table day,%h table hour,%m table minute. Only by using this format to specify the name of the log output file will cronolog generate a new log file by date and time.

However, there are two things you need to do under Windows (as you can see in the install instructions with CRONOLOG-1.6.1.WIN32):

Configuration for use with NT service:

Transferlog "|c:/apache/bin/convlog.exe C:/apache/logs/access%y%m%d.log"

Configuration for use from command line:

Transferlog "|c:/apache/bin/convlog.exe C:/apache/logs/access%%y%%m%%d.log"

That is, if you start tomcat by command-line mode, the log file name must be "catalina.%%y-%%m-%%d.out" to be correct.

Tomcat Catalina.ou Save log file splitting method by day

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.