使用jetty和log4j

时间:2015-09-08 14:25:09

标签: logging log4j jetty version

我一直在努力解决将log4j写入日志文件的问题。当服务器启动时,Log4j 会创建日志文件,但文件仍为空

当我从maven插件运行jetty时,数据 写入文件。

这是启动jetty的命令行:

java -server -Djava.awt.headless=true -Dcom.sun.management.jmxremote -Xshare:off -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.local.only=false -Djava.rmi.server.hostname=192.168.26.69 -Xms1200m -Xmn500m -Xmx16384m -XX:MaxGCPauseMillis=50 -DentityExpansionLimit=0 -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=80 -Djetty.home=/opt/jetty -Djava.io.tmpdir=/var/cache/jetty/data -jar /opt/jetty/start.jar --pre=etc/jetty-logging.xml OPTIONS=Server,jmx etc/jetty-jmx.xml path=/opt/pointsecs/conf

这是命令unzip -l RealTimeBidder.war | grep log

的输出
   156354  2015-09-08 06:27   WEB-INF/lib/aws-java-sdk-logs-1.9.32.jar
    61829  2015-09-08 06:27   WEB-INF/lib/commons-logging-1.2.jar
   481535  2015-09-08 06:22   WEB-INF/lib/log4j-1.2.16.jar
     8869  2015-09-08 06:27   WEB-INF/lib/slf4j-log4j12-1.7.5.jar
     1895  2015-09-08 13:18   WEB-INF/classes/log4j.xml

Jetty版本:8.1.9.v20130131

Java build:build 1.8.0_45-b14 最后这是log4j.xml文件的内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="RtbFile" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="logs/rtb.log" />
        <param name="Append" value="false" />
        <param name="MaxBackupIndex" value="30" />
        <param name="MaxFileSize" value="10KB" />
        <layout class="org.apache.log4j.PatternLayout">
            <!-- param name="ConversionPattern" value="%t %-5p %c{2} - %m%n"/ -->
            <param name="ConversionPattern" value="[%p %d{MMdd HH:mm:ss} : %t : %c{1} ] %m%n"/>
        </layout>
    </appender>
    <appender name="ErrorFile" class="org.apache.log4j.RollingFileAppender">
        <param name="File" value="logs/error.log" />
        <param name="Append" value="false" />
        <param name="MaxBackupIndex" value="30" />
        <param name="threshold" value="ERROR" />
        <param name="MaxFileSize" value="1024KB" />
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%p %d{MMdd HH:mm:ss} : %t : %c{1} ] %m%n"/>
        </layout>
    </appender>
    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%p %d{MMdd HH:mm:ss} : %t : %c{1} ] %m%n"/>
        </layout>
    </appender>
    <logger name="com.taptica.rtb" additivity="true">
        <level value="TRACE" />
        <appender-ref ref="RtbFile" />
        <appender-ref ref="ErrorFile" />
    </logger>
    <logger name="org.springframework">
        <level value="ERROR" />
        <appender-ref ref="ErrorFile" />
        <appender-ref ref="CONSOLE" />
    </logger>
    <root>
        <priority value ="debug" />
        <appender-ref ref="CONSOLE" />
    </root>
</log4j:configuration>

0 个答案:

没有答案