【发布时间】:2016-05-27 22:11:27
【问题描述】:
我有一个 Log4j2.xml 定义为:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Properties>
<Property name="log-path">E:/MLM/MLMDomain/servers/${sys:weblogic.Name}/logs</Property>
</Properties>
<Appenders>
<RollingFile name="RollingFile" fileName="${log-path}/MLMServices.log" filePattern="${log-path}/MLMServices-%d{yyyy-MM-dd}-%i.log" >
<PatternLayout>
<pattern>%d{dd/MMM/yyyy HH:mm:ss.SSS} [%-5level] [%c{1}] %m%n</pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="1 MB" />
</Policies>
<DefaultRolloverStrategy max="30"/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="root" level="debug" additivity="false">
<appender-ref ref="RollingFile" level="debug"/>
</Logger>
<Root level="debug" additivity="false">
<AppenderRef ref="RollingFile"/>
</Root>
</Loggers>
</Configuration>
据我了解,当我的日志文件达到 1MB 时,它应该滚动到新的。要翻转的文件数应该是30个。但是,如果您查看我下面的日志,则其中有40多个,并且所有最新的文件都接近30MB。当前日志文件 MLMServices.log 包含从 2016 年 4 月 13 日到现在的条目。事实上,最后几个日志文件 MLMServices-2016-05-24-4.log、MLMServices-2016-05-24-3.log 等都有 2016 年 4 月 13 日的条目。创建新日志文件时,它复制前一个条目中的条目,然后附加更多条目。所以逐渐地,每个新的日志文件都会比前一个稍大。
04/28/2016 04:26 PM 1,050,290 MLMServices-2016-04-28-1.log
04/28/2016 06:02 PM 1,188,994 MLMServices-2016-04-28-2.log
04/29/2016 12:11 PM 1,315,487 MLMServices-2016-04-29-1.log
04/29/2016 12:21 PM 1,364,634 MLMServices-2016-04-29-2.log
04/29/2016 12:30 PM 1,413,781 MLMServices-2016-04-29-3.log
04/29/2016 05:02 PM 1,472,373 MLMServices-2016-04-29-4.log
05/03/2016 04:16 PM 2,521,056 MLMServices-2016-05-03-1.log
05/04/2016 04:35 PM 3,379,593 MLMServices-2016-05-04-1.log
05/05/2016 01:47 PM 3,715,698 MLMServices-2016-05-05-1.log
05/05/2016 02:47 PM 3,858,833 MLMServices-2016-05-05-2.log
05/06/2016 02:13 PM 4,908,446 MLMServices-2016-05-06-1.log
05/06/2016 02:46 PM 4,927,119 MLMServices-2016-05-06-2.log
05/06/2016 03:04 PM 5,068,610 MLMServices-2016-05-06-3.log
05/06/2016 05:07 PM 5,267,743 MLMServices-2016-05-06-4.log
05/10/2016 03:16 PM 8,598,426 MLMServices-2016-05-10-1.log
05/10/2016 03:16 PM 11,280,054 MLMServices-2016-05-10-2.log
05/10/2016 03:16 PM 12,328,667 MLMServices-2016-05-10-3.log
05/10/2016 03:16 PM 13,377,298 MLMServices-2016-05-10-4.log
05/10/2016 03:16 PM 14,425,881 MLMServices-2016-05-10-5.log
05/10/2016 03:16 PM 15,474,464 MLMServices-2016-05-10-6.log
05/10/2016 03:16 PM 16,523,059 MLMServices-2016-05-10-7.log
05/10/2016 03:16 PM 17,571,640 MLMServices-2016-05-10-8.log
05/10/2016 03:53 PM 18,620,566 MLMServices-2016-05-10-9.log
05/11/2016 02:37 PM 19,002,926 MLMServices-2016-05-11-1.log
05/11/2016 02:44 PM 19,088,104 MLMServices-2016-05-11-2.log
05/11/2016 03:50 PM 19,375,771 MLMServices-2016-05-11-3.log
05/14/2016 01:51 PM 20,424,415 MLMServices-2016-05-14-1.log
05/16/2016 12:52 PM 21,473,018 MLMServices-2016-05-16-1.log
05/17/2016 07:01 PM 22,521,671 MLMServices-2016-05-17-1.log
05/18/2016 09:57 AM 23,570,365 MLMServices-2016-05-18-1.log
05/18/2016 02:03 PM 24,619,048 MLMServices-2016-05-18-2.log
05/18/2016 08:05 PM 25,667,655 MLMServices-2016-05-18-3.log
05/19/2016 09:18 AM 25,786,502 MLMServices-2016-05-19-1.log
05/19/2016 02:00 PM 26,259,036 MLMServices-2016-05-19-2.log
05/19/2016 05:52 PM 26,593,795 MLMServices-2016-05-19-3.log
05/19/2016 06:26 PM 26,671,744 MLMServices-2016-05-19-4.log
05/20/2016 03:30 PM 27,191,829 MLMServices-2016-05-20-1.log
05/20/2016 05:27 PM 28,240,467 MLMServices-2016-05-20-2.log
05/23/2016 06:10 PM 29,204,271 MLMServices-2016-05-23-1.log
05/24/2016 09:55 AM 29,338,523 MLMServices-2016-05-24-1.log
05/24/2016 10:31 AM 29,441,164 MLMServices-2016-05-24-2.log
05/24/2016 12:04 PM 29,556,676 MLMServices-2016-05-24-3.log
05/24/2016 12:05 PM 29,577,736 MLMServices-2016-05-24-4.log
05/20/2016 05:27 PM 29,734,763 MLMServices.log
这不是我想要的行为。我只希望每个日志文件限制为 1MB,并且我想最多保留 30 个日志文件。我在哪里配置出错了?
提前致谢
已编辑:我实际上已经在 weblogic.xml 中指定了 log4j2
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
http://xmlns.oracle.com/weblogic/weblogic-web-app/1.7/weblogic-web-app.xsd">
<wls:context-root>XXXXXX</wls:context-root>
<wls:library-ref>
<wls:library-name>jax-rs</wls:library-name>
<wls:specification-version>2.0</wls:specification-version>
<wls:exact-match>false</wls:exact-match>
</wls:library-ref>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j</wls:package-name>
<wls:package-name>log4j</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
【问题讨论】:
标签: log4j2 weblogic12c