When log4j is called to output logs in XXX class, the following statement is called at first,
Public static logger = org. Apache. log4j. Logger. getlogger (class name. Class. getname ());
This method can be used to set the Log Level of the class in the configuration file. For example, add the following lines to the configuration file log4j. properties:
Log4j. rootcategory = error, stdout, file -- Overall log output level
Log4j. Logger. AAA. BBB. ccc. xxx = debug -- the log output level of a separate class. If not set, the overall setting is used.
In this way, the log output level of XXX class is different from that of other classes for debug.
Simple encapsulation of log classes, easier to use
package com.cloudclass.test;import org.apache.log4j.Logger;import org.apache.log4j.PropertyConfigurator;public class Log {public Logger loger;private static Log log;private Log(){String filePath = this.getClass().getResource("/").getPath();filePath = filePath.substring(1).replace("bin", "src");loger = Logger.getLogger(this.getClass());PropertyConfigurator.configure(filePath+"log4j.properties"); }static Log getLoger(){if(log!=null)return log;elsereturn new Log();} public static void main(String[] args) { Log log = Log.getLoger(); String str = "test"; log.loger.info("info"); log.loger.info("info is " + str); log.loger.debug("debug"); log.loger.debug("debug is " + str); log.loger.error("error"); log.loger.error("error is " + str); }}