how to rotate tomcat logs with cronolog

install cronolog

fedoraproject’s download link, cronolog1.6.2

1
2
3
4
tar zxf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make && make install

configure tomcat

bin/catalina.sh‘s content’

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 1, add ".%Y-%m-%d"
if [ -z "$CATALINA_OUT" ] ; then
CATALINA_OUT="$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out
fi
# 2, comment "touch "$CATALINA_OUT"(located about 370 lines)
#touch "$CATALINA_OUT"
#3, change log redirection
if [ "$1" = "-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 "$@" start \
# >> "$CATALINA_OUT" 2>&1 &
org.apache.catalina.startup.Bootstrap "$@" start 2>&1\
|/usr/local/sbin/cronolog "$CATALINA_OUT" &
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 "$@" start \
# >> "$CATALINA_OUT" 2>&1 &
org.apache.catalina.startup.Bootstrap "$@" start 2>&1\
|/usr/local/sbin/cronolog "$CATALINA_OUT" &
fi

restart tomcat

1
2
3
bin/catalina.sh stop
bin/catalina.sh start
# if can't stop it, go straight to kill it

then, you will see result