1, the first page in the Web-inf directory under the new log4j.properties configuration file, the contents are as follows:
log4j.rootcategory = Info,dailyfile log4j.appender.dailyFile =org.apache.log4j.dailyrollingfileappenderlog4j.appender.dailyfile.threshold = DEBUG log4j.appender.dailyFile.ImmediateFlush =true log4j.appender.dailyfile.append =true log4j.appender.dailyfile.file =c:/logs/ Log.loglog4j.appender.dailyFile.DatePattern =yyyy-mm-dd .log " = Org.apache.log4j.PatternLayoutlog4j.appender.dailyFile.layout.ConversionPattern =[%-5p]%d (%r)--[%t]% L:%m%x%n
2. Modify the Web. XML configuration to add the following configuration to the first-level node:
<context-param> <param-name>log4jConfigLocation</param-name> <param-value>/ Web-inf/log4j.properties</param-value></context-param><listener> <listener-class > org.springframework.web.util.Log4jConfigListener </listener-class> </listener>
3. Use in Java files:
Logger log = Logger.getlogger (this. GetClass (). GetName ()); Log.info (" Logger "); Log.error ("error"); // log.debug ("Debug");
Debug is not written to the log here. See Log4j.properties for detailed configuration instructions.
Spring MVC log4j Configuration