|
|
@ -1,6 +1,8 @@ |
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
import org.apache.logging.log4j.LogManager; |
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
import org.apache.logging.log4j.Logger; |
|
|
|
import org.apache.logging.log4j.core.LoggerContext; |
|
|
|
import org.apache.logging.log4j.core.LoggerContext; |
|
|
|
|
|
|
|
import org.apache.logging.log4j.core.config.xml.XmlConfiguration; |
|
|
|
|
|
|
|
import org.pqh.util.Log4jUtil; |
|
|
|
|
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URISyntaxException; |
|
|
@ -10,32 +12,41 @@ import java.net.URISyntaxException; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
public class JunitTest { |
|
|
|
public class JunitTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final boolean flag=init(); |
|
|
|
private static final Logger rootLogger= LogManager.getLogger(); |
|
|
|
private static final Logger rootLogger= LogManager.getLogger(); |
|
|
|
private static final Logger consoleLogger= LogManager.getLogger("org.apache.logging.log4j.test1"); |
|
|
|
private static final Logger consoleLogger= LogManager.getLogger("log1"); |
|
|
|
private static final Logger loggerFile= LogManager.getLogger("org.apache.logging.log4j.test2"); |
|
|
|
private static final Logger loggerFile= LogManager.getLogger("log2"); |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
public static void main(String[] args) { |
|
|
|
// rootLogger.info("rootLogger");
|
|
|
|
|
|
|
|
// consoleLogger.info("consoleLogger");
|
|
|
|
|
|
|
|
// loggerFile.info("loggerFile");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LoggerContext loggerContext= (LoggerContext) LogManager.getContext(false);
|
|
|
|
rootLogger.info("rootLogger"); |
|
|
|
//
|
|
|
|
consoleLogger.info("consoleLogger"); |
|
|
|
|
|
|
|
loggerFile.info("loggerFile"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Collection<org.apache.logging.log4j.core.Logger> loggers=loggerContext.getLoggers();
|
|
|
|
// Collection<org.apache.logging.log4j.core.Logger> loggers=loggerContext.getLoggers();
|
|
|
|
// for(org.apache.logging.log4j.core.Logger logger:loggers){
|
|
|
|
// for(org.apache.logging.log4j.core.Logger logger:loggers){
|
|
|
|
// logger.info(logger.getName());
|
|
|
|
// logger.info(logger.getName());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean init(){ |
|
|
|
|
|
|
|
System.out.println(Log4jUtil.class.getClassLoader()); |
|
|
|
|
|
|
|
System.out.println(XmlConfiguration.class.getClassLoader()); |
|
|
|
LoggerContext loggerContext= (LoggerContext) LogManager.getContext(false); |
|
|
|
LoggerContext loggerContext= (LoggerContext) LogManager.getContext(false); |
|
|
|
try { |
|
|
|
try { |
|
|
|
loggerContext.setConfigLocation(new URI("https://github.com/luffy9412/Bilibili/blob/master/src/main/resources/log4j.properties")); |
|
|
|
URI uri=new URI("http://42.56.70.185:8080/master/testlog.xml"); |
|
|
|
|
|
|
|
loggerContext.setConfigLocation(uri); |
|
|
|
} catch (URISyntaxException e) { |
|
|
|
} catch (URISyntaxException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
// loggerContext.setConfigLocation();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
loggerContext.reconfigure(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|