diff --git a/pom.xml b/pom.xml index 91d8903..6c5db3c 100644 --- a/pom.xml +++ b/pom.xml @@ -90,12 +90,24 @@ LATEST + + org.apache.logging.log4j + log4j-web + LATEST + + org.fusesource.jansi jansi LATEST + + commons-io + commons-io + LATEST + + diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 96f54c7..665df5a 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -1,5 +1,5 @@ - - + + %d{yyyy-MM-dd HH:mm:ss} %p %l%n%m%n diff --git a/src/test/java/JunitTest.java b/src/test/java/JunitTest.java index 717ddb9..857399f 100644 --- a/src/test/java/JunitTest.java +++ b/src/test/java/JunitTest.java @@ -1,6 +1,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; 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.URISyntaxException; @@ -10,32 +12,41 @@ import java.net.URISyntaxException; */ public class JunitTest { + + private static final boolean flag=init(); private static final Logger rootLogger= LogManager.getLogger(); - private static final Logger consoleLogger= LogManager.getLogger("org.apache.logging.log4j.test1"); - private static final Logger loggerFile= LogManager.getLogger("org.apache.logging.log4j.test2"); + private static final Logger consoleLogger= LogManager.getLogger("log1"); + private static final Logger loggerFile= LogManager.getLogger("log2"); 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 loggers=loggerContext.getLoggers(); // for(org.apache.logging.log4j.core.Logger logger:loggers){ // 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); 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) { e.printStackTrace(); } - -// loggerContext.setConfigLocation(); - - loggerContext.reconfigure(); + return true; } }