How to set filter in the log4j.xml

后端 未结 2 1302
孤独总比滥情好
孤独总比滥情好 2021-01-04 07:15

HI,

In our web application it prints all the logs are printed like Spring and JSF jars files. Which not required for us. How can I set in the log4j.xml file to filte

相关标签:
2条回答
  • 2021-01-04 07:41

    You need to define the own logger and appender for your application. For example, if you need to log the trace message in com.xyz.http.RequestFilter:

    log4j.com.xyz.http.RequestFilter=TRACE, TRACE_APPEND
    
    log4j.appender.TRACE_APPEND=org.apache.log4j.RollingFileAppender
    log4j.appender.TRACE_APPEND.File=example.log
    
    log4j.appender.TRACE_APPEND.MaxFileSize=100KB
    log4j.appender.TRACE_APPEND.MaxBackupIndex=1
    
    log4j.appender.TRACE_APPEND.layout=org.apache.log4j.PatternLayout
    log4j.appender.TRACE_APPEND.layout.ConversionPattern=%p %t %c - %m%n
    

    See more at log4j official manual http://logging.apache.org/log4j/1.2/manual.html

    0 讨论(0)
  • 2021-01-04 07:52

    Log only warning for Spring :

    <logger name="org.springframework">
        <level value="warn"/>
        <appender-ref ref="socket"/>
        <appender-ref ref="stdout"/>
    </logger>
    

    Same for JSF with the jsf package name... javax.faces, org.apache.myfaces, com.sun.faces etc... also, the appender-ref refers to your appenders...

    0 讨论(0)
提交回复
热议问题