java日志处理组件log4j--log4j.xml配置详解
<!-- log4j 系统日志-->
注:本资料通过网络查找然后整理而成
首先要对配置文件的各个参数进行说明,这样才能合理的进行配置。
参数意义说明:
配置根Logger
public class Log4jUtil { private static final String configFile = "log4j.xml"; static{ BasicConfigurator.configure(); } public Log4jUtil() { super(); } public static String getConfigFile(){ return configFile; } public static Logger getLogger(Class clazz){ return Logger.getLogger(clazz); } public static Logger getLogger(String strClass){ return Logger.getLogger(strClass); } public static Logger getLogger(String strClass,LoggerFactory loggerFactory){ return Logger.getLogger(strClass, loggerFactory); } }
最后只需在代码中调用即可,格式如下:
public class HelloLog4j { private static Logger logger = Logger.getLogger(HelloLog4j.class); public String getURL(){ logger.info("getURL() ... "); return null; } }
这样log4j就配置成功了。
相关推荐
chw0 2020-11-04
sdaq 2020-07-26
MrLiar 2020-07-07
sdaq 2020-06-16
丨Fanny丨Cri 2020-06-13
CXC0 2020-06-08
MrLiar 2020-06-04
丨Fanny丨Cri 2020-06-03
丨Fanny丨Cri 2020-05-17
JavaWinner 2020-05-10
JavaWinner 2020-05-04
CXC0 2020-04-20
CXC0 2020-04-10
丨Fanny丨Cri 2020-02-18
MrLiar 2020-02-16
CXC0 2020-02-09