Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revise log level. #337

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions src/main/java/jp/co/future/uroborosql/SqlAgentImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,31 @@ public class SqlAgentImpl implements SqlAgent, ServiceLoggingSupport, Performanc
// クラス名が指定されている場合はそのクラス名を指定
var sqlCoverageClassName = System.getProperty(KEY_SQL_COVERAGE);
if (sqlCoverageClassName == null) {
COVERAGE_LOG.atInfo()
COVERAGE_LOG.atDebug()
.log("system property - uroborosql.sql.coverage not set. sql coverage turned off.");
} else if (Boolean.FALSE.toString().equalsIgnoreCase(sqlCoverageClassName)) {
sqlCoverageClassName = null;
COVERAGE_LOG.atInfo()
COVERAGE_LOG.atDebug()
.log("system property - uroborosql.sql.coverage is set to false. sql coverage turned off.");
} else if (Boolean.TRUE.toString().equalsIgnoreCase(sqlCoverageClassName)) {
// trueの場合は、デフォルト値を設定
sqlCoverageClassName = "jp.co.future.uroborosql.coverage.CoberturaCoverageHandler";
COVERAGE_LOG.atInfo()
COVERAGE_LOG.atDebug()
.log("system property - uroborosql.sql.coverage is set to true. sql coverage turned on.");
} else {
COVERAGE_LOG.atDebug()
.setMessage(
"system property - uroborosql.sql.coverage is set to custom class:{}. sql coverage turned on.")
.addArgument(sqlCoverageClassName)
.log();
}

CoverageHandler handler = null;
if (sqlCoverageClassName != null) {
try {
handler = (CoverageHandler) Class.forName(sqlCoverageClassName, true,
Thread.currentThread().getContextClassLoader()).getConstructor().newInstance();
COVERAGE_LOG.atInfo()
COVERAGE_LOG.atDebug()
.setMessage("CoverageHandler : {}")
.addArgument(sqlCoverageClassName)
.log();
Expand All @@ -185,7 +191,7 @@ public class SqlAgentImpl implements SqlAgent, ServiceLoggingSupport, Performanc
.addArgument(sqlCoverageClassName)
.addArgument(ex.getMessage())
.log();
COVERAGE_LOG.atInfo()
COVERAGE_LOG.atDebug()
.log("Turn off sql coverage due to failure to instantiate CoverageHandler class.");
}
}
Expand Down Expand Up @@ -1356,7 +1362,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept
.setMessage("Execute query sql. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
var startTime = PERFORMANCE_LOG.isInfoEnabled() ? Instant.now(getSqlConfig().getClock()) : null;
var startTime = PERFORMANCE_LOG.isDebugEnabled() ? Instant.now(getSqlConfig().getClock()) : null;

try {
// デフォルト最大リトライ回数を取得し、個別指定(ExecutionContextの値)があれば上書き
Expand Down Expand Up @@ -1436,7 +1442,7 @@ public ResultSet query(final ExecutionContext executionContext) throws SQLExcept
return null;
} finally {
// 後処理
infoWith(PERFORMANCE_LOG)
debugWith(PERFORMANCE_LOG)
.setMessage("SQL execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand Down Expand Up @@ -1494,7 +1500,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {

// 更新移譲処理の指定がある場合は移譲処理を実行し結果を返却
if (executionContext.getUpdateDelegate() != null) {
infoWith(LOG)
debugWith(LOG)
.log("Performs update delegate of update process.");
return executionContext.getUpdateDelegate().apply(executionContext);
}
Expand All @@ -1511,7 +1517,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
.addArgument(executionContext.getSqlName())
.log();

if (PERFORMANCE_LOG.isInfoEnabled()) {
if (PERFORMANCE_LOG.isDebugEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
}

Expand Down Expand Up @@ -1596,7 +1602,7 @@ public int update(final ExecutionContext executionContext) throws SQLException {
} finally {
// 後処理
var curStartTime = startTime;
infoWith(PERFORMANCE_LOG)
debugWith(PERFORMANCE_LOG)
.setMessage("SQL execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand All @@ -1623,7 +1629,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
// 更新移譲処理の指定がある場合は移譲処理を実行し結果を返却
if (executionContext.getUpdateDelegate() != null) {
releaseParameterLogging();
infoWith(LOG)
debugWith(LOG)
.log("Performs update delegate of batch process.");
return new int[] { executionContext.getUpdateDelegate().apply(executionContext) };
}
Expand All @@ -1639,7 +1645,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
.setMessage("Execute batch sql. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
if (PERFORMANCE_LOG.isInfoEnabled()) {
if (PERFORMANCE_LOG.isDebugEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
}

Expand Down Expand Up @@ -1723,7 +1729,7 @@ public int[] batch(final ExecutionContext executionContext) throws SQLException
} finally {
// 後処理
var curStartTime = startTime;
infoWith(PERFORMANCE_LOG)
debugWith(PERFORMANCE_LOG)
.setMessage("SQL execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand Down Expand Up @@ -1761,7 +1767,7 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
.setMessage("Execute stored procedure. sqlName: {}")
.addArgument(executionContext.getSqlName())
.log();
if (PERFORMANCE_LOG.isInfoEnabled()) {
if (PERFORMANCE_LOG.isDebugEnabled()) {
startTime = Instant.now(getSqlConfig().getClock());
}

Expand Down Expand Up @@ -1833,7 +1839,7 @@ public Map<String, Object> procedure(final ExecutionContext executionContext) th
} finally {
// 後処理
var curStartTime = startTime;
infoWith(PERFORMANCE_LOG)
debugWith(PERFORMANCE_LOG)
.setMessage("Stored procedure execution time [{}({})] : [{}]")
.addArgument(() -> generateSqlName(executionContext))
.addArgument(executionContext.getSqlKind())
Expand Down Expand Up @@ -1871,14 +1877,14 @@ private void transformContext(final ExecutionContext executionContext) {
originalSql = originalSql.replace(keySqlId, sqlId);
}

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

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

infoWith(SQL_LOG)
debugWith(SQL_LOG)
.setMessage("Executed SQL[{}{}{}]")
.addArgument(System.lineSeparator())
.addArgument(executionContext.getExecutableSql())
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/jp/co/future/uroborosql/UroboroSQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,12 @@ public static final class InternalConfig implements SqlConfig, SettingLoggingSup
this.entityHandler = new DefaultEntityHandler();
if (clock == null) {
this.clock = Clock.systemDefaultZone();
warnWith(SETTING_LOG)
traceWith(SETTING_LOG)
.log("SqlConfig - Clock was not set. Set SystemClock.");
} else {
this.clock = clock;
}
infoWith(SETTING_LOG)
debugWith(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, SettingLoggingSup
} else {
this.dialect = dialect;
}
infoWith(SETTING_LOG)
debugWith(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, SettingLoggingSup
} else {
this.expressionParser = expressionParser;
}
infoWith(SETTING_LOG)
debugWith(SETTING_LOG)
.setMessage("SqlConfig - ExpressionParser : {} has been selected.")
.addArgument(() -> this.expressionParser.getClass().getSimpleName())
.log();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ protected void makeConstParamMap(final Map<String, Parameter> paramMap,
.addArgument(prevValue.getValue())
.log();
}
infoWith(SETTING_LOG)
debugWith(SETTING_LOG)
.setMessage("Constant [name:{}, value:{}] added to parameter.")
.addArgument(fieldName)
.addArgument(newValue.getValue())
Expand Down Expand Up @@ -212,7 +212,7 @@ protected void makeEnumConstParamMap(final Map<String, Parameter> paramMap,
.addArgument(prevValue.getValue())
.log();
}
infoWith(SETTING_LOG)
debugWith(SETTING_LOG)
.setMessage("Enum [name:{}, value:{}] added to parameter.")
.addArgument(fieldName)
.addArgument(newValue.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void outputReplLog(final ExecutionContext executionContext) {
builder.append(" ");
builder.append(SqlParamUtils.formatPrams(params));
}
infoWith(EVENT_LOG)
debugWith(EVENT_LOG)
.setMessage("REPL command: {}")
.addArgument(builder.toString())
.log();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/jp/co/future/uroborosql/node/IfNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ public void accept(final TransformContext transformContext) {

if (result instanceof Boolean) {
var resultValue = (Boolean) result;
if (PARSER_LOG.isInfoEnabled()) {
if (PARSER_LOG.isDebugEnabled()) {
if (Boolean.TRUE.toString().equalsIgnoreCase(expression)
|| Boolean.FALSE.toString().equalsIgnoreCase(expression)) {
// 単純なBoolean評価の場合はログを出力しない
} else {
infoWith(PARSER_LOG)
debugWith(PARSER_LOG)
.setMessage("Evaluation Expression:[{}], Result:[{}], Parameter:[{}]")
.addArgument(expression)
.addArgument(resultValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ protected int setInParameter(final PreparedStatement preparedStatement, final in
* @param index パラメータインデックス
*/
protected void parameterLog(final int index) {
if (SQL_LOG.isInfoEnabled() && !isSuppressParameterLogging()) {
infoWith(SQL_LOG)
if (SQL_LOG.isDebugEnabled() && !isSuppressParameterLogging()) {
debugWith(SQL_LOG)
.setMessage("Set the parameter.[INDEX[{}], {}]")
.addArgument(index)
.addArgument(this)
Expand Down
Loading