P6Spy应用:Hibernate显示真正SQL(3)

更改p6spy.jar中的以下文件即可控制FileLogger的输出日志格式:

反编译后修改后再丢进jar中原位置

 

com\p6spy\engine\logging\appender\FormattedLogger.java

 

package com.p6spy.engine.logging.appender;

public abstract class FormattedLogger {
	protected String lastEntry;

	public void logSQL(int connectionId, String now, long elapsed, String category, 
            String prepared, String sql){
		 String separatorLine = "========================================";
		 String switchLine ="\r\n";
		 StringBuffer logEntry = new StringBuffer();
		 
		 logEntry.append("(1)◆执行时间:"+now);
		 logEntry.append(switchLine);
		 logEntry.append("(2)◆花费时间:"+elapsed+" millseconds ");
		 logEntry.append(switchLine);
		 logEntry.append("(3)◆连接Id:"+connectionId);
		 logEntry.append(switchLine);
		 logEntry.append("(4)◆类别:"+category);
		 logEntry.append(switchLine);
		 logEntry.append("(5)◆带参数且为[?]的SQL:\n"+prepared);
		 logEntry.append(switchLine);
		 logEntry.append("(6)◆带参数且设置了[参数值]的SQL或◆SQL执行结果:\n"+sql);
		 logEntry.append(switchLine);
		 
		 logEntry.append(separatorLine);
		 logEntry.append(separatorLine);
		 logEntry.append(switchLine);
		
		 logText(logEntry.toString());
	}

	public abstract void logText(String paramString);

	public void setLastEntry(String inVar) {
		this.lastEntry = inVar;
	}

	public String getLastEntry() {
		return this.lastEntry;
	}
}
 

 

原本代码为:
String logEntry = now + "|" + elapsed + "|" + ((connectionId == -1) ? "" : String.valueOf(connectionId)) + "|" + category + "|" + prepared + "|" + sql;
logText(logEntry);
也就是以下格式
current time|execution time|category|statement SQL String|effective SQL string


你可能感兴趣的:(Hibernate)