参考:

http://my.oschina.net/shootercn/blog/15534


最近从jetty6升级到了jetty7发现硬盘空间动不动就满了,我找... 我找.... 我找原因.... 发现是jetty7 logs目录搞得鬼,仅仅是个开发环境,1天1GB的日志,疯了! 这要是弄到生产环境还不完蛋啦!!我相信jetty的开发者不会这么缺心眼的、少智慧的,于是乎googling.....


E文太差先找中文的,发现了两位网友写的文章,说jetty自己实现了log系统,需要复写这个类.....  当时晕倒,不用这么麻烦吧。。。 于是觉然的开始 googling E文,终于找到了解决办法


jetty7有两套log系统,默认使用自己的 org.eclipse.jetty.util.log 如果配置来log4j则使用log4j。


在${jetty.home}/lib/ext 放入log4j jar包


在.jettyrc中加入 (jettyrc是什么我就不解释了)


-Dlog4j.configuration=file:/home/jetty/app/jetty7/resources/log4j.properties


# This is not needed by Jetty - but it helps with many web apps.

 

log4j.rootLogger=WARN, stdout

 

log4j.appender.stdout=org.apache.log4j.RollingFileAppender

log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} [%p] %t $

log4j.appender.stdout.File=${log4j.logdir}/stderrout.log

log4j.appender.stdout.MaxFileSize=204800KB

log4j.appender.stdout.MaxBackupIndex=10


 


之后修改etc/jetty-logging.xml


<?xml version="1.0"?>

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

 

 

<!-- =============================================================== -->

<!-- Configure stderr and stdout to a Jetty rollover log file        -->

<!-- this configuration file should be used in combination with      -->

<!-- other configuration files.  e.g.                                -->

<!--    java -jar start.jar etc/jetty-logging.xml                    -->

<!-- =============================================================== -->

<Configure id="Server" class="org.eclipse.jetty.server.Server">

 

    <New id="ServerLog" class="java.io.PrintStream">

      <Arg>

        <New class="org.eclipse.jetty.util.RolloverFileOutputStream">

          <Arg><Property name="jetty.logs" default="/var/log/jetty"/>/yyyy_mm_dd.stderrout.log</Arg>

          <Arg type="boolean">false</Arg>

          <Arg type="int">30</Arg>

          <Arg><Call class="java.util.TimeZone" name="getTimeZone"><Arg>GMT</Arg></Call></Arg>

          <Get id="ServerLogName" name="datedFilename"/>

        </New>

      </Arg>

    </New>

 

    <Call class="org.eclipse.jetty.util.log.Log" name="info"><Arg>Redirecting stderr/stdout to <Ref id="ServerLogName"/></Arg></Call>

    <Call class="java.lang.System" name="setErr"><Arg><Ref id="ServerLog"/></Arg></Call>

    <Call class="java.lang.System" name="setOut"><Arg><Ref id="ServerLog"/></Arg></Call>

 

</Configure>


30我猜是保留的文件个数,这个还有在考证

 


重启jetty,世界清爽啦!~~~


 


英文如下:


With Jetty 7.x you have 2 options.

Both require you to tell Jetty what kind of advanced logger you want to use.

* java.util.logging

* SLF4J


- java.util.logging -

Set a system property called "org.eclipse.jetty.util.log.class" to

"org.eclipse.jetty.util.log.JavaUtilLog" and from there you have all of the

standard java.util.logging configuration options to write to a file / roll

the log / etc ...


- SLF4J -

You'll want to setup SLF4J, have JettyLog use its SLF4J impl.

The mere existence of slf4j-api.jar in the classpath is enough to trigger

this behavior.

Download the slf4j-api.jar of your choice, and put it in

${jetty.home}/lib/ext

Be sure you checkout $ java -jar start.jar --version to see if it will load

into the Jetty Classpath (not your webapps)


Then you'll want to worry about how to take the SLF4J produced logging

events and route them to a logging impl you like.

Check out the docs at http://slf4j.org/ to understand how to setup slf4j.

For example: you can have SLF4J use log4j to write the logs to disk.


I personally like logback http://logback.qos.ch/ opposed to log4j, as it

allows me greater log routing control than log4j alone.

(Example: I can route all commons-logging & log4j & java.util.logging &

slf4j & stderr & stdout generated logging events to a file controlled by the

logback configuration under slf4j)