log4j does not require framework logs struts

2019-08-27 19:33发布

问题:

I am creating a web application in struts2 using NetBeans IDE.

Now, i need to use log4j in my application and i have successfully created log4j.properties file under WEB-INF/classes.

This is my log4j.properties file :-

      # Define the root logger with appender file
        log4j.rootLogger = FATAL,FILE

        # Define the file appender
          log4j.appender.FILE=org.apache.log4j.FileAppender
          log4j.appender.FILE.File=F:\\Projects\\TinyStars\\NetbeansProject\\tinystarsbak\\web\\logs\\tinystar_log.out

         # Define the layout for file appender
        log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
        log4j.appender.FILE.layout.conversionPattern=[%-5p][%d{dd-MM-yyyy  HH:mm:ss}]%m%n

I have logged all my messages using appropriate log4j hierarchy like Debug, warn, error etc.

But along with my logging messages i am also getting thousands of (maybe framework related) logs. And this behavior is making my log file very bulky.

I strictly don't want any logs messages apart from what i give explicitly in my application.

Appreciate the help. Thanks in advance.

回答1:

Try this:

# Define the root logger with appender file
log4j.rootLogger = WARN,FILE

log4j.logger.your.package=DEBUG

It should set the default log level to WARN (ie for all frameworks), and DEGUB log level for your packages.



标签: struts2 log4j