免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2445 | 回复: 4
打印 上一主题 下一主题

[tomcat] tomcat 日志定义请求[已解决] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-05-16 10:17 |只看该作者 |倒序浏览
本帖最后由 signmem 于 2013-05-16 14:38 编辑

现在公司有一堆 tomcat 7 server,  有时候 tomcat 7会 down 机, 重启一下就好了, (环境都是 linux )

我想了解一下, tomcat 7 是否可以像 apache 一定定义 error_log,  或者定义一些 down 机相关的报错日志, 令下次 down 机也有个文件可以分析一下.

当前, 可用日志有

-r--r-- 1 root root  349 May 10 11:37 catalina.2013-05-10.log
-rw-r--r-- 1 root root 787K May 15 15:49 catalina.out
-rw-r--r-- 1 root root    0 Mar 20 16:08 host-manager.2013-03-20.log
-rw-r--r-- 1 root root  526 Mar 20 16:18 localhost.2013-03-20.log
-rw-r--r-- 1 root root  54K May 16 10:15 localhost_access_log.2013-05-16.txt
-rw-r--r-- 1 root root    0 Mar 20 16:08 manager.2013-03-20.log

有好的建议吗?

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
2 [报告]
发表于 2013-05-16 14:16 |只看该作者
catalina.out 就可以看作 error log, 但是你没有激活 log rotate.

有两个小工具可以用:

1. rotatelogs
http://httpd.apache.org/docs/2.2/programs/rotatelogs.html

按天数改名
CustomLog "|bin/rotatelogs -l /var/logs/logfile.%Y.%m.%d 86400" common
This creates the files /var/logs/logfile.yyyy.mm.dd where yyyy is the year, mm is the month, and dd is the day of the month. Logging will switch to a new file every day at midnight, local time.

按日志文件大小改名
CustomLog "|bin/rotatelogs /var/logs/logfile 500M" common
This configuration will rotate the logfile whenever it reaches a size of 500 megabytes.

按日志大小改名,并且附上时间。
ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 500M"
This configuration will rotate the error logfile whenever it reaches a size of 500 megabytes, and the suffix to the logfile name will be created of the form errorlog.YYYY-mm-dd-HH_MM_SS.

2. cronolog
http://www.cronolog.org/

我用第二个工具做例子:

编辑 $TOMCAT_HOME/bin/catalina.sh,每天凌晨自动对 catalina.out 改名 找到下面这段语句:

  if [ "$1" = "-security" ] ; then
    if [ $have_tty -eq 1 ]; then
      echo "Using Security Manager"
    fi
    shift
    "$_RUNJAVA" "$LOGGING_CONFIG" $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" \
        -Dfile.encoding=ISO-8859-1 \
      org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
      | /usr/bin/cronolog "$CATALINA_HOME"/logs/catalina.out.%Y-%m-%d.log >> /dev/null &

  else
    "$_RUNJAVA" "$LOGGING_CONFIG" $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" \
        -Dfile.encoding=ISO-8859-1 \
      org.apache.catalina.startup.Bootstrap "$@" start 2>&1 \
      | /usr/bin/cronolog "$CATALINA_HOME"/logs/catalina.out.%Y-%m-%d.log >> /dev/null &
   fi

论坛徽章:
0
3 [报告]
发表于 2013-05-16 14:38 |只看该作者
非常感谢 rdcwayx  的详细解析.

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
4 [报告]
发表于 2013-05-16 14:38 |只看该作者
有了每天的记录(catalina.out.2013-05-10.log) 你就可以具体问题具体分析。

还有,这个日志轮转设置改好后, 你的tomcat server (不是操作系统啊) 需要重启一下,才可以激活

论坛徽章:
0
5 [报告]
发表于 2013-05-16 14:41 |只看该作者
再次感谢傻瓜式的教学.. 受教了.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP