//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package org.apache.ibatis.logging.stdout;
import org.apache.ibatis.logging.Log;
public class StdOutImpl implements Log {
public StdOutImpl(String clazz) {
}
public boolean isDebugEnabled() {
return true;
}
public boolean isTraceEnabled() {
return true;
}
public void error(String s, Throwable e) {
System.err.println(s);
e.printStackTrace(System.err);
}
public void error(String s) {
System.err.println(s);
}
public void debug(String s) {
System.out.println(s);
}
public void trace(String s) {
System.out.println(s);
}
public void warn(String s) {
System.out.println(s);
}
}
System.out.println 输出的日志,在生产环境中不要打开它,System.out.println 源代码当中存在synchronized 代码块 在请求量很大的时候会导致代码串行执行 影响性能
public void println() {
newLine();
}
private void newLine() {
try {
synchronized (this) {
ensureOpen();
textOut.newLine();
textOut.flushBuffer();
charOut.flushBuffer();
if (autoFlush)
out.flush();
}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}
我自己的解决方法比较粗暴,直接通过mybaits Log接口编写自己的实现类然后通过logback输出,也有其他方法可百度。
package com.unbox.common.log;
import org.apache.ibatis.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author 王振宇
*/
public class MybatisLog implements Log {
private Logger log = LoggerFactory.getLogger(MybatisLog.class);
public MybatisLog(String clazz) {}
@Override
public boolean isDebugEnabled() {
return true;
}
@Override
public boolean isTraceEnabled() {
return true;
}
@Override
public void error(String s, Throwable throwable) {
log.error(s, throwable);
}
@Override
public void error(String s) {
log.error(s);
}
@Override
public void debug(String s) {
log.info(s); // 这里会输出sql执行日志
}
@Override
public void trace(String s) {
log.trace(s);
}
@Override
public void warn(String s) {
log.warn(s);
}
}
mybatis-plus:
type-aliases-package: ${TYPE-ALIASES-PACKAGE:com.unbox}
mapper-locations: classpath:mapper/**/*.xml
configuration:
log-impl: com.unbox.common.log.MybatisLog