我有一些函数可以初始化我想迁移到 logback 的 log4j。
public static Categorylog log = writeLog();
@SuppressWarnings("deprecation")
public static Category writeLog() {
initializeLogger();
log = Category.getInstance(Logfile.class);
log.info("Log4JExample - leaving the constructor ...<BR>", null);
return log;
}
private static void initializeLogger() {
Properties logProperties = new Properties();
String path = "", finalPath = "";
Global global = new Global();
try {
// load our log4j properties / configuration file
System.setProperty("log4j2.configurationFile", "log4j2.xml");
System.setProperty("“log4j1.compatibility", "true");
logProperties.load(new FileInputStream("filePaths.properties"));
path = logProperties.getProperty("logfile");
finalPath = global.appendProjName(path);
logProperties.load(new FileInputStream(finalPath));
PropertyConfigurator.configure(logProperties);
} catch (IOException e) {
throw new RuntimeException("Unable to load logging property " + finalPath);
}
}
我一直在尝试,但到目前为止没有成功进行完全转换:
public static Logger writeLog() {
initializeLogger();
log = LoggerFactory.getLogger(Logfile.class);
log.info("Log4Back - leaving the constructor ...<BR>");
return log;
}