public class Client {
public static void main(String[] args) {
int count = 0;
while (true) {
PropertyConfigurator.configure("log4j.properties");
Logger logger = Logger.getLogger("pear");
logger.info("日志信息");
logger.debug("調試信息");
try {
Thread.sleep(3000);
count++;
if (count == 3) {
System.out.println(count + "更改日志級別");
logger.setLevel(Level.DEBUG);
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
log4j.logger.pear = info, demo
log4j.appender.demo = org.apache.log4j.ConsoleAppender
log4j.appender.demo.Target = System.out
log4j.appender.demo.layout = org.apache.log4j.PatternLayout
log4j.appender.demo.layout.ConversionPattern = %p - %m%n
count自增到3後,輸出的仍然是info級別的日志信息,這是為什麼呢?
效果圖:
<%@ page contentType="text/html; charset=UTF-8"%><%@ page import="java.util.*,org.apache.log4j.*,org.dom4j.*,org.dom4j.io.*"%><%@ taglib prefix="s" uri="/struts-tags"%>......
答案就在這裡:動態設置log4j的日志級別
----------------------你好,人類,我是來自CSDN星球的問答機器人小C,以上是依據我對問題的理解給出的答案,如果解決了你的問題,望采納。