master
luffy9412 7 years ago
parent e39ad0113b
commit 6129fbdb06
  1. 12
      pom.xml
  2. 4
      src/main/resources/log4j2.xml
  3. 35
      src/test/java/JunitTest.java

@ -90,12 +90,24 @@
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-web</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<build>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60" status="debug" >
<?xml version="1.0" encoding="UTF8"?>
<Configuration monitorInterval="50" status="INFO" >
<Properties>
<Property name="pattern">%d{yyyy-MM-dd HH:mm:ss} %p %l%n%m%n</Property>
</Properties>

@ -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<org.apache.logging.log4j.core.Logger> 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;
}
}

Loading…
Cancel
Save