我需要一些过滤器来截断我的Java EE应用程序写入的大量日志信息。我正在使用Struts2。
这是我的档案log4j.properties
# Define the root logger with appender file
log = E:\\Uiip\\ProjectWork\\Workspace
log4j.rootLogger = DEBUG, DEBUG_APPENDER
log4j.logger.OTHER_LOGGER=DEBUG, INFO_APPENDER
log4j.additivity.OTHER_LOGGER = false
#File appender for log debug
log4j.appender.DEBUG_APPENDER=org.apache.log4j.FileAppender
log4j.appender.DEBUG_APPENDER.File=${log}/logDebug.txt
#File Appender for log info
log4j.appender.INFO_APPENDER=org.apache.log4j.FileAppender
log4j.appender.INFO_APPENDER.File=${log}/logInfo.txt
# Define the layout for file appender log debug
log4j.appender.DEBUG_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.DEBUG_APPENDER.layout.conversionPattern=%d [%t] %m%n
# Define the layout for file appender log info
log4j.appender.INFO_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.INFO_APPENDER.append=false
log4j.appender.INFO_APPENDER.layout.ConversionPattern= %d [%t] %m%n
每次我启动我的应用程序时,仅对于登录,logdebug文件大约为1MB!
我可以用什么来过滤我的调试日志文件?
P.S。 infofile工作正常!
答案 0 :(得分:0)
您可以将错误级别设置为categorie
,例如:
# This will always be printed (except TRACE level...);
log4j.category.org.apache.struts2=DEBUG
# This will be printed only in INFO or higher
log4j.category.org.springframework.beans.factory.xml=INFO
log4j.category.org.springframework.jdbc.core.StatementCreatorUtils = INFO
# This will be printed only in ERROR or higher
log4j.category.com.opensymphony.xwork2=ERROR
log4j.category.freemarker.beans=ERROR
log4j.category.freemarker.cache=ERROR
详细了解log levels
答案 1 :(得分:0)
您无法使用属性文件配置进行过滤。请改用xml配置。带过滤器的示例配置
<appender name="MyFileAppender" class="org.apache.log4j.FileAppender">
<param name="File" value="myfile.log"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{HH:mm:ss} [%t] %m%n"/>
</layout>
<filter class="org.apache.log4j.varia.StringMatchFilter">
<param name="StringToMatch" value="MyStringToMatch" />
<param name="AcceptOnMatch" value="true" />
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"/>
</appender>