美文网首页
tomcat日志分割(按天分割)

tomcat日志分割(按天分割)

作者: 平_方 | 来源:发表于2018-11-19 16:52 被阅读0次

    安装cronolog

    yum install -y cronolog

    将catalina.sh对应的位置修改如下即可

    (修改前先备份原脚本)

    # touch "$CATALINA_OUT"
      if [ "$1" = "-security" ] ; then
        if [ $have_tty -eq 1 ]; then
          echo "Using Security Manager"
        fi
        shift
        eval $_NOHUP "\"$_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 2>&1 \
          |/usr/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &
      else
        eval $_NOHUP "\"$_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 2>&1 \
          |/usr/sbin/cronolog "$CATALINA_BASE"/logs/catalina.%Y-%m-%d.out >> /dev/null &
      fi
    

    程序日志分割

    log4j.rootLogger=DEBUG,file
    log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
    log4j.appender.file.file=${catalina.home}/logs/app.log
    log4j.appender.file.DatePattern= yyyy-MM-dd'.log'
    log4j.appender.file.layout=org.apache.log4j.PatternLayout
    log4j.appender.file.layout.ConversionPattern=[%p][%d{yyyy-MM-dd HH:mm:ss}][%C{1}:%L] - %m%n
    

    相关文章

      网友评论

          本文标题:tomcat日志分割(按天分割)

          本文链接:https://www.haomeiwen.com/subject/nxdafqtx.html