- オンラインでこれを行うには多くの方法があります。最も簡単な方法は、rootをdebugに設定することですが、粒度は十分細かくありません;
<configuration>
<!-- mybatisを使う@Mapper注釈 name は、注釈付きクラスへのパスとして構成される。>
<logger name="xx.xx.mapper" level="DEBUG"/>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>[%d{yyyy-MM-dd HH:mm:ss:SSS}] %level %thread %logger{36}:%L- %msg%n</pattern>
<charset class="java.nio.charset.Charset">UTF-8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
</root>
</configuration>
- 以下はSQLを出力するクラスですが、プロキシを経由した後、ログに自分のクラス名が表示されます。
SQLを表示するクラス: org.apache.ibatis.logging.jdbc.ConnectionLogger
パラメータを表示するクラス: org.apache.ibatis.logging.jdbc.PreparedStatementLogger
システムが起動すると、自動的にxmlのすべてのコンフィギュレーションをスキャンします。rootはルートノードで、他のすべてのクラスの親ノードです。
// ルート・ロガーの設定
public LoggerContext() {
super();
this.loggerCache = new ConcurrentHashMap<String, Logger>();
this.loggerContextRemoteView = new LoggerContextVO(this);
this.root = new Logger(Logger.ROOT_LOGGER_NAME, null, this);
this.root.setLevel(Level.DEBUG);
loggerCache.put(Logger.ROOT_LOGGER_NAME, root);
initEvaluatorMap();
size = 1;
this.frameworkPackages = new ArrayList<String>();
}
@Override
public final Logger getLogger(final String name) {
.... いくつかのコードを省略する
/**
現在のカスタム@mapperインターフェース・クラスのパッケージ・パスとログバック構成
構成ファイルの定義が見つかるまで、構成ファイルのパッケージ・パスが段階的にマッチングされる。
次に、root.Log の定義を使用する;
**/
String childName;
while (true) {
int h = LoggerNameUtil.getSeparatorIndexOf(name, i);
if (h == -1) {
childName = name;
} else {
childName = name.substring(0, h);
}
// move i left of the last point
i = h + 1;
synchronized (logger) {
childLogger = logger.getChildByName(childName);
if (childLogger == null) {
//ロガーが見つかり、ロガーに返される。
childLogger = logger.createChildByName(childName);
loggerCache.put(childName, childLogger);
incSize();
}
}
logger = childLogger;
if (h == -1) {
return childLogger;
}
}
}
level が debug に設定されている場合、effectiveLevelInt プロパティは 00100 になります。
level が info に設定されている場合、effectiveLevelInt 属性は 00200 になります。
最終的な Log は、MappedStatement クラスの statementLog プロパティに設定されます。
SQL文が実行されると、以下のコードが呼び出されます。
protected Connection getConnection(Log statementLog) throws SQLException {
Connection connection = transaction.getConnection();
//デバッグを使用するかどうかを決定する
if (statementLog.isDebugEnabled()) {
// 最終的にConnectionLoggerが呼び出される。.invoke()
return ConnectionLogger.newInstance(connection, statementLog, queryStack);
} else {
return connection;
}
}
public boolean isDebugEnabled(Marker marker) {
final FilterReply decision = callTurboFilters(marker, Level.DEBUG);
if (decision == FilterReply.NEUTRAL) {
//via: effectiveLevelInt <= 10000 ログ印刷を使用するかどうかを決定する
return effectiveLevelInt <= Level.DEBUG_INT;
} else if (decision == FilterReply.DENY) {
return false;
} else if (decision == FilterReply.ACCEPT) {
return true;
} else {
throw new IllegalStateException("Unknown FilterReply value: " + decision);
}
}
最後のコンソールはSQL文を表示します。
xx.mapper.xx:159- ==> Preparing: select ***
xx.mapper.xx:159- ==> Parameters:





