Using Cronolog to split the tomcat log Apache log

Source: Internet
Author: User
Tags locale log log month name apache log

1. Installing Cronolog

Official website Download: http://cronolog.org/usage.html


./configure

Make;make Install


Default installation Location:


# which Cronolog

/usr/local/sbin/cronolog


2. Configure the split Tomcat log

Edit the catalina.sh file under the Tomcat directory bin


# VI bin/catalina.sh


Find the following line


elif ["$" = "start"]; Then


......


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

>> "$CATALINA _out" 2>&1 &


In this elif statement like this line has 2, the first is Tomcat with the "-security" parameter of the start, the second is the default Tomcat boot mode, that is, else the next part, only modify here. In order to use Cronolog cutting, we both modify.


In addition, the touch "$CATALINA _out" this line commented out.


The complete changes are as follows:


# touch "$CATALINA _out"

If ["$" = "-security"]; Then

If [$have _tty-eq 1]; Then

echo "Using Security Manager"

Fi

Shift

"$_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 | /usr/local/sbin/cronolog/usr/local/tomcat/logs/catalina.%y-%m-%d.out >>/dev/null &

# >> "$CATALINA _out" 2>&1 &


Else

"$_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/usr/local/tomcat/logs/catalina.%y%m%d.out >>/dev/null &

# >> "$CATALINA _out" 2>&1 &


Fi


Save exit


Restart the Tomcat service


[Email protected] tomcat]# bin/shutdown.sh

Using catalina_base:/usr/local/tomcat

Using Catalina_home:/usr/local/tomcat

Using Catalina_tmpdir:/usr/local/tomcat/temp

Using Jre_home:/usr/java/jdk1.6.0_29

Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar

[Email protected] tomcat]# bin/startup.sh

Using catalina_base:/usr/local/tomcat

Using Catalina_home:/usr/local/tomcat

Using Catalina_tmpdir:/usr/local/tomcat/temp

Using Jre_home:/usr/java/jdk1.6.0_29

Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar


To see if the log directory generates catalina.yymmdd.out log files


-rw-r--r--1 root root 10537 Jul 10:50 catalina.20140730.out


Configuration Cronolog completed, observing whether there is a new catalina.yymmdd.out log file generated every day, periodically deleting older log files.


Note that Cronolog generates a new log file instead of a fixed-point build when the Catalina.out log has new content.


3. Split Apache logs

Edit the Apache default profile httpd.conf, find the Apache log location, and modify it as follows (this example is divided by day):


Errorlog "|/usr/local/sbin/cronolog/var/log/httpd/error_%y-%m-%d.log"


Customlog "|/usr/local/sbin/cronolog/var/log/httpd/access_%y-%m-%d.log" combined


Save


Restart Apache Service


#/etc/init.d/httpd Restart

stopping httpd: [OK]

Starting httpd: [OK]


Note: Apache log directory permissions by default is 700, can only generate Error_xxxxxx.log log, unable to produce access_xxxxxx.log log, we need to give/VAR/LOG/HTTPD directory other user w permission


# chmod O+W/VAR/LOG/HTTPD


You can see that the Access_xxxxxx.log log is generated in the/VAR/LOG/HTTPD directory.


Knowledge Point: Configured with Cronolog, it does not generate a new log as scheduled at the specified time, and it generates a log precondition that new log files will not be created until new content is available in the log, and no new logs will be created without log content updates.


3.1 Testing


If you want to see the effect quickly, you can follow the following configuration, cycle set to 1 minutes, new log file name plus hour minutes


Customlog "|/usr/local/sbin/cronolog--period=1minutes/var/log/httpd/access_%y-%m-%d-%h%m.log" combined


Restart Apache service to make it effective


Then access the HTTP page so that the new log content appears, as long as there is log update, will generate a new Access_xxxxxx.log file per minute, no log updates will not generate new logs.


-rw-r--r--1 root root 17280 2 01:10 access_2014-08-02-0100.log

-rw-r--r--1 root root 28620 2 01:13 access_2014-08-02-0110.log

-rw-r--r--1 root root 2160 2 01:18 access_2014-08-02-0115.log


Appendix

Cronolog Use Syntax:


Customlog "|/path/to/cronolog [OPTIONS] logfile-spec" [format]


Common options


--period= time


The unit must indicate that the available units include seconds, minutes, hours, days, weeks, months.


Common format


SpecifierDescription

Percenta literal%character

%na new-line character

%ta horizontal tab character

Time fields

%HHour (00..23)

%IHour (01..12)

%pThe locale ' s AM or PM indicator

%Mminute (00..59)

%ssecond (00..61, which allows for leap seconds)

%xThe locale ' s time representation (e.g.: "15:12:47")

%Ztime zone (e.g GMT), or nothing if the time zone cannot be determined

Date fields

%aThe locale ' s abbreviated weekday name (e.g.: Sun.. Sat)

%AThe locale ' s full weekday name (e.g.: Sunday. Saturday)

%bThe locale ' s abbreviated month name (e.g.: Jan. DEC)

%BThe locale ' s full month name, (e.g.: January.. December)

%cThe locale ' s date and time (e.g.: "Sun Dec 14:12:47 GMT 1996")

%dDay of month (01.. 31)

%jDay of the Year (001:366)

%mMonth (01:12)

%uWeek of the year with Sunday as first day of week (00..53, where Week 1 is the week containing the first Sunday of the year)

%WWeek of the year with Monday as first day of week (00..53, where Week 1 is the week containing the first Monday of the year)

%wDay of week (0:6, where 0 corresponds to Sunday)

%xlocale ' s date representation (e.g. today in Britain: "15/12/96")

%yYear without the Century (00:99)

%YYear with the Century (1970:2038)


This article is from the "-it commune" blog, please be sure to keep this source http://guangpu.blog.51cto.com/3002132/1566433

Using Cronolog to split the tomcat log Apache log

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.