强烈推荐一个大神的人工智能的教程:http://www.captainbed.net/zhanghan
描述 |
添加jar包依赖 |
</font>
<h1 id="背景"><table><tbody><tr><td bgcolor="#008B8B" height="40px"><font size="6px" face="华文新魏" color="white">自定义输出格式</font></td></tr></tbody></table></h1>
<font size="4px" face="楷体" font-weight="bold">
package com.zh.ssm.p6spy;
import com.p6spy.engine.spy.appender.MessageFormattingStrategy;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
- p6spy打印日志输出格式修改
- 1.只打印最终执行的sql.
- 2.sql换到下一行
- 3.结尾处增加分号,以标示sql结尾
*/
public class P6SpyLogger implements MessageFormattingStrategy {
private SimpleDateFormat format = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss:SSS”);
public P6SpyLogger() {
}
public String formatMessage(int connectionId, String now, long elapsed, String category, String prepared, String sql) {
return !"".equals(sql.trim())?this.format.format(new Date()) + " | took " + elapsed + "ms | " + category + " | connection " + connectionId + "\n " + sql + ";":"";
}
}
</font>
<h1 id="背景"><table><tbody><tr><td bgcolor="#008B8B" height="40px"><font size="6px" face="华文新魏" color="white">配置spy.properties</font></td></tr></tbody></table></h1>
<font size="4px" face="楷体" font-weight="bold">
在service层的classpath下新建文件spy.properties,内容如下:
#%L
P6Spy
%%
Copyright © 2013 P6Spy
%%
Licensed under the Apache License, Version 2.0 (the “License”);
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#L%
#################################################################
P6Spy Options File
See documentation for detailed instructions
http://p6spy.github.io/p6spy/2.0/configandusage.html
#################################################################
#################################################################