当前位置: 首页 > 知识库问答 >
问题:

TomEE和Log4j RollingFileAppender

龚博涛
2023-03-14

我使用log4j RollingFileAppender根据文件大小滚动日志文件。我们设置的最大文件大小是"10 MB"。它在tomcat 6中运行良好,但是当我们迁移到TomEE Plus时...日志文件滚动不会发生...文件大小继续增长。

log4j配置如下:

html prettyprint-override"><?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'>

	<!-- Not needed for Production -->
	<appender name="CA" class="org.apache.log4j.ConsoleAppender">
		<param name="Threshold" value="DEBUG" />
		<param name="encoding" value="UTF-8" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>

	<!-- Appender to log Gateway information messages -->
	<appender name="FA_GATEWAY_INFO" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/freshgate_info.log" />
		<param name="encoding" value="UTF-8" />
		<param name="MaxFileSize" value="10MB" />
		<param name="MaxBackupIndex" value="25" />
		<param name="Threshold" value="INFO" />
		<layout class="org.apache.log4j.PatternLayout">
			<!-- For production use this -->
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
			<!-- For Development use this pattern -->
			<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern" 
				value="%-4r [%t] %-5p %c %x - %m%n" /> -->
		</layout>
		<filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="DEBUG" />
			<param name="AcceptOnMatch" value="false" />
		</filter>
		<filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="WARN" />
			<param name="AcceptOnMatch" value="false" />
		</filter>
		<filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="ERROR" />
			<param name="AcceptOnMatch" value="false" />
		</filter>
		<filter class="org.apache.log4j.varia.LevelMatchFilter">
			<param name="LevelToMatch" value="FATAL" />
			<param name="AcceptOnMatch" value="false" />
		</filter>
	</appender>


	<!-- Appender to log Gateway information messages -->
	<appender name="FA_GATEWAY_DEBUG" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/freshgate_debug.log" />
		<param name="encoding" value="UTF-8" />
		<param name="MaxFileSize" value="10MB" />
		<param name="MaxBackupIndex" value="25" />
		<param name="Threshold" value="DEBUG" />
		<layout class="org.apache.log4j.PatternLayout">
			<!-- For production use this -->
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
			<!-- For Development use this pattern -->
			<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern" 
				value="%-4r [%t] %-5p %c %x - %m%n" /> -->
		</layout>
	</appender>


	<!-- Appender to log bC scale command messages -->
	<appender name="FA_BC_SCALE_COMMAND_DEBUG" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/bc_scale_command_debug.log" />
		<param name="encoding" value="UTF-8" />
		<param name="MaxFileSize" value="5MB" />
		<param name="MaxBackupIndex" value="25" />
		<param name="Threshold" value="DEBUG" />
		<layout class="org.apache.log4j.PatternLayout">
			<!-- For production use this -->
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
			<!-- For Development use this pattern -->
			<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern" 
				value="%-4r [%t] %-5p %c %x - %m%n" /> -->
		</layout>
	</appender>


	<!-- Appender to log Gateway error messages -->
	<appender name="FA_GATEWAY_ERROR" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/freshgate_error.log" />
		<param name="encoding" value="UTF-8" />
		<param name="Threshold" value="ERROR" />
		<param name="MaxFileSize" value="1MB" />
		<param name="MaxBackupIndex" value="5" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>

	<logger name="com.mt.gw">
		<level value="DEBUG" />
		<appender-ref ref="FA_GATEWAY_DEBUG" />
		<appender-ref ref="FA_GATEWAY_INFO" />
		<appender-ref ref="FA_GATEWAY_ERROR" />
	</logger>

	<logger name="BcScaleCommandLogger">
		<level value="DEBUG" />
		<appender-ref ref="FA_BC_SCALE_COMMAND_DEBUG" />
	</logger>

	<!-- Blocks the hibernate table creation logs -->
	<logger name="com.mt.gw.core.bl.persistence">
		<level value="INFO" />
	</logger>

	<!-- Blocks hibernate logs -->
	<logger name="org.hibernate">
		<level value="ERROR" />
	</logger>

	<!-- Blocks both Struts and Catalina logs -->
	<logger name="org.apache">
		<level value="ERROR" />
	</logger>

	<!-- Blocks c3po connection pooling log messages -->
	<logger name="com.mchange">
		<level value="ERROR" />
	</logger>

	<!-- Blocks Quartz Scheduler logs -->
	<logger name="org.quartz">
		<level value="ERROR" />
	</logger>

	<!-- Not needed for Production -->

	<root>
		<level value="DEBUG" />
		<appender-ref ref="CA" />
	</root>

	<!-- Appender to log bC TAF messages -->
	<appender name="FA_BC_TAF_DEBUG_LOGGER" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/bc_taf_debug.log" />
		<param name="encoding" value="UTF-8" />
		<param name="MaxFileSize" value="10MB" />
		<param name="MaxBackupIndex" value="25" />
		<param name="Threshold" value="DEBUG" />
		<layout class="org.apache.log4j.PatternLayout">
			<!-- For production use this -->
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
			<!-- For Development use this pattern -->
			<!-- <param name="ConversionPattern" value="%m%n" /> <param name="ConversionPattern" 
				value="%-4r [%t] %-5p %c %x - %m%n" /> -->
		</layout>
	</appender>

	<logger name="BcTafLogger">
		<level value="DEBUG" />
		<appender-ref ref="FA_BC_TAF_DEBUG_LOGGER" />
	</logger>
	
	<appender name="FA_TAF_LOGGER_DEBUG" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/taf_debug.log" />
		<param name="encoding" value="UTF-8" />
		<param name="MaxFileSize" value="10MB" />
		<param name="MaxBackupIndex" value="25" />
		<param name="Threshold" value="DEBUG" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>
	
	<appender name="FA_TAF_LOGGER_ERROR" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/taf_error.log" />
		<param name="encoding" value="UTF-8" />
		<param name="Threshold" value="ERROR" />
		<param name="MaxFileSize" value="1MB" />
		<param name="MaxBackupIndex" value="5" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>

	<logger name="TafLogger">
		<level value="DEBUG" />
		<appender-ref ref="FA_TAF_LOGGER_DEBUG" />
		<appender-ref ref="FA_TAF_LOGGER_ERROR" />
	</logger>
	
	<appender name="FA_MANAGER_ERROR" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/manager_error.log" />
		<param name="encoding" value="UTF-8" />
		<param name="Threshold" value="ERROR" />
		<param name="MaxFileSize" value="1MB" />
		<param name="MaxBackupIndex" value="5" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>
	
	<!-- Appender to log Gateway manager messages -->
	<appender name="FA_GATEWAY_MANAGER" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/manager.log" />
		<param name="encoding" value="UTF-8" />
		<param name="Threshold" value="INFO" />
		<param name="MaxFileSize" value="5MB" />
		<param name="MaxBackupIndex" value="10" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>
	
	<appender name="FA_GATEWAY_MANAGER_DEBUG" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/manager_debug.log" />
		<param name="encoding" value="UTF-8" />
		<param name="Threshold" value="DEBUG" />
		<param name="MaxFileSize" value="5MB" />
		<param name="MaxBackupIndex" value="10" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>
	
	<logger name="com.mt.manager">
		<level value="DEBUG" />
		<appender-ref ref="FA_GATEWAY_MANAGER_DEBUG" />
		<appender-ref ref="FA_GATEWAY_MANAGER" />
		<appender-ref ref="FA_MANAGER_ERROR" />
	</logger>
	
	<appender name="FA_ACTIVEMQ" class="org.apache.log4j.RollingFileAppender">
		<param name="File" value="${gateway.logs}/logs/activemq.log" />
		<param name="encoding" value="UTF-8" />
		<param name="Threshold" value="ERROR" />
		<param name="MaxFileSize" value="1MB" />
		<param name="MaxBackupIndex" value="5" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="[%p] %d{dd MMM hh:mm:ss.SSS aa} %t [%c] - %m%n"/>
		</layout>
	</appender>
	
	<logger name="org.apache.activemq">
		<level value="ERROR" />
		<appender-ref ref="FA_ACTIVEMQ" />
	</logger>
</log4j:configuration>

共有1个答案

慎建本
2023-03-14

我通过分离log4j解决了这个问题。将xml转换为两种不同的配置。这解决了我的问题。

 类似资料:
  • 多年来,我一直试图让托米1.5.2 JAX-RS与杰克逊合作。我想我已经尝试了100种方法。 这是我的最后一次尝试: 我在conf/system.properties中添加了以下内容: 我在托米的 lib 文件夹中添加了: jackson-mapper-asl-1.9.12.jar jackson-core-asl-1.9.12.jar罐 jackson-jaxrs-1.9.12.jar 我在一个

  • 在tome远程上执行具有阿奎利安的测试用例时,我得到以下异常 似乎没有与部署相关的其他异常。使用以下 maven 依赖项 arquillian-junit-container 1.1.9 arquillian-tomee-remote

  • Apache TomEE 是经过 J2EE 6 认证的 Tomcat 企业版本,Tomcat 是目前市场占有率超过 70% 的Java 应用服务器。 Apache TomEE 是 Apache OpenEJB 的一个子项目,为 Tomcat (7.0.27) 增加了一些 Java EE 的特性,无额外的内存要求,兼容 Tomcat 上的所有应用和工具。 Apache TomEE 可让 Java E

  • 根据这里,Log4j2应该与Tomcat7.0.47一起工作。我用的是TomEE Plus 7.0.47。 SLF4J-API-1.7.5.jar log4j-api-2.0-rc1.jar log4j-core-2.0-rc1.jar log4j-SLF4j-impl-2.0-rc1.jar 如果我将配置状态更改为TRACE,我可以看到我的配置文件被拾取,并且配置按预期进行。我还可以看到MBea

  • [warning] 注意 安装前重启一次Web的服务,确保业务重启后可以正常运行,然后再安装G01防护模块; 对于直接修改启动脚本的方式, 请先备份启动脚本, 再做修改, 以备出现问题时, 还原使用。 Web容器使用的Java(jdk或jre)的版本需 1.6 及以上,暂不支持“敏感词过滤”和“防多线程下载”功能。 Windows安装说明 官网Tomcat JTM套件 其它版本 Linux安装说明

  • 因此,我试图找到任何参考文档或使用这三者的重要示例。 我发现的“最好的”是: TomEE/OpenEJB JAXRS 重构 有关 TomEE 和 JAXRS 配置的一些提示 TomEE文档根本没有列出Jax-RS,我只能找到一些包含单个endpoint类的例子 在哪里可以找到配置选项的全面参考? 主要的问题是,当使用独立的CXF时,我知道如何做大多数我想做的事情,但我几乎不知道JAX-RS在Tom