系统一直有log4j打印日志,但是需要在日志打印上加上系统的版本信息,因为生产系统的频繁升级的情况下会出现一天的日志打印乱输出的情况,也是为了方便定位问题吧。在这里之前考虑了下对DailyRollingFileAppender ConsoleAppender进行extend操作,发现这种要对两个appender进行实现,有些繁琐。
接下来就考虑改造org.apache.log4j.PatternLayout;对其进行继承,并重写它的所有方法。
import org.apache.log4j.MDC;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.helpers.PatternParser;
import org.apache.log4j.spi.LoggingEvent;
import org.jeecgframework.core.util.PropertiesUtil;
public class LogCustomLayout extends PatternLayout {
private static String systemVersion = "v1.0";
static{
PropertiesUtil propertiesUtil = new PropertiesUtil("sysConfig.properties");
systemVersion = propertiesUtil.readProperty("system.platf.version");
}
public LogCustomLayout() {
super();
}
public LogCustomLayout(String pattern) {
super(pattern);
}