Skip to content

Commit

Permalink
Changed to use slf4j v2.0 API
Browse files Browse the repository at this point in the history
Also added suppressLogging API
  • Loading branch information
HidekiSugimoto189 committed Sep 10, 2024
1 parent 97b8a17 commit d053799
Show file tree
Hide file tree
Showing 27 changed files with 236 additions and 123 deletions.
49 changes: 25 additions & 24 deletions src/main/java/jp/co/future/uroborosql/SqlAgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept
// REPLで実行するための文字列をREPLログに出力する
outputReplLog(executionContext);

LOG.atDebug()
atDebug(LOG)
.setMessage("Execute query sql. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
Expand Down Expand Up @@ -1401,7 +1401,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept
var pessimisticLockingErrorCodes = dialect.getPessimisticLockingErrorCodes();
if (maxRetryCount > loopCount
&& (getSqlRetryCodes().contains(errorCode) || getSqlRetryCodes().contains(sqlState))) {
LOG.atDebug()
atDebug(LOG)
.setMessage("Caught the error code to be retried.({} times). Retry after {} ms.")
.addArgument(loopCount + 1)
.addArgument(() -> String.format("%,3d", retryWaitTime))
Expand Down Expand Up @@ -1440,7 +1440,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept
return null;
} finally {
// 後処理
PERFORMANCE_LOG.atInfo()
atInfo(PERFORMANCE_LOG)
.setMessage("SQL execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand Down Expand Up @@ -1498,7 +1498,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {

// 更新移譲処理の指定がある場合は移譲処理を実行し結果を返却
if (executionContext.getUpdateDelegate() != null) {
LOG.atInfo()
atInfo(LOG)
.log("Performs update delegate of update process.");
return executionContext.getUpdateDelegate().apply(executionContext);
}
Expand All @@ -1513,7 +1513,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
// REPLで実行するための文字列をREPLログに出力する
outputReplLog(executionContext);

LOG.atDebug()
atDebug(LOG)
.setMessage("Execute update sql. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
Expand Down Expand Up @@ -1571,7 +1571,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
var errorCode = String.valueOf(ex.getErrorCode());
var sqlState = ex.getSQLState();
if (getSqlRetryCodes().contains(errorCode) || getSqlRetryCodes().contains(sqlState)) {
LOG.atDebug()
atDebug(LOG)
.setMessage("Caught the error code to be retried.({} times). Retry after {} ms.")
.addArgument(loopCount + 1)
.addArgument(() -> String.format("%,3d", retryWaitTime))
Expand Down Expand Up @@ -1603,7 +1603,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
} finally {
// 後処理
var curStartTime = startTime;
PERFORMANCE_LOG.atInfo()
atInfo(PERFORMANCE_LOG)
.setMessage("SQL execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand All @@ -1630,7 +1630,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
// 更新移譲処理の指定がある場合は移譲処理を実行し結果を返却
if (executionContext.getUpdateDelegate() != null) {
releaseParameterLogging();
LOG.atInfo()
atInfo(LOG)
.log("Performs update delegate of batch process.");
return new int[] { executionContext.getUpdateDelegate().apply(executionContext) };
}
Expand All @@ -1642,7 +1642,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
// INパラメータ設定
executionContext.bindBatchParams(stmt);

LOG.atDebug()
atDebug(LOG)
.setMessage("Execute batch sql. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
Expand Down Expand Up @@ -1697,7 +1697,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
var errorCode = String.valueOf(ex.getErrorCode());
var sqlState = ex.getSQLState();
if (getSqlRetryCodes().contains(errorCode) || getSqlRetryCodes().contains(sqlState)) {
LOG.atDebug()
atDebug(LOG)
.setMessage("Caught the error code to be retried.({} times). Retry after {} ms.")
.addArgument(loopCount + 1)
.addArgument(() -> String.format("%,3d", retryWaitTime))
Expand Down Expand Up @@ -1730,7 +1730,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
} finally {
// 後処理
var curStartTime = startTime;
PERFORMANCE_LOG.atInfo()
atInfo(PERFORMANCE_LOG)
.setMessage("SQL execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand Down Expand Up @@ -1764,7 +1764,7 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
// パラメータ設定
executionContext.bindParams(callableStatement);

LOG.atDebug()
atDebug(LOG)
.setMessage("Execute stored procedure. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
Expand Down Expand Up @@ -1808,7 +1808,7 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
var errorCode = String.valueOf(ex.getErrorCode());
var sqlState = ex.getSQLState();
if (getSqlRetryCodes().contains(errorCode) || getSqlRetryCodes().contains(sqlState)) {
LOG.atDebug()
atDebug(LOG)
.setMessage("Caught the error code to be retried.({} times). Retry after {} ms.")
.addArgument(loopCount + 1)
.addArgument(() -> String.format("%,3d", retryWaitTime))
Expand Down Expand Up @@ -1840,7 +1840,7 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
} finally {
// 後処理
var curStartTime = startTime;
PERFORMANCE_LOG.atInfo()
atInfo(PERFORMANCE_LOG)
.setMessage("Stored procedure execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand Down Expand Up @@ -1880,12 +1880,12 @@ private void transformContext(final ExecutionContext executionContext) {

if (SQL_LOG.isInfoEnabled() && sqlName != null) {
if (executionContext.getSqlKind().isEntityType()) {
SQL_LOG.atInfo()
atInfo(SQL_LOG)
.setMessage("EntityClass : {}")
.addArgument(sqlName)
.log();
} else if (getSqlResourceManager().existSql(sqlName)) {
SQL_LOG.atInfo()
atInfo(SQL_LOG)
.setMessage("SQLPath : {}")
.addArgument(() -> getSqlResourceManager().getSqlPath(sqlName))
.log();
Expand All @@ -1912,7 +1912,7 @@ && getSqlConfig().getEventListenerHolder().hasBeforeParseSqlListener()) {
.forEach(listener -> listener.accept(eventObj));
}

SQL_LOG.atDebug()
atDebug(SQL_LOG)
.setMessage("Template SQL[{}{}{}]")
.addArgument(System.lineSeparator())
.addArgument(originalSql)
Expand All @@ -1932,7 +1932,7 @@ && getSqlConfig().getEventListenerHolder().hasBeforeParseSqlListener()) {
// SQLカバレッジ用のログを出力する
var coverageData = new CoverageData(sqlName, originalSql,
contextTransformer.getPassedRoute());
COVERAGE_LOG.atDebug()
atDebug(COVERAGE_LOG)
.setMessage("coverage data: {}")
.addArgument(coverageData)
.log();
Expand All @@ -1941,7 +1941,7 @@ && getSqlConfig().getEventListenerHolder().hasBeforeParseSqlListener()) {
}
}

SQL_LOG.atInfo()
atInfo(SQL_LOG)
.setMessage("Executed SQL[{}{}{}]")
.addArgument(System.lineSeparator())
.addArgument(executionContext.getExecutableSql())
Expand Down Expand Up @@ -1977,7 +1977,7 @@ private void handleException(final ExecutionContext executionContext, final SQLE
}

if (outputExceptionLog) {
LOG.atError()
atError(LOG)
.setMessage(() -> {
var builder = new StringBuilder();
builder.append(System.lineSeparator()).append("Exception occurred in SQL execution.")
Expand Down Expand Up @@ -2034,7 +2034,7 @@ private void outputReplLog(final ExecutionContext executionContext) {
builder.append(" ");
builder.append(SqlParamUtils.formatPrams(params));
}
REPL_LOG.atInfo()
atInfo(REPL_LOG)
.setMessage("REPL command: {}")
.addArgument(builder.toString())
.log();
Expand Down Expand Up @@ -2900,7 +2900,8 @@ private static String formatElapsedTime(final Instant start, final Instant end)
*
* @param <T> ResultSetの1行を変換した型
*/
private static final class ResultSetSpliterator<T> extends Spliterators.AbstractSpliterator<T> {
private static final class ResultSetSpliterator<T> extends Spliterators.AbstractSpliterator<T>
implements ServiceLogger {
private final ResultSetConverter<T> converter;
private final ResultSet rs;
private boolean finished = false;
Expand Down Expand Up @@ -2929,7 +2930,7 @@ public boolean tryAdvance(final Consumer<? super T> action) {
rs.close();
}
} catch (SQLException ex2) {
LOG.atError()
atError(LOG)
.setMessage(ex2.getMessage())
.setCause(ex2)
.log();
Expand All @@ -2941,7 +2942,7 @@ public boolean tryAdvance(final Consumer<? super T> action) {
rs.close();
}
} catch (SQLException ex2) {
LOG.atError()
atError(LOG)
.setMessage(ex2.getMessage())
.setCause(ex2)
.log();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/jp/co/future/uroborosql/SqlEntityQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public SqlEntityQuery<E> forUpdateNoWait() {
return this;
} else if (!agent().getSqlConfig().getSqlAgentProvider().isStrictForUpdateType()
&& dialect.supportsForUpdate()) {
LOG.atWarn()
atWarn(LOG)
.log("'FOR UPDATE NOWAIT' is not supported. Set 'FOR UPDATE' instead.");
this.forUpdateType = ForUpdateType.NORMAL;
return this;
Expand All @@ -601,7 +601,7 @@ public SqlEntityQuery<E> forUpdateWait() {
return forUpdateWait(agent().getSqlConfig().getSqlAgentProvider().getDefaultForUpdateWaitSeconds());
} else if (!agent().getSqlConfig().getSqlAgentProvider().isStrictForUpdateType()
&& dialect.supportsForUpdate()) {
LOG.atWarn()
atWarn(LOG)
.log("'FOR UPDATE WAIT' is not supported. Set 'FOR UPDATE' instead.");
this.forUpdateType = ForUpdateType.NORMAL;
return this;
Expand All @@ -623,7 +623,7 @@ public SqlEntityQuery<E> forUpdateWait(final int waitSeconds) {
return this;
} else if (!agent().getSqlConfig().getSqlAgentProvider().isStrictForUpdateType()
&& dialect.supportsForUpdate()) {
LOG.atWarn()
atWarn(LOG)
.log("'FOR UPDATE WAIT' is not supported. Set 'FOR UPDATE' instead.");
this.forUpdateType = ForUpdateType.NORMAL;
return this;
Expand All @@ -642,7 +642,7 @@ public SqlEntityQuery<E> hint(final String hint) {
if (dialect.supportsOptimizerHints()) {
this.optimizerHints.add(hint);
} else {
LOG.atWarn()
atWarn(LOG)
.log("Optimizer Hints is not supported.");
}
return this;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/jp/co/future/uroborosql/UroboroSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ public SqlConfig build() {

}

public static final class InternalConfig implements SqlConfig {
public static final class InternalConfig implements SqlConfig, SettingLogger {
/**
* コネクション提供クラス.
*/
Expand Down Expand Up @@ -296,12 +296,12 @@ public static final class InternalConfig implements SqlConfig {
this.entityHandler = new DefaultEntityHandler();
if (clock == null) {
this.clock = Clock.systemDefaultZone();
SETTING_LOG.atWarn()
atWarn(SETTING_LOG)
.log("SqlConfig - Clock was not set. Set SystemClock.");
} else {
this.clock = clock;
}
SETTING_LOG.atInfo()
atInfo(SETTING_LOG)
.setMessage("SqlConfig - Clock : {} has been selected.")
.addArgument(this.clock)
.log();
Expand All @@ -314,7 +314,7 @@ public static final class InternalConfig implements SqlConfig {
} else {
this.dialect = dialect;
}
SETTING_LOG.atInfo()
atInfo(SETTING_LOG)
.setMessage("SqlConfig - Dialect : {} has been selected.")
.addArgument(() -> this.dialect.getClass().getSimpleName())
.log();
Expand All @@ -329,7 +329,7 @@ public static final class InternalConfig implements SqlConfig {
} else {
this.expressionParser = expressionParser;
}
SETTING_LOG.atInfo()
atInfo(SETTING_LOG)
.setMessage("SqlConfig - ExpressionParser : {} has been selected.")
.addArgument(() -> this.expressionParser.getClass().getSimpleName())
.log();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/jp/co/future/uroborosql/client/SqlREPL.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void initialize(final Terminal terminal) throws Exception {

urls.add(Paths.get(sb.toString()).toUri().toURL());
} catch (Exception ex) {
REPL_LOG.atError()
atError(REPL_LOG)
.setMessage(ex.getMessage())
.setCause(ex)
.log();
Expand All @@ -214,7 +214,7 @@ private void initialize(final Terminal terminal) throws Exception {
try {
DriverManager.registerDriver(new DriverShim(driver));
} catch (Exception ex) {
REPL_LOG.atError()
atError(REPL_LOG)
.setMessage(ex.getMessage())
.setCause(ex)
.log();
Expand Down Expand Up @@ -311,7 +311,7 @@ private void listen(final Terminal terminal) throws IOException {
} catch (UserInterruptException | EndOfFileException ex) {
break;
} catch (Exception ex) {
REPL_LOG.atError()
atError(REPL_LOG)
.setMessage(ex.getMessage())
.setCause(ex)
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean execute(final LineReader reader, final String[] parts, final SqlC
}
writer.println();
} catch (SQLException ex) {
REPL_LOG.atError()
atError(REPL_LOG)
.setMessage(ex.getMessage())
.setCause(ex)
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public boolean execute(final LineReader reader, final String[] parts, final SqlC
}).orElseGet(() -> sqlConfig.getEntityHandler().createSelectContext(agent, metadata, null, true));
writer.println(ctx.getSql());
} catch (SQLException ex) {
REPL_LOG.atError()
atError(REPL_LOG)
.setMessage(ex.getMessage())
.setCause(ex)
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void complete(final LineReader reader, final ParsedLine line, final List<
}
}
} catch (SQLException ex) {
REPL_LOG.atError()
atError(REPL_LOG)
.setMessage(ex.getMessage())
.setCause(ex)
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ public ExecutionContext bindBatchParams(final PreparedStatement preparedStatemen
preparedStatement.addBatch();
}
if (!isSuppressLogging()) {
SQL_LOG.atDebug()
atDebug(SQL_LOG)
.setMessage("{} items Added for batch process.")
.addArgument(batchParameters.size())
.log();
Expand Down Expand Up @@ -923,7 +923,7 @@ public Map<String, Object> getOutParams(final CallableStatement callableStatemen
parameterIndex++;
}

SQL_LOG.atDebug()
atDebug(SQL_LOG)
.setMessage("Stored procedure out parameter[{}]")
.addArgument(out)
.log();
Expand Down
Loading

0 comments on commit d053799

Please sign in to comment.