From a23f241fff2d01c743e3a862eb34f1f2db7e5199 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 18 Aug 2022 22:44:31 +1200 Subject: [PATCH 1/2] Use AppLog and System.Logger for logging rather than slf4j-api The avaje-applog-slf4j dependency means this is still using slf4j-api for implementation. Remove that dependency and service load the desired implementation. --- ebean-api/pom.xml | 28 ++-- .../src/main/java/io/ebean/DbContext.java | 8 +- .../src/main/java/io/ebean/EbeanVersion.java | 20 ++- .../config/dbplatform/DatabasePlatform.java | 25 ++- .../dbplatform/SequenceIdGenerator.java | 13 +- .../java/io/ebean/event/ShutdownManager.java | 20 +-- .../io/ebean/text/csv/DefaultCsvCallback.java | 15 +- .../main/java/io/ebean/util/JdbcClose.java | 16 +- ebean-api/src/main/java/module-info.java | 3 +- .../service/DefaultAutoTuneService.java | 28 ++-- .../service/ProfileOriginNodeUsage.java | 10 +- .../java/io/ebeaninternal/api/CoreLog.java | 7 +- .../io/ebeaninternal/api/LoadManyRequest.java | 9 +- .../server/cache/DefaultCacheHolder.java | 12 +- .../server/cache/DefaultServerCache.java | 12 +- .../cache/DefaultServerCacheManager.java | 14 +- .../changelog/DefaultChangeLogListener.java | 10 +- .../server/cluster/ClusterManager.java | 10 +- .../server/core/BeanRequest.java | 4 +- .../server/core/DatabasePlatformFactory.java | 5 +- .../server/core/DefaultBeanLoader.java | 8 +- .../server/core/DefaultContainer.java | 15 +- .../server/core/DefaultQueryPlanListener.java | 9 +- .../server/core/DefaultServer.java | 79 ++-------- .../server/core/DefaultSlowQueryListener.java | 9 +- .../server/core/InternalConfigXmlMap.java | 3 +- .../server/core/InternalConfiguration.java | 13 +- .../server/core/OrmQueryRequest.java | 4 +- .../core/bootup/BootupClassPathSearch.java | 7 +- .../server/core/bootup/BootupClasses.java | 8 +- .../server/core/bootup/ManifestReader.java | 8 +- .../server/deploy/BeanDescriptor.java | 17 +- .../deploy/BeanDescriptorCacheHelp.java | 146 +++++++++--------- .../server/deploy/BeanDescriptorManager.java | 30 ++-- .../server/deploy/BeanFinderManager.java | 7 +- .../server/deploy/BeanProperty.java | 3 +- .../server/deploy/BeanPropertyAssoc.java | 3 +- .../server/deploy/BeanPropertyAssocMany.java | 7 +- .../deploy/BeanQueryAdapterManager.java | 4 +- .../server/deploy/BeanTable.java | 4 +- .../deploy/PersistControllerManager.java | 4 +- .../server/deploy/PersistListenerManager.java | 4 +- .../server/deploy/PostConstructManager.java | 4 +- .../server/deploy/PostLoadManager.java | 4 +- .../deploy/meta/DeployBeanPropertyLists.java | 4 +- .../deploy/parse/AnnotationAssocOnes.java | 5 +- .../server/deploy/parse/AnnotationClass.java | 4 +- .../deploy/parse/DeployCreateProperties.java | 9 +- .../server/dto/DtoMetaBuilder.java | 5 +- .../executor/DaemonExecutorService.java | 15 +- .../executor/DaemonScheduleThreadPool.java | 14 +- .../executor/DefaultBackgroundExecutor.java | 25 ++- .../server/idgen/UuidV1IdGenerator.java | 56 +++---- .../server/idgen/UuidV1RndIdGenerator.java | 9 +- .../server/logger/DLoggerFactory.java | 4 +- .../server/logger/DSpiLogger.java | 15 +- .../server/persist/BatchedPstmt.java | 5 +- .../ebeaninternal/server/persist/Binder.java | 3 +- .../server/persist/DefaultPersister.java | 30 ++-- .../server/persist/SaveManyBase.java | 3 +- .../server/persist/SaveManyBeans.java | 2 +- .../server/persist/dml/DmlHandler.java | 4 +- .../io/ebeaninternal/server/query/CQuery.java | 8 +- .../server/query/CQueryEngine.java | 7 +- .../query/CQueryFetchSingleAttribute.java | 4 +- .../server/query/CQueryPlan.java | 4 +- .../server/query/CQueryPlanManager.java | 3 +- .../server/query/CQueryPredicates.java | 4 +- .../server/query/QueryPlanLoggerExplain.java | 4 +- .../server/query/QueryPlanLoggerOracle.java | 4 +- .../server/query/QueryPlanLoggerPostgres.java | 4 +- .../query/QueryPlanLoggerSqlServer.java | 6 +- .../server/query/SqlTreeBuilder.java | 33 ++-- .../readaudit/DefaultReadAuditLogger.java | 20 +-- .../transaction/DefaultProfileHandler.java | 27 ++-- .../ImplicitReadOnlyTransaction.java | 3 +- .../server/transaction/JdbcTransaction.java | 16 +- .../transaction/JtaTransactionManager.java | 22 +-- .../transaction/PostCommitProcessing.java | 8 +- .../server/transaction/TableModState.java | 26 ++-- .../transaction/TransactionManager.java | 16 +- .../ebeaninternal/server/type/DataBind.java | 16 +- .../server/type/DefaultTypeManager.java | 24 ++- .../server/type/ScalarTypeFile.java | 5 +- ebean-core/src/main/java/module-info.java | 1 - .../dbmigration/DdlGenerator.java | 10 +- .../dbmigration/DefaultDbMigration.java | 14 +- .../dbmigration/model/MTable.java | 8 +- .../dbmigration/model/MigrationModel.java | 9 +- .../dbmigration/model/PlatformDdlWriter.java | 8 +- .../extraddl/model/ExtraDdlXmlReader.java | 8 +- .../test/java/io/localtest/BaseTestCase.java | 12 +- ebean-externalmapping-xml/pom.xml | 7 - .../xmlmapping/InternalConfigXmlRead.java | 7 - .../src/main/java/module-info.java | 1 - ebean-postgis/pom.xml | 8 - .../main/java/io/ebean/redis/RedisCache.java | 18 ++- .../io/ebean/redis/RedisCacheFactory.java | 58 +++---- .../ebean/redis/topic/DaemonTopicRunner.java | 14 +- ebean-test/pom.xml | 7 +- .../io/ebean/test/CapturingLoggerFactory.java | 19 +-- .../test/config/AutoConfigureForTesting.java | 10 +- .../io/ebean/test/config/platform/Config.java | 8 +- .../config/platform/PlatformAutoConfig.java | 14 +- .../config/provider/ProviderAutoConfig.java | 10 +- ebean-test/src/main/java/module-info.java | 2 +- .../ebean/platform/h2/H2HistoryTrigger.java | 17 +- pom.xml | 7 - 108 files changed, 666 insertions(+), 756 deletions(-) diff --git a/ebean-api/pom.xml b/ebean-api/pom.xml index c2fe306bef..325b0a70a3 100644 --- a/ebean-api/pom.xml +++ b/ebean-api/pom.xml @@ -13,27 +13,23 @@ - - org.slf4j - slf4j-api - 1.7.36 - provided + io.avaje + avaje-applog + 1.0 + io.avaje - avaje-config - 2.2 + avaje-applog-slf4j + 1.0 io.avaje - avaje-applog-slf4j - 1.0 + avaje-config + 2.2 + + org.slf4j + slf4j-api + 1.7.36 + true + + com.fasterxml.jackson.core diff --git a/ebean-api/src/main/java/io/ebean/DbContext.java b/ebean-api/src/main/java/io/ebean/DbContext.java index 3ce395cf77..c098f079a4 100644 --- a/ebean-api/src/main/java/io/ebean/DbContext.java +++ b/ebean-api/src/main/java/io/ebean/DbContext.java @@ -2,10 +2,9 @@ import io.ebean.config.BeanNotEnhancedException; import io.ebean.datasource.DataSourceConfigurationException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.persistence.PersistenceException; +import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; @@ -15,7 +14,8 @@ */ final class DbContext { - private static final Logger log = LoggerFactory.getLogger("io.ebean"); + private static final System.Logger log = EbeanVersion.log; + static { EbeanVersion.getVersion(); } @@ -52,7 +52,7 @@ private DbContext() { throw new DataSourceConfigurationException(msg, e); } catch (Throwable e) { - log.error("Error trying to create the default Database", e); + log.log(Level.ERROR, "Error trying to create the default Database", e); throw new RuntimeException(e); } } diff --git a/ebean-api/src/main/java/io/ebean/EbeanVersion.java b/ebean-api/src/main/java/io/ebean/EbeanVersion.java index c47a546c0e..7eaf5a52a7 100644 --- a/ebean-api/src/main/java/io/ebean/EbeanVersion.java +++ b/ebean-api/src/main/java/io/ebean/EbeanVersion.java @@ -1,9 +1,12 @@ package io.ebean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.avaje.applog.AppLog; -import java.io.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.lang.System.Logger.Level; import java.util.Properties; /** @@ -13,7 +16,7 @@ */ public final class EbeanVersion { - private static final Logger log = LoggerFactory.getLogger("io.ebean"); + public static final System.Logger log = AppLog.getLogger("io.ebean"); /** * Maintain the minimum ebean-agent version manually based on required ebean-agent bug fixes. @@ -21,6 +24,7 @@ public final class EbeanVersion { private static final int MIN_AGENT_MAJOR_VERSION = 12; private static final int MIN_AGENT_MINOR_VERSION = 12; private static String version = "unknown"; + static { readVersion(); checkAgentVersion(); @@ -32,12 +36,12 @@ private static void readVersion() { if (in != null) { try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(in))) { version = reader.readLine(); - log.info("ebean version: {}", version); + log.log(Level.INFO, "ebean version: {0}", version); } } } } catch (IOException e) { - log.warn("Could not determine ebean version: {}", e.getMessage()); + log.log(Level.WARNING, "Could not determine ebean version: {0}", e.getMessage()); } } @@ -49,13 +53,13 @@ private static void checkAgentVersion() { String agentVersion = readVersion(in); if (agentVersion != null) { if (checkMinAgentVersion(agentVersion)) { - log.error("Expected minimum ebean-agent version {}.{}.0 but we have {}, please update the ebean-agent", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, agentVersion); + log.log(Level.ERROR, "Expected minimum ebean-agent version {0}.{1}.0 but we have {2}, please update the ebean-agent", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, agentVersion); } } } } } catch (IOException e) { - log.warn("Could not check minimum ebean-agent version {}.{}.0 required due to - {}", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, e.getMessage()); + log.log(Level.WARNING, "Could not check minimum ebean-agent version {0}.{1}.0 required due to - {2}", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, e.getMessage()); } } diff --git a/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java b/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java index 20b7ccd00d..53d4163726 100644 --- a/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java +++ b/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java @@ -1,32 +1,25 @@ package io.ebean.config.dbplatform; import io.ebean.BackgroundExecutor; +import io.ebean.EbeanVersion; import io.ebean.Query; -import io.ebean.annotation.PartitionMode; import io.ebean.annotation.PersistBatch; import io.ebean.annotation.Platform; import io.ebean.config.CustomDbTypeMapping; import io.ebean.config.PlatformConfig; import io.ebean.util.JdbcClose; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.persistence.PersistenceException; import javax.sql.DataSource; -import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.sql.Types; +import java.lang.System.Logger.Level; +import java.sql.*; /** * Database platform specific settings. */ public class DatabasePlatform { - private static final Logger log = LoggerFactory.getLogger("io.ebean"); + private static final System.Logger log = EbeanVersion.log; /** * Behavior used when ending a query only transaction (at read committed isolation level). @@ -60,7 +53,7 @@ public enum OnQueryOnly { * Can we use native java time API objects in * {@link ResultSet#getObject(int, Class)} and * {@link PreparedStatement#setObject(int, Object)}. - * + *

* Not all drivers (DB2 e.g.) will support this. */ protected boolean supportsNativeJavaTime = true; @@ -165,7 +158,7 @@ public enum OnQueryOnly { * want to use quoted identifiers for. The backticks get converted to the * appropriate characters in convertQuotedIdentifiers */ - private static final char[] QUOTED_IDENTIFIERS = new char[] { '"', '\'', '[', ']', '`' }; + private static final char[] QUOTED_IDENTIFIERS = new char[]{'"', '\'', '[', ']', '`'}; /** * The non-escaped like clause (to stop slash being escaped on some platforms). @@ -666,7 +659,7 @@ public String convertQuotedIdentifiers(String dbName) { if (isQuote(dbName.charAt(dbName.length() - 1))) { return openQuote + dbName.substring(1, dbName.length() - 1) + closeQuote; } else { - log.error("Missing backquote on [" + dbName + "]"); + log.log(Level.ERROR, "Missing backquote on [" + dbName + "]"); } } else if (allQuotedIdentifiers) { return openQuote + dbName + closeQuote; @@ -729,7 +722,7 @@ public String fromForUpdate(Query.LockWait lockWait) { protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) { // silently assume the database does not support the "for update" clause. - log.info("it seems your database does not support the 'for update' clause"); + log.log(Level.INFO, "it seems your database does not support the 'for update' clause"); return sql; } @@ -763,7 +756,7 @@ public void createSchemaIfNotExists(String dbSchema, Connection connection) thro if (!schemaExists(dbSchema, connection)) { Statement query = connection.createStatement(); try { - log.debug("create schema:{}", dbSchema); + log.log(Level.DEBUG, "create schema:{0}", dbSchema); query.executeUpdate("create schema " + dbSchema); } finally { JdbcClose.close(query); diff --git a/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java b/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java index 10e8c924b6..658c5e94e6 100644 --- a/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java +++ b/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java @@ -1,13 +1,13 @@ package io.ebean.config.dbplatform; +import io.avaje.applog.AppLog; import io.ebean.BackgroundExecutor; import io.ebean.Transaction; import io.ebean.util.JdbcClose; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.persistence.PersistenceException; import javax.sql.DataSource; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -24,7 +24,7 @@ */ public abstract class SequenceIdGenerator implements PlatformIdGenerator { - protected static final Logger log = LoggerFactory.getLogger("io.ebean.SEQ"); + protected static final System.Logger log = AppLog.getLogger("io.ebean.SEQ"); private final ReentrantLock lock = new ReentrantLock(); protected final String seqName; @@ -120,7 +120,7 @@ private void loadMore(int requestSize) { protected void loadInBackground(final int requestSize) { if (currentlyBackgroundLoading.get()) { // skip as already background loading - log.debug("... skip background sequence load (another load in progress)"); + log.log(Level.DEBUG, "... skip background sequence load (another load in progress)"); return; } currentlyBackgroundLoading.set(true); @@ -152,9 +152,6 @@ protected List getMoreIds(int requestSize) { resultSet = statement.executeQuery(); List newIds = readIds(resultSet, requestSize); - if (log.isTraceEnabled()) { - log.trace("seq:{} loaded:{} sql:{}", seqName, newIds.size(), sql); - } if (newIds.isEmpty()) { throw new PersistenceException("Always expecting more than 1 row from " + sql); } @@ -164,7 +161,7 @@ protected List getMoreIds(int requestSize) { } catch (SQLException e) { if (e.getMessage().contains("Database is already closed")) { String msg = "Error getting SEQ when DB shutting down " + e.getMessage(); - log.error(msg); + log.log(Level.ERROR, msg); System.out.println(msg); return Collections.emptyList(); } else { diff --git a/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java b/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java index 4341c5cfda..2547ee5423 100644 --- a/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java +++ b/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java @@ -1,10 +1,10 @@ package io.ebean.event; import io.ebean.Database; +import io.ebean.EbeanVersion; import io.ebean.service.SpiContainer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; @@ -20,13 +20,14 @@ */ public final class ShutdownManager { - private static final Logger log = LoggerFactory.getLogger("io.ebean"); + private static final System.Logger log = EbeanVersion.log; private static final ReentrantLock lock = new ReentrantLock(); private static final List databases = new ArrayList<>(); private static final ShutdownHook shutdownHook = new ShutdownHook(); private static boolean stopping; private static SpiContainer container; + static { // Register the Shutdown hook registerShutdownHook(); @@ -120,8 +121,8 @@ public static void shutdown() { // Already run shutdown... return; } - if (log.isDebugEnabled()) { - log.debug("Ebean shutting down"); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "Ebean shutting down"); } stopping = true; deregisterShutdownHook(); @@ -133,7 +134,7 @@ public static void shutdown() { Runnable r = (Runnable) ClassUtil.newInstance(shutdownRunner); r.run(); } catch (Exception e) { - log.error("Error running custom shutdown runnable", e); + log.log(Level.ERROR, "Error running custom shutdown runnable", e); } } @@ -147,7 +148,7 @@ public static void shutdown() { try { server.shutdown(); } catch (Exception ex) { - log.error("Error executing shutdown runnable", ex); + log.log(Level.ERROR, "Error executing shutdown runnable", ex); ex.printStackTrace(); } } @@ -165,10 +166,10 @@ private static void deregisterAllJdbcDrivers() { while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { - log.info("De-registering jdbc driver: " + driver); + log.log(Level.INFO, "De-registering jdbc driver: " + driver); DriverManager.deregisterDriver(driver); } catch (SQLException e) { - log.error("Error de-registering driver " + driver, e); + log.log(Level.ERROR, "Error de-registering driver " + driver, e); } } } @@ -204,6 +205,7 @@ private static class ShutdownHook extends Thread { private ShutdownHook() { super("EbeanHook"); } + @Override public void run() { ShutdownManager.shutdown(); diff --git a/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java b/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java index cec1043557..d2e6d3f98e 100644 --- a/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java +++ b/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java @@ -1,9 +1,10 @@ package io.ebean.text.csv; import io.ebean.Database; +import io.ebean.EbeanVersion; import io.ebean.Transaction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.lang.System.Logger.Level; /** * Provides the default implementation of CsvCallback. @@ -20,7 +21,7 @@ */ public class DefaultCsvCallback implements CsvCallback { - private static final Logger log = LoggerFactory.getLogger(DefaultCsvCallback.class); + private static final System.Logger log = EbeanVersion.log; /** * The transaction to use (if not using CsvCallback). @@ -128,7 +129,7 @@ public void processBean(int row, String[] line, T bean) { // related beans (e.g. customer -> customer.billingAddress server.save(bean, transaction); if (logInfoFrequency > 0 && (row % logInfoFrequency == 0)) { - log.debug("processed {} rows", row); + log.log(Level.DEBUG, "processed {0} rows", row); } } @@ -139,7 +140,7 @@ public void processBean(int row, String[] line, T bean) { public void end(int row) { commitTransactionIfCreated(); exeTime = System.currentTimeMillis() - startTime; - log.info("Csv finished, rows[{}] exeMillis[{}]", row, exeTime); + log.log(Level.INFO, "Csv finished, rows[{0}] exeMillis[{1}]", row, exeTime); } /** @@ -160,7 +161,6 @@ protected void initTransactionIfRequired() { transaction = server.beginTransaction(); createdTransaction = true; if (persistBatchSize > 1) { - log.debug("Creating transaction, batchSize[{}]", persistBatchSize); transaction.setBatchMode(true); transaction.setBatchSize(persistBatchSize); transaction.setGetGeneratedKeys(false); @@ -168,7 +168,6 @@ protected void initTransactionIfRequired() { // explicitly turn off JDBC batching in case // is has been turned on globally transaction.setBatchMode(false); - log.debug("Creating transaction with no JDBC batching"); } } } @@ -180,7 +179,6 @@ protected void initTransactionIfRequired() { protected void commitTransactionIfCreated() { if (createdTransaction) { transaction.commit(); - log.debug("Committed transaction"); } } @@ -191,7 +189,6 @@ protected void commitTransactionIfCreated() { protected void rollbackTransactionIfCreated(Throwable e) { if (createdTransaction) { transaction.rollback(e); - log.debug("Rolled back transaction"); } } diff --git a/ebean-api/src/main/java/io/ebean/util/JdbcClose.java b/ebean-api/src/main/java/io/ebean/util/JdbcClose.java index a1d04536e6..b450db79ab 100644 --- a/ebean-api/src/main/java/io/ebean/util/JdbcClose.java +++ b/ebean-api/src/main/java/io/ebean/util/JdbcClose.java @@ -1,8 +1,8 @@ package io.ebean.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.ebean.EbeanVersion; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; @@ -13,7 +13,7 @@ */ public final class JdbcClose { - private static final Logger log = LoggerFactory.getLogger("io.ebean"); + private static final System.Logger log = EbeanVersion.log; /** * Close the resultSet logging if an error occurs. @@ -24,7 +24,7 @@ public static void close(Statement statement) { statement.close(); } } catch (SQLException e) { - log.warn("Error closing statement", e); + log.log(Level.WARNING, "Error closing statement", e); } } @@ -37,7 +37,7 @@ public static void close(ResultSet resultSet) { resultSet.close(); } } catch (SQLException e) { - log.warn("Error closing resultSet", e); + log.log(Level.WARNING, "Error closing resultSet", e); } } @@ -50,7 +50,7 @@ public static void close(Connection connection) { connection.close(); } } catch (SQLException e) { - log.warn("Error closing connection", e); + log.log(Level.WARNING, "Error closing connection", e); } } @@ -63,7 +63,7 @@ public static void rollback(Connection connection) { connection.rollback(); } } catch (SQLException e) { - log.warn("Error on connection rollback", e); + log.log(Level.WARNING, "Error on connection rollback", e); } } @@ -76,7 +76,7 @@ public static void cancel(Statement stmt) { stmt.cancel(); } } catch (SQLException e) { - log.warn("Error on cancelling statement", e); + log.log(Level.WARNING, "Error on cancelling statement", e); } } } diff --git a/ebean-api/src/main/java/module-info.java b/ebean-api/src/main/java/module-info.java index 7c8453cea6..e5128fb5f0 100644 --- a/ebean-api/src/main/java/module-info.java +++ b/ebean-api/src/main/java/module-info.java @@ -15,8 +15,9 @@ requires transitive persistence.api; requires transitive io.ebean.annotation; requires transitive io.ebean.datasource.api; - requires transitive org.slf4j; + requires transitive io.avaje.applog; + requires static org.slf4j; requires static io.ebean.types; requires static com.fasterxml.jackson.core; requires static com.fasterxml.jackson.databind; diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java index b8d302f232..be43c42afb 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.autotune.service; +import io.avaje.applog.AppLog; import io.ebean.config.AutoTuneConfig; import io.ebean.config.DatabaseConfig; import io.ebeaninternal.api.SpiEbeanServer; @@ -7,12 +8,11 @@ import io.ebeaninternal.server.autotune.AutoTuneService; import io.ebeaninternal.server.autotune.model.Autotune; import io.ebeaninternal.server.autotune.model.Origin; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; @@ -21,7 +21,7 @@ */ public class DefaultAutoTuneService implements AutoTuneService { - private static final Logger logger = LoggerFactory.getLogger(DefaultAutoTuneService.class); + private static final System.Logger logger = AppLog.getLogger(DefaultAutoTuneService.class); private final ReentrantLock lock = new ReentrantLock(); @@ -111,7 +111,7 @@ private void loadTuningFile() { if (stream != null) { loadAutoTuneProfiling(AutoTuneXmlReader.read(stream)); } else { - logger.warn("AutoTune file {} not found - no initial automatic query tuning", tuningFile); + logger.log(Level.WARNING, "AutoTune file {0} not found - no initial automatic query tuning", tuningFile); } } catch (IOException e) { throw new IllegalStateException("Error on auto close of " + tuningFile, e); @@ -120,7 +120,7 @@ private void loadTuningFile() { } private void loadAutoTuneProfiling(Autotune profiling) { - logger.info("AutoTune loading {} tuning entries", profiling.getOrigin().size()); + logger.log(Level.INFO, "AutoTune loading {0} tuning entries", profiling.getOrigin().size()); for (Origin origin : profiling.getOrigin()) { queryTuner.put(origin); } @@ -141,17 +141,17 @@ private void runtimeTuningUpdate() { event.process(); if (event.isEmpty()) { long exeMillis = System.currentTimeMillis() - start; - logger.debug("No query tuning updates for server:{} executionMillis:{}", serverName, exeMillis); + logger.log(Level.DEBUG, "No query tuning updates for server:{0} executionMillis:{1}", serverName, exeMillis); } else { // report the query tuning changes that have been made runtimeChangeCount += event.getChangeCount(); event.writeFile(profilingFile + "-" + serverName + "-update"); long exeMillis = System.currentTimeMillis() - start; - logger.info("query tuning updates - new:{} diff:{} for server:{} executionMillis:{}", event.getNewCount(), event.getDiffCount(), serverName, exeMillis); + logger.log(Level.INFO, "query tuning updates - new:{0} diff:{1} for server:{2} executionMillis:{3}", event.getNewCount(), event.getDiffCount(), serverName, exeMillis); } } catch (Throwable e) { - logger.error("Error collecting or applying automatic query tuning", e); + logger.log(Level.ERROR, "Error collecting or applying automatic query tuning", e); } } finally { lock.unlock(); @@ -172,11 +172,11 @@ private void saveProfilingOnShutdown(boolean reset) { AutoTuneDiffCollection event = new AutoTuneDiffCollection(profiling, queryTuner, false); event.process(); if (event.isEmpty()) { - logger.info("No new or diff entries for profiling server:{}", serverName); + logger.log(Level.INFO, "No new or diff entries for profiling server:{0}", serverName); } else { event.writeFile(profilingFile + "-" + serverName); - logger.info("writing new:{} diff:{} profiling entries for server:{}", event.getNewCount(), event.getDiffCount(), serverName); + logger.log(Level.INFO, "writing new:{0} diff:{1} profiling entries for server:{2}", event.getNewCount(), event.getDiffCount(), serverName); } } } finally { @@ -196,7 +196,7 @@ private void saveProfilingOnShutdown(boolean reset) { private void outputAllTuning() { if (runtimeChangeCount == 0) { - logger.info("no runtime query tuning changes for server:{}", serverName); + logger.log(Level.INFO, "no runtime query tuning changes for server:{0}", serverName); } else { AutoTuneAllCollection event = new AutoTuneAllCollection(queryTuner); @@ -205,12 +205,12 @@ private void outputAllTuning() { if (existingTuning.exists()) { // rename the existing autotune.xml file (appending 'now') if (!existingTuning.renameTo(new File(tuningFile + "." + AutoTuneXmlWriter.now()))) { - logger.warn("Failed to rename autotune file [{}]", tuningFile); + logger.log(Level.WARNING, "Failed to rename autotune file [{0}]", tuningFile); } } event.writeFile(tuningFile, false); - logger.info("query tuning detected [{}] changes, writing all [{}] tuning entries for server:{}", runtimeChangeCount, size, serverName); + logger.log(Level.INFO, "query tuning detected [{0}] changes, writing all [{1}] tuning entries for server:{2}", runtimeChangeCount, size, serverName); } } @@ -279,7 +279,7 @@ public void collectProfiling(long waitMillis) { } catch (InterruptedException e) { // restore the interrupted status Thread.currentThread().interrupt(); - logger.warn("Error while sleeping after System.gc() request.", e); + logger.log(Level.WARNING, "Error while sleeping after System.gc() request.", e); } } diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java index c5a3c17db3..fb9007ebfa 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.autotune.service; +import io.avaje.applog.AppLog; import io.ebean.bean.NodeUsageCollector; import io.ebean.text.PathProperties; import io.ebean.util.SplitName; @@ -7,9 +8,8 @@ import io.ebeaninternal.server.deploy.BeanProperty; import io.ebeaninternal.server.deploy.BeanPropertyAssoc; import io.ebeaninternal.server.el.ElPropertyValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.LinkedHashSet; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; @@ -19,7 +19,7 @@ */ public class ProfileOriginNodeUsage { - private static final Logger logger = LoggerFactory.getLogger(ProfileOriginNodeUsage.class); + private static final System.Logger logger = AppLog.getLogger(ProfileOriginNodeUsage.class); private final ReentrantLock lock = new ReentrantLock(); @@ -45,7 +45,7 @@ protected void buildTunedFetch(PathProperties pathProps, BeanDescriptor rootD if (path != null) { ElPropertyValue elGetValue = rootDesc.elGetValue(path); if (elGetValue == null) { - logger.warn("AutoTune: Can't find join for path[" + path + "] for " + rootDesc.name()); + logger.log(Level.WARNING, "AutoTune: Can't find join for path[" + path + "] for " + rootDesc.name()); return; } else { BeanProperty beanProperty = elGetValue.beanProperty(); @@ -61,7 +61,7 @@ protected void buildTunedFetch(PathProperties pathProps, BeanDescriptor rootD for (String propName : aggregateUsed) { BeanProperty beanProp = desc.findPropertyFromPath(propName); if (beanProp == null) { - logger.warn("AutoTune: Can't find property[" + propName + "] for " + desc.name()); + logger.log(Level.WARNING, "AutoTune: Can't find property[" + propName + "] for " + desc.name()); } else { if (beanProp.isId()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/CoreLog.java b/ebean-core/src/main/java/io/ebeaninternal/api/CoreLog.java index cfbf56283d..85b491d152 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/CoreLog.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/CoreLog.java @@ -1,13 +1,12 @@ package io.ebeaninternal.api; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.avaje.applog.AppLog; /** * Common loggers used in ebean-core. */ public final class CoreLog { - public static final Logger log = LoggerFactory.getLogger("io.ebean.core"); - public static final Logger internal = LoggerFactory.getLogger("io.ebean.internal"); + public static final System.Logger log = AppLog.getLogger("io.ebean.core"); + public static final System.Logger internal = AppLog.getLogger("io.ebean.internal"); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java b/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java index dcbc3c32b8..b2956f1d27 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/LoadManyRequest.java @@ -7,17 +7,18 @@ import io.ebeaninternal.server.core.OrmQueryRequest; import io.ebeaninternal.server.deploy.BeanDescriptor; import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; -import org.slf4j.Logger; import java.util.ArrayList; import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Request for loading Associated Many Beans. */ public final class LoadManyRequest extends LoadRequest { - private static final Logger log = CoreLog.log; + private static final System.Logger log = CoreLog.log; private final List> batch; private final LoadManyBuffer loadContext; @@ -113,10 +114,10 @@ public void postLoad() { // in the +query or +lazy load due to no rows (predicates) for (BeanCollection bc : batch) { if (bc.checkEmptyLazyLoad()) { - if (log.isDebugEnabled()) { + if (log.isLoggable(DEBUG)) { EntityBean ownerBean = bc.getOwnerBean(); Object parentId = desc.getId(ownerBean); - log.debug("BeanCollection after lazy load was empty. type:" + ownerBean.getClass().getName() + " id:" + parentId + " owner:" + ownerBean); + log.log(DEBUG, "BeanCollection after lazy load was empty. type:" + ownerBean.getClass().getName() + " id:" + parentId + " owner:" + ownerBean); } } else if (loadCache && many.isUseCache()) { desc.cacheManyPropPut(many, bc, desc.getId(bc.getOwnerBean())); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java index ad3faa7498..cf6a02089b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.cache; +import io.avaje.applog.AppLog; import io.ebean.annotation.Cache; import io.ebean.annotation.CacheBeanTuning; import io.ebean.annotation.CacheQueryTuning; @@ -7,9 +8,8 @@ import io.ebean.config.CurrentTenantProvider; import io.ebean.meta.MetricVisitor; import io.ebean.util.AnnotationUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; @@ -20,7 +20,7 @@ */ final class DefaultCacheHolder { - private static final Logger log = LoggerFactory.getLogger("io.ebean.cache.ALL"); + private static final System.Logger log = AppLog.getLogger("io.ebean.cache.ALL"); private final ReentrantLock lock = new ReentrantLock(); private final ConcurrentHashMap allCaches = new ConcurrentHashMap<>(); @@ -89,7 +89,7 @@ private ServerCache createCache(Class beanType, ServerCacheType type, String } void clearAll() { - log.debug("clearAll"); + log.log(Level.DEBUG, "clearAll"); for (ServerCache serverCache : allCaches.values()) { serverCache.clear(); } @@ -97,7 +97,7 @@ void clearAll() { public void clear(String name) { - log.debug("clear {}", name); + log.log(Level.DEBUG, "clear {0}", name); clearIfExists(key(name, ServerCacheType.QUERY)); clearIfExists(key(name, ServerCacheType.BEAN)); clearIfExists(key(name, ServerCacheType.NATURAL_KEY)); @@ -112,7 +112,7 @@ public void clear(String name) { private void clearIfExists(String fullKey) { ServerCache cache = allCaches.get(fullKey); if (cache != null) { - log.trace("clear cache {}", fullKey); + log.log(Level.TRACE, "clear cache {0}", fullKey); cache.clear(); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java index f3b49fd2e5..e5bfd2628e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java @@ -1,15 +1,15 @@ package io.ebeaninternal.server.cache; +import io.avaje.applog.AppLog; import io.ebean.BackgroundExecutor; import io.ebean.cache.ServerCache; import io.ebean.cache.ServerCacheStatistics; import io.ebean.meta.MetricVisitor; import io.ebean.metric.CountMetric; import io.ebean.metric.MetricFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.Serializable; +import java.lang.System.Logger.Level; import java.lang.ref.SoftReference; import java.util.*; import java.util.concurrent.TimeUnit; @@ -25,7 +25,7 @@ */ public class DefaultServerCache implements ServerCache { - protected static final Logger logger = LoggerFactory.getLogger(DefaultServerCache.class); + protected static final System.Logger logger = AppLog.getLogger(DefaultServerCache.class); /** * Compare by last access time (for LRU eviction). @@ -287,13 +287,13 @@ public void runEviction() { evictCount.add(trimmedByGC); evictCount.add(trimmedByTTL); evictCount.add(trimmedByLRU); - if (logger.isTraceEnabled()) { + if (logger.isLoggable(Level.TRACE)) { long exeMicros = TimeUnit.MICROSECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS); - logger.trace("Executed trim of cache {} in [{}]millis idle[{}] timeToLive[{}] accessTime[{}] gc[{}]", + logger.log(Level.TRACE, "Executed trim of cache {0} in [{1}]millis idle[{2}] timeToLive[{3}] accessTime[{4}] gc[{5}]", name, exeMicros, trimmedByIdle, trimmedByTTL, trimmedByLRU, trimmedByGC); } } catch (Throwable e) { - logger.warn("Error during trim of DefaultServerCache [" + name + "]. Cache might be bigger than desired.", e); + logger.log(Level.WARNING, "Error during trim of DefaultServerCache [" + name + "]. Cache might be bigger than desired.", e); } } finally { lock.unlock(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java index 00f551da8b..6142f6d500 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.cache; +import io.avaje.applog.AppLog; import io.ebean.cache.ServerCache; import io.ebean.cache.ServerCacheRegion; import io.ebean.cache.ServerCacheType; @@ -7,9 +8,8 @@ import io.ebeaninternal.api.SpiCacheRegion; import io.ebeaninternal.server.cluster.ClusterManager; import io.ebeaninternal.server.deploy.DCacheRegion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.*; /** @@ -17,7 +17,7 @@ */ public final class DefaultServerCacheManager implements SpiCacheManager { - private static final Logger log = LoggerFactory.getLogger("io.ebean.cache.REGION"); + private static final System.Logger log = AppLog.getLogger("io.ebean.cache.REGION"); private final Map regionMap = new HashMap<>(); private final ClusterManager clusterManager; @@ -65,23 +65,23 @@ public void setEnabledRegions(String regions) { enabled.add(region.name()); if (!region.isEnabled()) { region.setEnabled(true); - log.debug("Cache region[{}] enabled", region.name()); + log.log(Level.DEBUG, "Cache region[{0}] enabled", region.name()); } } else { disabled.add(region.name()); if (region.isEnabled()) { region.setEnabled(false); - log.debug("Cache region[{}] disabled", region.name()); + log.log(Level.DEBUG, "Cache region[{0}] disabled", region.name()); } } } - log.info("Cache regions enabled:{} disabled:{}", enabled, disabled); + log.log(Level.INFO, "Cache regions enabled:{0} disabled:{1}", enabled, disabled); } } @Override public void setAllRegionsEnabled(boolean enabled) { - log.debug("All cache regions enabled[{}]", enabled); + log.log(Level.DEBUG, "All cache regions enabled[{0}]", enabled); for (SpiCacheRegion region : regionMap.values()) { region.setEnabled(enabled); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java index 597d87df01..c85edd3158 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.changelog; +import io.avaje.applog.AppLog; import io.ebean.event.changelog.BeanChange; import io.ebean.event.changelog.ChangeLogListener; import io.ebean.event.changelog.ChangeSet; @@ -7,10 +8,9 @@ import io.ebean.plugin.Plugin; import io.ebean.plugin.SpiServer; import io.ebeaninternal.api.CoreLog; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.StringWriter; +import java.lang.System.Logger.Level; import java.util.Properties; /** @@ -21,7 +21,7 @@ public final class DefaultChangeLogListener implements ChangeLogListener, Plugin /** * The named logger we send the change set payload to. Can be externally configured as desired. */ - private static final Logger changeLog = LoggerFactory.getLogger("io.ebean.ChangeLog"); + private static final System.Logger changeLog = AppLog.getLogger("io.ebean.ChangeLog"); /** * Used to build the JSON. @@ -65,9 +65,9 @@ public void log(ChangeSet changeSet) { try { StringWriter writer = new StringWriter(getBufferSize(beanChange)); jsonBuilder.writeBeanJson(writer, beanChange, changeSet); - changeLog.info(writer.toString()); + changeLog.log(Level.INFO, writer.toString()); } catch (Exception e) { - CoreLog.log.error("Exception logging beanChange " + beanChange, e); + CoreLog.log.log(Level.ERROR, "Exception logging beanChange " + beanChange, e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java index b273c031a2..4af7e1fce1 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java @@ -1,11 +1,11 @@ package io.ebeaninternal.server.cluster; +import io.avaje.applog.AppLog; import io.ebean.Database; import io.ebean.config.ContainerConfig; import io.ebeaninternal.server.transaction.RemoteTransactionEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.Iterator; import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; @@ -16,7 +16,7 @@ */ public class ClusterManager implements ServerLookup { - private static final Logger clusterLogger = LoggerFactory.getLogger("io.ebean.Cluster"); + private static final System.Logger clusterLogger = AppLog.getLogger("io.ebean.Cluster"); private final ReentrantLock lock = new ReentrantLock(); @@ -112,8 +112,8 @@ public boolean isClustering() { */ public void broadcast(RemoteTransactionEvent event) { if (broadcast != null) { - if (clusterLogger.isDebugEnabled()) { - clusterLogger.debug("sending: {}", event); + if (clusterLogger.isLoggable(Level.DEBUG)) { + clusterLogger.log(Level.DEBUG, "sending: {0}", event); } broadcast.broadcast(event); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java index 45fe5ff146..6d68210bde 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java @@ -6,6 +6,8 @@ import io.ebeaninternal.api.SpiTransaction; import io.ebeaninternal.server.core.timezone.DataTimeZone; +import java.lang.System.Logger.Level; + /** * Base class for find and persist requests. */ @@ -61,7 +63,7 @@ public void rollbackTransIfRequired() { // Just log this and carry on. A previous exception has been // thrown and if this rollback throws exception it likely means // that the connection is broken (and the dataSource and db will cleanup) - CoreLog.log.error("Error trying to rollback a transaction (after a prior exception thrown)", e); + CoreLog.log.log(Level.ERROR, "Error trying to rollback a transaction (after a prior exception thrown)", e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java index 407ebcaf85..265e71cba4 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java @@ -8,6 +8,7 @@ import javax.persistence.PersistenceException; import javax.sql.DataSource; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; @@ -38,7 +39,7 @@ public DatabasePlatform create(DatabaseConfig config) { try { String offlinePlatform = DbOffline.getPlatform(); if (offlinePlatform != null) { - CoreLog.log.info("offline platform [{}]", offlinePlatform); + CoreLog.log.log(Level.INFO, "offline platform [{0}]", offlinePlatform); return byDatabaseName(offlinePlatform); } if (config.getDatabasePlatformName() != null) { @@ -87,7 +88,7 @@ private DatabasePlatform byDatabaseMeta(DatabaseMetaData metaData, Connection co String dbProductName = metaData.getDatabaseProductName().toLowerCase(); final int majorVersion = metaData.getDatabaseMajorVersion(); final int minorVersion = metaData.getDatabaseMinorVersion(); - CoreLog.log.debug("platform for productName[{}] version[{}.{}]", dbProductName, majorVersion, minorVersion); + CoreLog.log.log(Level.DEBUG, "platform for productName[{0}] version[{1}.{2}]", dbProductName, majorVersion, minorVersion); for (DatabasePlatformProvider provider : providers) { if (provider.matchByProductName(dbProductName)) { return provider.create(majorVersion, minorVersion, metaData, connection); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java index 5bdf93a347..7cd82edebd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java @@ -12,9 +12,9 @@ import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType; import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; import io.ebeaninternal.server.transaction.DefaultPersistenceContext; -import org.slf4j.Logger; import javax.persistence.EntityNotFoundException; +import java.lang.System.Logger.Level; import java.util.List; import java.util.Set; @@ -23,7 +23,7 @@ */ final class DefaultBeanLoader { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final DefaultServer server; private final boolean onIterateUseExtraTxn; @@ -108,8 +108,8 @@ private void loadManyInternal(EntityBean parentBean, String propertyName, boolea server.findOne(query, null); if (beanCollection != null) { if (beanCollection.checkEmptyLazyLoad()) { - if (log.isDebugEnabled()) { - log.debug("BeanCollection after load was empty. Owner:" + beanCollection.getOwnerBean()); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "BeanCollection after load was empty. Owner:" + beanCollection.getOwnerBean()); } } else if (useManyIdCache) { parentDesc.cacheManyPropPut(many, beanCollection, parentId); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java index 5b84996610..eb1cb1fe2a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java @@ -1,7 +1,6 @@ package io.ebeaninternal.server.core; import io.ebean.config.*; -import io.ebean.config.EntityClassRegister; import io.ebean.config.dbplatform.DatabasePlatform; import io.ebean.event.ShutdownManager; import io.ebean.service.SpiContainer; @@ -13,9 +12,9 @@ import io.ebeaninternal.server.core.bootup.BootupClassPathSearch; import io.ebeaninternal.server.core.bootup.BootupClasses; import io.ebeaninternal.server.executor.DefaultBackgroundExecutor; -import org.slf4j.Logger; import javax.persistence.PersistenceException; +import java.lang.System.Logger.Level; import java.net.URL; import java.sql.Connection; import java.sql.SQLException; @@ -28,7 +27,7 @@ */ public final class DefaultContainer implements SpiContainer { - private static final Logger log = CoreLog.log; + private static final System.Logger log = CoreLog.log; private final ReentrantLock lock = new ReentrantLock(); private final ClusterManager clusterManager; @@ -108,7 +107,7 @@ public SpiEbeanServer createServer(DatabaseConfig config) { startServer(online, server); } DbOffline.reset(); - log.info("Started database[{}] platform[{}] in {}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start); + log.log(Level.INFO, "Started database[{0}] platform[{1}] in {2}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start); return server; } finally { lock.unlock(); @@ -137,7 +136,7 @@ private void applyConfigServices(DatabaseConfig config) { private void checkMissingModulePathProvides() { URL servicesFile = ClassLoader.getSystemResource("META-INF/services/io.ebean.config.EntityClassRegister"); if (servicesFile != null) { - log.error("module-info.java is probably missing 'provides io.ebean.config.EntityClassRegister with EbeanEntityRegister' clause. EntityClassRegister exists but was not service loaded."); + log.log(Level.ERROR, "module-info.java is probably missing 'provides io.ebean.config.EntityClassRegister with EbeanEntityRegister' clause. EntityClassRegister exists but was not service loaded."); } } @@ -201,7 +200,7 @@ private void setDatabasePlatform(DatabaseConfig config) { DatabasePlatform platform = config.getDatabasePlatform(); if (platform == null) { if (config.getTenantMode().isDynamicDataSource()) { - throw new IllegalStateException("DatabasePlatform must be explicitly set on DatabaseConfig for TenantMode "+config.getTenantMode()); + throw new IllegalStateException("DatabasePlatform must be explicitly set on DatabaseConfig for TenantMode " + config.getTenantMode()); } // automatically determine the platform platform = new DatabasePlatformFactory().create(config); @@ -215,7 +214,7 @@ private void setDatabasePlatform(DatabaseConfig config) { */ private void setDataSource(DatabaseConfig config) { if (isOfflineMode(config)) { - log.debug("... DbOffline using platform [{}]", DbOffline.getPlatform()); + log.log(Level.DEBUG, "... DbOffline using platform [{0}]", DbOffline.getPlatform()); } else { InitDataSource.init(config); } @@ -251,7 +250,7 @@ private boolean checkDataSource(DatabaseConfig config) { } try (Connection connection = config.getDataSource().getConnection()) { if (connection.getAutoCommit()) { - log.warn("DataSource [{}] has autoCommit defaulting to true!", config.getName()); + log.log(Level.WARNING, "DataSource [{0}] has autoCommit defaulting to true!", config.getName()); } return true; } catch (SQLException ex) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultQueryPlanListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultQueryPlanListener.java index f748e7f2bb..0393240725 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultQueryPlanListener.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultQueryPlanListener.java @@ -1,23 +1,24 @@ package io.ebeaninternal.server.core; +import io.avaje.applog.AppLog; import io.ebean.config.QueryPlanCapture; import io.ebean.config.QueryPlanListener; import io.ebean.meta.MetaQueryPlan; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import static java.lang.System.Logger.Level.INFO; final class DefaultQueryPlanListener implements QueryPlanListener { static final QueryPlanListener INSTANT = new DefaultQueryPlanListener(); - private static final Logger log = LoggerFactory.getLogger("io.ebean.QUERYPLAN"); + private static final System.Logger log = AppLog.getLogger("io.ebean.QUERYPLAN"); @Override public void process(QueryPlanCapture capture) { // better to log this in JSON form? String dbName = capture.database().name(); for (MetaQueryPlan plan : capture.plans()) { - log.info("queryPlan db:{} label:{} queryTimeMicros:{} loc:{} sql:{} bind:{} plan:{}", + log.log(INFO, "queryPlan db:{0} label:{1} queryTimeMicros:{2} loc:{3} sql:{4} bind:{5} plan:{6}", dbName, plan.label(), plan.queryTimeMicros(), plan.profileLocation(), plan.sql(), plan.bind(), plan.plan()); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java index b42381956e..b6b498b0d3 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java @@ -2,49 +2,11 @@ import io.avaje.lang.NonNullApi; import io.avaje.lang.Nullable; -import io.ebean.AutoTune; -import io.ebean.BackgroundExecutor; -import io.ebean.BeanState; -import io.ebean.CallableSql; -import io.ebean.DocumentStore; -import io.ebean.DtoQuery; -import io.ebean.ExpressionFactory; -import io.ebean.ExpressionList; -import io.ebean.ExtendedServer; -import io.ebean.Filter; -import io.ebean.FutureIds; -import io.ebean.FutureList; -import io.ebean.FutureRowCount; -import io.ebean.MergeOptions; -import io.ebean.MergeOptionsBuilder; -import io.ebean.PagedList; -import io.ebean.PersistenceContextScope; -import io.ebean.ProfileLocation; -import io.ebean.Query; -import io.ebean.QueryIterator; -import io.ebean.RowConsumer; -import io.ebean.RowMapper; -import io.ebean.ScriptRunner; -import io.ebean.SqlQuery; -import io.ebean.SqlRow; -import io.ebean.SqlUpdate; -import io.ebean.Transaction; -import io.ebean.TransactionCallback; -import io.ebean.TxScope; -import io.ebean.Update; -import io.ebean.UpdateQuery; -import io.ebean.ValuePair; -import io.ebean.Version; +import io.ebean.*; import io.ebean.annotation.Platform; import io.ebean.annotation.TxIsolation; -import io.ebean.bean.BeanCollection; -import io.ebean.bean.BeanLoader; -import io.ebean.bean.CallOrigin; -import io.ebean.bean.EntityBean; -import io.ebean.bean.EntityBeanIntercept; -import io.ebean.bean.PersistenceContext; +import io.ebean.bean.*; import io.ebean.bean.PersistenceContext.WithOption; -import io.ebean.bean.SingleBeanLoader; import io.ebean.cache.ServerCacheManager; import io.ebean.common.CopyOnFirstWriteList; import io.ebean.config.*; @@ -53,11 +15,7 @@ import io.ebean.event.ShutdownManager; import io.ebean.event.readaudit.ReadAuditLogger; import io.ebean.event.readaudit.ReadAuditPrepare; -import io.ebean.meta.MetaInfoManager; -import io.ebean.meta.MetaQueryPlan; -import io.ebean.meta.MetricVisitor; -import io.ebean.meta.QueryPlanInit; -import io.ebean.meta.QueryPlanRequest; +import io.ebean.meta.*; import io.ebean.migration.auto.AutoMigrationRunner; import io.ebean.plugin.BeanType; import io.ebean.plugin.Plugin; @@ -78,21 +36,8 @@ import io.ebeaninternal.server.dto.DtoBeanManager; import io.ebeaninternal.server.el.ElFilter; import io.ebeaninternal.server.grammer.EqlParser; -import io.ebeaninternal.server.query.CQuery; -import io.ebeaninternal.server.query.CQueryEngine; -import io.ebeaninternal.server.query.CallableQueryCount; -import io.ebeaninternal.server.query.CallableQueryIds; -import io.ebeaninternal.server.query.CallableQueryList; -import io.ebeaninternal.server.query.DtoQueryEngine; -import io.ebeaninternal.server.query.LimitOffsetPagedList; -import io.ebeaninternal.server.query.QueryFutureIds; -import io.ebeaninternal.server.query.QueryFutureList; -import io.ebeaninternal.server.query.QueryFutureRowCount; -import io.ebeaninternal.server.querydefn.DefaultDtoQuery; -import io.ebeaninternal.server.querydefn.DefaultOrmQuery; -import io.ebeaninternal.server.querydefn.DefaultOrmUpdate; -import io.ebeaninternal.server.querydefn.DefaultRelationalQuery; -import io.ebeaninternal.server.querydefn.DefaultUpdateQuery; +import io.ebeaninternal.server.query.*; +import io.ebeaninternal.server.querydefn.*; import io.ebeaninternal.server.rawsql.SpiRawSql; import io.ebeaninternal.server.text.csv.TCsvReader; import io.ebeaninternal.server.transaction.DefaultPersistenceContext; @@ -101,12 +46,12 @@ import io.ebeaninternal.util.ParamTypeHelper; import io.ebeaninternal.util.ParamTypeHelper.TypeInfo; import io.ebeanservice.docstore.api.DocStoreIntegration; -import org.slf4j.Logger; import javax.persistence.NonUniqueResultException; import javax.persistence.OptimisticLockException; import javax.persistence.PersistenceException; import javax.sql.DataSource; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -129,7 +74,7 @@ @NonNullApi public final class DefaultServer implements SpiServer, SpiEbeanServer { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final ReentrantLock lock = new ReentrantLock(); private final DatabaseConfig config; @@ -386,7 +331,7 @@ private void startQueryPlanCapture() { if (config.isQueryPlanCapture()) { long secs = config.getQueryPlanCapturePeriodSecs(); if (secs > 10) { - log.info("capture query plan enabled, every {}secs", secs); + log.log(Level.INFO, "capture query plan enabled, every {0}secs", secs); backgroundExecutor.scheduleWithFixedDelay(this::collectQueryPlans, secs, secs, TimeUnit.SECONDS); } } @@ -434,7 +379,7 @@ public void shutdown(boolean shutdownDataSource, boolean deregisterDriver) { * Shutdown the services like threads and DataSource. */ private void shutdownInternal(boolean shutdownDataSource, boolean deregisterDriver) { - log.trace("shutting down instance {}", serverName); + log.log(Level.TRACE, "shutting down instance {0}", serverName); if (shutdown) { // already shutdown return; @@ -463,7 +408,7 @@ private void shutdownPlugins() { try { plugin.shutdown(); } catch (Exception e) { - log.error("Error when shutting down plugin", e); + log.log(Level.ERROR, "Error when shutting down plugin", e); } } } @@ -2038,7 +1983,7 @@ public Object beanId(Object bean) { return desc(bean.getClass()).getId(eb); } - private BeanDescriptor desc(Class beanClass) { + private BeanDescriptor desc(Class beanClass) { BeanDescriptor desc = descriptorManager.descriptor(beanClass); if (desc == null) { throw new PersistenceException(beanClass.getName() + " is NOT an Entity Bean registered with this server?"); @@ -2130,7 +2075,7 @@ private void processRemoteCacheEvent(RemoteTransactionEvent event) { try { serverCacheManager.clearLocal(Class.forName(cache)); } catch (Exception e) { - log.error("Error clearing local cache for type " + cache, e); + log.log(Level.ERROR, "Error clearing local cache for type " + cache, e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultSlowQueryListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultSlowQueryListener.java index 64c813213d..6dc42b2115 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultSlowQueryListener.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultSlowQueryListener.java @@ -1,17 +1,18 @@ package io.ebeaninternal.server.core; +import io.avaje.applog.AppLog; import io.ebean.bean.ObjectGraphNode; import io.ebean.config.SlowQueryEvent; import io.ebean.config.SlowQueryListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import static java.lang.System.Logger.Level.WARNING; /** * Default slow query listener implementation that logs a warning message. */ final class DefaultSlowQueryListener implements SlowQueryListener { - private static final Logger log = LoggerFactory.getLogger("io.ebean.SlowQuery"); + private static final System.Logger log = AppLog.getLogger("io.ebean.SlowQuery"); @Override public void process(SlowQueryEvent event) { @@ -20,6 +21,6 @@ public void process(SlowQueryEvent event) { if (node != null) { firstStack = node.getOriginQueryPoint().getTopElement(); } - log.warn("Slow query warning - millis:{} rows:{} caller[{}] sql[{}]", event.getTimeMillis(), event.getRowCount(), firstStack, event.getSql()); + log.log(WARNING, "Slow query warning - millis:{0} rows:{1} caller[{2}] sql[{3}]", event.getTimeMillis(), event.getRowCount(), firstStack, event.getSql()); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java index 826cc34713..4bd2545eda 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java @@ -6,6 +6,7 @@ import io.ebeaninternal.xmapping.api.XmapEbean; import io.ebeaninternal.xmapping.api.XmapRawSql; +import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -55,7 +56,7 @@ private void readDtoMapping(XmapDto dto) { try { dtoClass = Class.forName(dto.getClazz(), false, classLoader); } catch (Exception e) { - CoreLog.internal.error("Could not load dto bean class " + dto.getClazz() + " for ebean xml entry"); + CoreLog.internal.log(Level.ERROR, "Could not load dto bean class " + dto.getClazz() + " for ebean xml entry"); return; } DtoNamedQueries namedQueries = dtoNamedQueries.computeIfAbsent(dtoClass, aClass -> new DtoNamedQueries()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index e6944a9e96..c8b7f8810f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -56,8 +56,8 @@ import io.ebeanservice.docstore.api.DocStoreIntegration; import io.ebeanservice.docstore.api.DocStoreUpdateProcessor; import io.ebeanservice.docstore.none.NoneDocStoreFactory; -import org.slf4j.Logger; +import java.lang.System.Logger.Level; import java.util.*; /** @@ -66,7 +66,7 @@ */ public final class InternalConfiguration { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final TableModState tableModState; private final boolean online; @@ -246,7 +246,7 @@ public ChangeLogListener changeLogListener(ChangeLogListener listener) { */ ReadAuditLogger getReadAuditLogger() { ReadAuditLogger found = bootupClasses.getReadAuditLogger(); - return plugin(found != null ? found : jacksonCorePresent? new DefaultReadAuditLogger(): null); + return plugin(found != null ? found : jacksonCorePresent ? new DefaultReadAuditLogger() : null); } /** @@ -433,7 +433,7 @@ private TransactionScopeManager createTransactionScopeManager() { externalTransactionManager = new JtaTransactionManager(); } if (externalTransactionManager != null) { - log.info("Using Transaction Manager [" + externalTransactionManager.getClass() + "]"); + log.log(Level.INFO, "Using Transaction Manager {0}", externalTransactionManager.getClass()); return new ExternalTransactionScopeManager(externalTransactionManager); } else { return new DefaultTransactionScopeManager(); @@ -523,7 +523,7 @@ private ServerCachePlugin initServerCachePlugin() { if (iterator.hasNext()) { // use the cacheFactory (via classpath service loader) plugin = iterator.next(); - log.debug("using ServerCacheFactory {}", plugin.getClass()); + log.log(Level.DEBUG, "using ServerCacheFactory {0}", plugin.getClass()); } else { // use the built in default l2 caching which is local cache based localL2Caching = true; @@ -605,6 +605,7 @@ public SpiDdlGenerator initDdlGenerator(SpiEbeanServer server) { private static class NoopDdl implements SpiDdlGenerator { private final boolean ddlRun; + NoopDdl(boolean ddlRun) { this.ddlRun = ddlRun; } @@ -612,7 +613,7 @@ private static class NoopDdl implements SpiDdlGenerator { @Override public void execute(boolean online) { if (online && ddlRun) { - CoreLog.log.error("Configured to run DDL but ebean-ddl-generator is not in the classpath (or ebean-test in the test classpath?)"); + CoreLog.log.log(Level.ERROR, "Configured to run DDL but ebean-ddl-generator is not in the classpath (or ebean-test in the test classpath?)"); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java index 695960f6b4..23df28e38a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/OrmQueryRequest.java @@ -24,6 +24,8 @@ import java.util.function.Consumer; import java.util.function.Predicate; +import static java.lang.System.Logger.Level.ERROR; + /** * Wraps the objects involved in executing a Query. */ @@ -244,7 +246,7 @@ public void rollbackTransIfRequired() { // Just log this and carry on. A previous exception has been // thrown and if this rollback throws exception it likely means // that the connection is broken (and the dataSource and db will cleanup) - CoreLog.log.error("Error trying to rollback a transaction (after a prior exception thrown)", e); + CoreLog.log.log(ERROR, "Error trying to rollback a transaction (after a prior exception thrown)", e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java index 1c378cbf9c..031c87688e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java @@ -4,8 +4,8 @@ import io.ebean.config.DatabaseConfig; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.core.ClassPathScanners; -import org.slf4j.Logger; +import java.lang.System.Logger.Level; import java.util.List; import java.util.Set; @@ -14,7 +14,7 @@ */ public class BootupClassPathSearch { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final List packages; private final List scanners; @@ -42,7 +42,6 @@ private BootupClassPathSearch(DatabaseConfig config) { * Search the classPath for the classes we are interested in. */ private BootupClasses getBootupClasses() { - try { BootupClasses bc = new BootupClasses(); @@ -59,7 +58,7 @@ private BootupClasses getBootupClasses() { } long searchTime = System.currentTimeMillis() - st; - log.debug("Classpath search entities[{}] searchTime[{}] in packages[{}]", bc.getEntities().size(), searchTime, packages); + log.log(Level.DEBUG, "Classpath search entities[{0}] searchTime[{1}] in packages[{2}]", bc.getEntities().size(), searchTime, packages); return bc; } catch (Exception ex) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java index 3fc4bbb950..b3f777c6fd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java @@ -13,12 +13,12 @@ import io.ebean.event.readaudit.ReadAuditPrepare; import io.ebean.util.AnnotationUtil; import io.ebeaninternal.api.CoreLog; -import org.slf4j.Logger; import javax.persistence.AttributeConverter; import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.Table; +import java.lang.System.Logger.Level; import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -31,7 +31,7 @@ */ public class BootupClasses implements Predicate> { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final List> embeddableList = new ArrayList<>(); private final List> entityList = new ArrayList<>(); @@ -205,13 +205,13 @@ private T create(Class cls, boolean logOnException) { try { return cls.getConstructor().newInstance(); } catch (NoSuchMethodException e) { - log.debug("Ignore/expected - no default constructor: " +e.getMessage()); + log.log(Level.DEBUG, "Ignore/expected - no default constructor: " + e.getMessage()); return null; } catch (Exception e) { if (logOnException) { // not expected but we log and carry on - log.error("Error creating " + cls, e); + log.log(Level.ERROR, "Error creating " + cls, e); return null; } else { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java index d9a651293a..a9dbf21abb 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java @@ -3,10 +3,10 @@ import io.ebean.util.StringHelper; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.util.UrlHelper; -import org.slf4j.Logger; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.net.URL; import java.util.Collections; import java.util.Enumeration; @@ -20,7 +20,7 @@ */ class ManifestReader { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final Set packageSet = new HashSet<>(); private final ClassLoader classLoader; @@ -55,7 +55,6 @@ Set entityPackages() { * Read all the specific manifest files and return the set of packages containing type query beans. */ private Set read(ClassLoader classLoader, String resourcePath) { - try { Enumeration resources = classLoader.getResources(resourcePath); while (resources.hasMoreElements()) { @@ -64,7 +63,7 @@ private Set read(ClassLoader classLoader, String resourcePath) { } } } catch (IOException e) { - log.warn("Error reading " + resourcePath + " manifest resources", e); + log.log(Level.WARNING, "Error reading " + resourcePath + " manifest resources", e); } return packageSet; } @@ -73,7 +72,6 @@ private Set read(ClassLoader classLoader, String resourcePath) { * Read the entity packages from the manifest. */ private void read(Manifest manifest) throws IOException { - Attributes attributes = manifest.getMainAttributes(); String agentOnlyUse = attributes.getValue("agent-use-only"); if (agentOnlyUse == null || !"true".equalsIgnoreCase(agentOnlyUse.trim())) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java index 2ba7bf20be..4fd54268fe 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java @@ -54,11 +54,11 @@ import io.ebeanservice.docstore.api.mapping.DocMappingBuilder; import io.ebeanservice.docstore.api.mapping.DocPropertyMapping; import io.ebeanservice.docstore.api.mapping.DocumentMapping; -import org.slf4j.Logger; import javax.persistence.PersistenceException; import java.io.IOException; import java.io.StringWriter; +import java.lang.System.Logger.Level; import java.lang.reflect.Modifier; import java.sql.SQLException; import java.sql.Types; @@ -74,7 +74,7 @@ */ public class BeanDescriptor implements BeanType, STreeType, SpiBeanType { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; public enum EntityType { ORM, EMBEDDED, VIEW, SQL, DOC @@ -494,9 +494,6 @@ public BeanProperty propertyByIndex(int pos) { * as they are used to get the imported and exported properties. */ void initialiseId(BeanDescriptorInitContext initContext) { - if (log.isTraceEnabled()) { - log.trace("BeanDescriptor initialise " + fullName); - } if (draftable) { initContext.addDraft(baseTable, draftTable); } @@ -795,7 +792,7 @@ private BeanChange updateBeanChange(PersistRequestBean request) { changeJson.flush(); return beanChange(ChangeType.UPDATE, request.beanId(), changeJson.newJson(), changeJson.oldJson()); } catch (RuntimeException e) { - log.error("Failed to write ChangeLog entry for update", e); + log.log(Level.ERROR, "Failed to write ChangeLog entry for update", e); return null; } } @@ -811,7 +808,7 @@ private BeanChange insertBeanChange(PersistRequestBean request) { jsonWriter.flush(); return beanChange(ChangeType.INSERT, request.beanId(), writer.toString(), null); } catch (IOException e) { - log.error("Failed to write ChangeLog entry for insert", e); + log.log(Level.ERROR, "Failed to write ChangeLog entry for insert", e); return null; } } @@ -2291,11 +2288,11 @@ private ElComparator createComparator(String sortByClause) { private ElComparator createPropertyComparator(SortByClause.Property sortProp) { ElPropertyValue elGetValue = elGetValue(sortProp.getName()); if (elGetValue == null) { - log.error("Sort property [" + sortProp + "] not found in " + beanType + ". Cannot sort."); + log.log(Level.ERROR, "Sort property [" + sortProp + "] not found in " + beanType + ". Cannot sort."); return new ElComparatorNoop<>(); } if (elGetValue.isAssocMany()) { - log.error("Sort property [" + sortProp + "] in " + beanType + " is a many-property. Cannot sort."); + log.log(Level.ERROR, "Sort property [" + sortProp + "] in " + beanType + " is a many-property. Cannot sort."); return new ElComparatorNoop<>(); } Boolean nullsHigh = sortProp.getNullsHigh(); @@ -2771,7 +2768,7 @@ public String softDeletePredicate(String tableAlias) { public void markAsDeleted(EntityBean bean) { if (softDeleteProperty == null) { Object id = getId(bean); - log.info("(Lazy) loading unsuccessful for type:{} id:{} - expecting when bean has been deleted", name(), id); + log.log(Level.INFO, "(Lazy) loading unsuccessful for type:{0} id:{1} - expecting when bean has been deleted", name(), id); bean._ebean_getIntercept().setLazyLoadFailure(id); } else { softDeleteValue(bean); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java index 725a850e2b..4e0c39b394 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.deploy; +import io.avaje.applog.AppLog; import io.ebean.bean.BeanCollection; import io.ebean.bean.EntityBean; import io.ebean.bean.EntityBeanIntercept; @@ -13,10 +14,9 @@ import io.ebeaninternal.server.core.PersistRequest; import io.ebeaninternal.server.core.PersistRequestBean; import io.ebeaninternal.server.transaction.DefaultPersistenceContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; +import java.lang.System.Logger.Level; import java.util.*; /** @@ -26,12 +26,12 @@ */ final class BeanDescriptorCacheHelp { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; - private static final Logger queryLog = LoggerFactory.getLogger("io.ebean.cache.QUERY"); - private static final Logger beanLog = LoggerFactory.getLogger("io.ebean.cache.BEAN"); - private static final Logger manyLog = LoggerFactory.getLogger("io.ebean.cache.COLL"); - private static final Logger natLog = LoggerFactory.getLogger("io.ebean.cache.NATKEY"); + private static final System.Logger queryLog = AppLog.getLogger("io.ebean.cache.QUERY"); + private static final System.Logger beanLog = AppLog.getLogger("io.ebean.cache.BEAN"); + private static final System.Logger manyLog = AppLog.getLogger("io.ebean.cache.COLL"); + private static final System.Logger natLog = AppLog.getLogger("io.ebean.cache.NATKEY"); private final BeanDescriptor desc; private final SpiCacheManager cacheManager; @@ -104,10 +104,10 @@ final class BeanDescriptorCacheHelp { void deriveNotifyFlags() { cacheNotifyOnAll = (invalidateQueryCache || beanCache != null || queryCache != null); cacheNotifyOnDelete = !cacheNotifyOnAll && isNotifyOnDeletes(); - if (log.isDebugEnabled()) { + if (log.isLoggable(Level.DEBUG)) { if (cacheNotifyOnAll || cacheNotifyOnDelete) { String notifyMode = cacheNotifyOnAll ? "All" : "Delete"; - log.debug("l2 caching on {} - beanCaching:{} queryCaching:{} notifyMode:{} ", + log.log(Level.DEBUG, "l2 caching on {0} - beanCaching:{1} queryCaching:{2} notifyMode:{3} ", desc.fullName(), isBeanCaching(), isQueryCaching(), notifyMode); } } @@ -178,8 +178,8 @@ CacheOptions getCacheOptions() { */ void queryCacheClear() { if (queryCache != null) { - if (queryLog.isDebugEnabled()) { - queryLog.debug(" CLEAR {}", cacheName); + if (queryLog.isLoggable(Level.DEBUG)) { + queryLog.log(Level.DEBUG, " CLEAR {0}", cacheName); } queryCache.clear(); } @@ -202,11 +202,11 @@ Object queryCacheGet(Object id) { throw new IllegalStateException("No query cache enabled on " + desc + ". Need explicit @Cache(enableQueryCache=true)"); } Object queryResult = queryCache.get(id); - if (queryLog.isDebugEnabled()) { + if (queryLog.isLoggable(Level.DEBUG)) { if (queryResult == null) { - queryLog.debug(" GET {}({}) - cache miss", cacheName, id); + queryLog.log(Level.DEBUG, " GET {0}({1}) - cache miss", cacheName, id); } else { - queryLog.debug(" GET {}({}) - hit", cacheName, id); + queryLog.log(Level.DEBUG, " GET {0}({1}) - hit", cacheName, id); } } return queryResult; @@ -219,8 +219,8 @@ void queryCachePut(Object id, QueryCacheEntry entry) { if (queryCache == null) { throw new IllegalStateException("No query cache enabled on " + desc + ". Need explicit @Cache(enableQueryCache=true)"); } - if (queryLog.isDebugEnabled()) { - queryLog.debug(" PUT {}({})", cacheName, id); + if (queryLog.isLoggable(Level.DEBUG)) { + queryLog.log(Level.DEBUG, " PUT {0}({1})", cacheName, id); } queryCache.put(id, entry); } @@ -228,16 +228,16 @@ void queryCachePut(Object id, QueryCacheEntry entry) { void manyPropRemove(String propertyName, Object parentId) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName); - if (manyLog.isTraceEnabled()) { - manyLog.trace(" REMOVE {}({}).{}", cacheName, parentId, propertyName); + if (manyLog.isLoggable(Level.TRACE)) { + manyLog.log(Level.TRACE, " REMOVE {0}({1}).{2}", cacheName, parentId, propertyName); } collectionIdsCache.remove(parentId); } void manyPropClear(String propertyName) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName); - if (manyLog.isDebugEnabled()) { - manyLog.debug(" CLEAR {}(*).{} ", cacheName, propertyName); + if (manyLog.isLoggable(Level.DEBUG)) { + manyLog.log(Level.DEBUG, " CLEAR {0}(*).{1} ", cacheName, propertyName); } collectionIdsCache.clear(); } @@ -249,11 +249,11 @@ private CachedManyIds manyPropGet(Object parentId, String propertyName) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName); CachedManyIds entry = (CachedManyIds) collectionIdsCache.get(parentId); if (entry == null) { - if (manyLog.isTraceEnabled()) { - manyLog.trace(" GET {}({}).{} - cache miss", cacheName, parentId, propertyName); + if (manyLog.isLoggable(Level.TRACE)) { + manyLog.log(Level.TRACE, " GET {0}({1}).{2} - cache miss", cacheName, parentId, propertyName); } - } else if (manyLog.isDebugEnabled()) { - manyLog.debug(" GET {}({}).{} - hit", cacheName, parentId, propertyName); + } else if (manyLog.isLoggable(Level.DEBUG)) { + manyLog.log(Level.DEBUG, " GET {0}({1}).{2} - hit", cacheName, parentId, propertyName); } return entry; } @@ -303,12 +303,12 @@ void manyPropPut(BeanPropertyAssocMany many, Object details, Object parentId) changes.put(many.name(), asJson); CachedBeanData newData = data.update(changes, data.getVersion()); - if (beanLog.isDebugEnabled()) { - beanLog.debug(" UPDATE {}({}) changes:{}", cacheName, parentId, changes); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, parentId, changes); } beanCache.put(parentId, newData); } catch (IOException e) { - log.error("Error updating L2 cache", e); + log.log(Level.ERROR, "Error updating L2 cache", e); } } } else { @@ -321,8 +321,8 @@ void manyPropPut(BeanPropertyAssocMany many, Object details, Object parentId) void cachePutManyIds(Object parentId, String manyName, CachedManyIds entry) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, manyName); - if (manyLog.isDebugEnabled()) { - manyLog.debug(" PUT {}({}).{} - ids:{}", cacheName, parentId, manyName, entry); + if (manyLog.isLoggable(Level.DEBUG)) { + manyLog.log(Level.DEBUG, " PUT {0}({1}).{2} - ids:{3}", cacheName, parentId, manyName, entry); } collectionIdsCache.put(parentId, entry); } @@ -353,8 +353,8 @@ BeanCacheResult cacheIdLookup(PersistenceContext context, Collection ids) return new BeanCacheResult<>(); } Map beanDataMap = beanCache.getAll(keys); - if (beanLog.isTraceEnabled()) { - beanLog.trace(" MGET {}({}) - hits:{}", cacheName, ids, beanDataMap.keySet()); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " MGET {0}({1}) - hits:{2}", cacheName, ids, beanDataMap.keySet()); } BeanCacheResult result = new BeanCacheResult<>(); for (Map.Entry entry : beanDataMap.entrySet()) { @@ -375,8 +375,8 @@ BeanCacheResult naturalKeyLookup(PersistenceContext context, Set keys // naturalKey -> Id map Map naturalKeyMap = naturalKeyCache.getAll(keys); - if (natLog.isTraceEnabled()) { - natLog.trace(" MLOOKUP {}({}) - hits:{}", cacheName, keys, naturalKeyMap); + if (natLog.isLoggable(Level.TRACE)) { + natLog.log(Level.TRACE, " MLOOKUP {0}({1}) - hits:{2}", cacheName, keys, naturalKeyMap); } BeanCacheResult result = new BeanCacheResult<>(); @@ -392,8 +392,8 @@ BeanCacheResult naturalKeyLookup(PersistenceContext context, Set keys Set ids = new HashSet<>(naturalKeyMap.values()); Map beanDataMap = beanCache.getAll(ids); - if (beanLog.isTraceEnabled()) { - beanLog.trace(" MGET {}({}) - hits:{}", cacheName, ids, beanDataMap.keySet()); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " MGET {0}({1}) - hits:{2}", cacheName, ids, beanDataMap.keySet()); } // process the hits into beans etc for (Map.Entry entry : beanDataMap.entrySet()) { @@ -437,8 +437,8 @@ private ServerCache getBeanCache() { */ void beanCacheClear() { if (beanCache != null) { - if (beanLog.isDebugEnabled()) { - beanLog.debug(" CLEAR {}", cacheName); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " CLEAR {0}", cacheName); } beanCache.clear(); } @@ -507,14 +507,14 @@ void beanCachePutAllDirect(Collection beans) { } } } - if (beanLog.isDebugEnabled()) { - beanLog.debug(" MPUT {}({})", cacheName, map.keySet()); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " MPUT {0}({1})", cacheName, map.keySet()); } getBeanCache().putAll(map); if (natKeys != null && !natKeys.isEmpty()) { - if (natLog.isDebugEnabled()) { - natLog.debug(" MPUT {}({}, {})", cacheName, naturalKey, natKeys.keySet()); + if (natLog.isLoggable(Level.DEBUG)) { + natLog.log(Level.DEBUG, " MPUT {0}({1}, {2})", cacheName, naturalKey, natKeys.keySet()); } naturalKeyCache.putAll(natKeys); } @@ -526,15 +526,15 @@ void beanCachePutAllDirect(Collection beans) { void beanCachePutDirect(EntityBean bean) { CachedBeanData beanData = beanExtractData(desc, bean); String key = desc.cacheKeyForBean(bean); - if (beanLog.isDebugEnabled()) { - beanLog.debug(" PUT {}({}) data:{}", cacheName, key, beanData); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " PUT {0}({1}) data:{2}", cacheName, key, beanData); } getBeanCache().put(key, beanData); if (naturalKey != null) { String naturalKey = calculateNaturalKey(beanData); if (naturalKey != null) { - if (natLog.isDebugEnabled()) { - natLog.debug(" PUT {}({}, {})", cacheName, naturalKey, key); + if (natLog.isLoggable(Level.DEBUG)) { + natLog.log(Level.DEBUG, " PUT {0}({1}, {2})", cacheName, naturalKey, key); } naturalKeyCache.put(naturalKey, key); } @@ -575,13 +575,13 @@ T beanCacheGet(String key, Boolean readOnly, PersistenceContext context) { private T beanCacheGetInternal(String key, Boolean readOnly, PersistenceContext context) { CachedBeanData data = (CachedBeanData) getBeanCache().get(key); if (data == null) { - if (beanLog.isTraceEnabled()) { - beanLog.trace(" GET {}({}) - cache miss", cacheName, key); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " GET {0}({1}) - cache miss", cacheName, key); } return null; } - if (beanLog.isTraceEnabled()) { - beanLog.trace(" GET {}({}) - hit", cacheName, key); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " GET {0}({1}) - hit", cacheName, key); } return convertToBean(key, readOnly, context, data); } @@ -591,8 +591,8 @@ private T convertToBean(Object id, Boolean readOnly, PersistenceContext context, if (cacheSharableBeans && !Boolean.FALSE.equals(readOnly)) { Object bean = data.getSharableBean(); if (bean != null) { - if (beanLog.isTraceEnabled()) { - beanLog.trace(" GET {}({}) - hit shared bean", cacheName, id); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " GET {0}({1}) - hit shared bean", cacheName, id); } if (desc.isReadAuditing()) { desc.readAuditBean("l2", "", bean); @@ -680,8 +680,8 @@ EntityBean embeddedBeanLoadDirect(CachedBeanData data, PersistenceContext contex */ void beanCacheApplyInvalidate(Collection keys) { if (beanCache != null) { - if (beanLog.isDebugEnabled()) { - beanLog.debug(" MREMOVE {}({})", cacheName, keys); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " MREMOVE {0}({1})", cacheName, keys); } beanCache.removeAll(new HashSet<>(keys)); } @@ -700,8 +700,8 @@ Set beanCacheLoadAll(Set batch, Persis } Map hits = getBeanCache().getAll(ebis.keySet()); - if (beanLog.isTraceEnabled()) { - beanLog.trace(" MLOAD {}({}) - got hits ({})", cacheName, ebis.keySet(), hits.size()); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " MLOAD {0}({1}) - got hits ({2})", cacheName, ebis.keySet(), hits.size()); } Set loaded = new HashSet<>(); @@ -713,19 +713,19 @@ Set beanCacheLoadAll(Set batch, Persis CachedBeanData cacheData = (CachedBeanData) hit.getValue(); if (lazyLoadProperty > -1 && !cacheData.isLoaded(propertyName)) { - if (beanLog.isTraceEnabled()) { - beanLog.trace(" load {}({}) - cache miss on property({})", cacheName, key, propertyName); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " load {0}({1}) - cache miss on property({2})", cacheName, key, propertyName); } } else { CachedBeanDataToBean.load(desc, ebi.getOwner(), cacheData, context); loaded.add(ebi); - if (beanLog.isDebugEnabled()) { - beanLog.debug(" load {}({}) - hit", cacheName, key); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " load {0}({1}) - hit", cacheName, key); } } } - if (!ebis.isEmpty() && beanLog.isTraceEnabled()) { - beanLog.trace(" load {}({}) - cache miss", cacheName, ebis.keySet()); + if (!ebis.isEmpty() && beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " load {0}({1}) - cache miss", cacheName, ebis.keySet()); } return loaded; } @@ -736,21 +736,21 @@ Set beanCacheLoadAll(Set batch, Persis boolean beanCacheLoad(EntityBean bean, EntityBeanIntercept ebi, String key, PersistenceContext context) { CachedBeanData cacheData = (CachedBeanData) getBeanCache().get(key); if (cacheData == null) { - if (beanLog.isTraceEnabled()) { - beanLog.trace(" LOAD {}({}) - cache miss", cacheName, key); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " LOAD {0}({1}) - cache miss", cacheName, key); } return false; } int lazyLoadProperty = ebi.getLazyLoadPropertyIndex(); if (lazyLoadProperty > -1 && !cacheData.isLoaded(ebi.getLazyLoadProperty())) { - if (beanLog.isTraceEnabled()) { - beanLog.trace(" LOAD {}({}) - cache miss on property({})", cacheName, key, ebi.getLazyLoadProperty()); + if (beanLog.isLoggable(Level.TRACE)) { + beanLog.log(Level.TRACE, " LOAD {0}({1}) - cache miss on property({2})", cacheName, key, ebi.getLazyLoadProperty()); } return false; } CachedBeanDataToBean.load(desc, bean, cacheData, context); - if (beanLog.isDebugEnabled()) { - beanLog.debug(" LOAD {}({}) - hit", cacheName, key); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " LOAD {0}({1}) - hit", cacheName, key); } return true; } @@ -874,8 +874,8 @@ void cacheBeanUpdate(String key, Map changes, boolean updateNatu if (existingData != null) { long currentVersion = existingData.getVersion(); if (version > 0 && version < currentVersion) { - if (beanLog.isDebugEnabled()) { - beanLog.debug(" REMOVE {}({}) - version conflict old:{} new:{}", cacheName, key, currentVersion, version); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " REMOVE {0}({1}) - version conflict old:{2} new:{3}", cacheName, key, currentVersion, version); } cache.remove(key); } else { @@ -883,16 +883,16 @@ void cacheBeanUpdate(String key, Map changes, boolean updateNatu version = currentVersion; } CachedBeanData newData = existingData.update(changes, version); - if (beanLog.isDebugEnabled()) { - beanLog.debug(" UPDATE {}({}) changes:{}", cacheName, key, changes); + if (beanLog.isLoggable(Level.DEBUG)) { + beanLog.log(Level.DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, key, changes); } cache.put(key, newData); } if (updateNaturalKey) { Object oldKey = calculateNaturalKey(existingData); if (oldKey != null) { - if (natLog.isDebugEnabled()) { - natLog.debug(".. update {} REMOVE({}) - old key for ({})", cacheName, oldKey, key); + if (natLog.isLoggable(Level.DEBUG)) { + natLog.log(Level.DEBUG, ".. update {0} REMOVE({1}) - old key for ({2})", cacheName, oldKey, key); } naturalKeyCache.remove(oldKey); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java index 82f29361c8..0074b550a1 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java @@ -41,13 +41,13 @@ import io.ebeaninternal.xmapping.api.XmapRawSql; import io.ebeanservice.docstore.api.DocStoreBeanAdapter; import io.ebeanservice.docstore.api.DocStoreFactory; -import org.slf4j.Logger; import javax.persistence.MappedSuperclass; import javax.persistence.PersistenceException; import javax.persistence.Transient; import javax.sql.DataSource; import java.io.Serializable; +import java.lang.System.Logger.Level; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; @@ -58,7 +58,7 @@ */ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTypeManager { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private static final BeanDescComparator beanDescComparator = new BeanDescComparator(); public static final String JAVA_LANG_RECORD = "java.lang.Record"; @@ -309,7 +309,7 @@ public Map deploy(List mappings) { } catch (BeanNotEnhancedException e) { throw e; } catch (RuntimeException e) { - log.error("Error in deployment", e); + log.log(Level.ERROR, "Error in deployment", e); throw e; } } @@ -332,13 +332,13 @@ private void readEntityMapping(ClassLoader classLoader, XmapEntity entityDeploy) try { entityClass = Class.forName(entityClassName, false, classLoader); } catch (Exception e) { - log.error("Could not load entity bean class " + entityClassName + " for ebean.xml entry"); + log.log(Level.ERROR, "Could not load entity bean class " + entityClassName + " for ebean.xml entry"); return; } DeployBeanInfo info = deployInfoMap.get(entityClass); if (info == null) { - log.error("No entity bean for ebean.xml entry " + entityClassName); + log.log(Level.ERROR, "No entity bean for ebean.xml entry " + entityClassName); } else { for (XmapRawSql sql : entityDeploy.getRawSql()) { @@ -601,11 +601,11 @@ private void createListeners() { int pc = postConstructManager.getRegisterCount(); int lc = persistListenerManager.getRegisterCount(); int fc = beanFinderManager.getRegisterCount(); - log.debug("BeanPersistControllers[{}] BeanFinders[{}] BeanPersistListeners[{}] BeanQueryAdapters[{}] BeanPostLoaders[{}] BeanPostConstructors[{}]", cc, fc, lc, qa, pl, pc); + log.log(Level.DEBUG, "BeanPersistControllers[{0}] BeanFinders[{1}] BeanPersistListeners[{2}] BeanQueryAdapters[{3}] BeanPostLoaders[{4}] BeanPostConstructors[{5}]", cc, fc, lc, qa, pl, pc); } private void logStatus() { - log.debug("Entities[{}]", entityBeanCount); + log.log(Level.DEBUG, "Entities[{0}]", entityBeanCount); } /** @@ -865,13 +865,13 @@ private boolean findMappedBy(DeployBeanPropertyAssocMany prop) { for (String possibleMappedBy : matchSet) { String possibleLower = possibleMappedBy.toLowerCase(); if (possibleLower.contains(searchName)) { - // we have a match.. + // we have a match prop.setMappedBy(possibleMappedBy); - - String m = "Implicitly found mappedBy for " + targetDesc + "." + prop; - m += " by searching for [" + searchName + "] against " + matchSet; - log.debug(m); - + if (log.isLoggable(Level.DEBUG)) { + String m = "Implicitly found mappedBy for " + targetDesc + "." + prop; + m += " by searching for [" + searchName + "] against " + matchSet; + log.log(Level.DEBUG, m); + } return true; } } @@ -1207,12 +1207,12 @@ private void setIdGeneration(DeployBeanDescriptor desc) { final DeployIdentityMode identityMode = desc.getIdentityMode(); if (identityMode.isSequence() && !dbIdentity.isSupportsSequence()) { // explicit sequence but not supported by the DatabasePlatform - log.info("Explicit sequence on " + desc.getFullName() + " but not supported by DB Platform - ignored"); + log.log(Level.INFO, "Explicit sequence on {0} but not supported by DB Platform - ignored", desc.getFullName()); identityMode.setIdType(IdType.AUTO); } if (identityMode.isIdentity() && !dbIdentity.isSupportsIdentity()) { // explicit identity but not supported by the DatabasePlatform - log.info("Explicit Identity on " + desc.getFullName() + " but not supported by DB Platform - ignored"); + log.log(Level.INFO, "Explicit Identity on {0} but not supported by DB Platform - ignored", desc.getFullName()); identityMode.setIdType(IdType.AUTO); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanFinderManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanFinderManager.java index ecb99e8b10..5bcf1883fd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanFinderManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanFinderManager.java @@ -4,16 +4,17 @@ import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.core.bootup.BootupClasses; import io.ebeaninternal.server.deploy.meta.DeployBeanDescriptor; -import org.slf4j.Logger; import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Default implementation for BeanFinderFactory. */ final class BeanFinderManager { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final List list; @@ -31,7 +32,7 @@ int getRegisterCount() { void addFindControllers(DeployBeanDescriptor deployDesc) { for (BeanFindController c : list) { if (c.isRegisterFor(deployDesc.getBeanType())) { - log.debug("BeanFindController on[{}] {}", deployDesc.getFullName(), c.getClass().getName()); + log.log(DEBUG, "BeanFindController on[{0}] {1}", deployDesc.getFullName(), c.getClass().getName()); deployDesc.setBeanFinder(c); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java index 4d5e989161..a119ddb90b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java @@ -44,6 +44,7 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.lang.System.Logger.Level; import java.lang.reflect.Field; import java.sql.SQLException; import java.sql.Types; @@ -1433,7 +1434,7 @@ public void jsonRead(SpiJsonReader ctx, EntityBean bean) throws IOException { objValue = null; String msg = "Error trying to use Jackson ObjectMapper to read transient property " + fullName() + " - consider marking this property with @JsonIgnore"; - CoreLog.log.error(msg, e); + CoreLog.log.log(Level.ERROR, msg, e); } } if (jsonDeserialize) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java index 147f623a1d..c2bd2bb4db 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java @@ -27,6 +27,7 @@ import io.ebeanservice.docstore.api.support.DocStructure; import javax.persistence.PersistenceException; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; @@ -432,7 +433,7 @@ ImportedId createImportedId(BeanPropertyAssoc owner, BeanDescriptor target if (!idProp.isEmbedded()) { // simple single scalar id if (cols.length != 1) { - CoreLog.log.error("No Imported Id column for [" + idProp + "] in table [" + join.getTable() + "]"); + CoreLog.log.log(Level.ERROR, "No Imported Id column for [" + idProp + "] in table [" + join.getTable() + "]"); return null; } else { BeanProperty[] idProps = {idProp}; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index 2afae6a9d7..fab75feeab 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -24,6 +24,7 @@ import javax.persistence.PersistenceException; import java.io.IOException; import java.io.StringWriter; +import java.lang.System.Logger.Level; import java.util.*; /** @@ -667,7 +668,7 @@ private ExportedProperty[] createExported() { } } catch (PersistenceException e) { // not found as individual scalar properties - CoreLog.log.error("Could not find a exported property?", e); + CoreLog.log.log(Level.ERROR, "Could not find a exported property?", e); } } else { if (idProp != null) { @@ -962,7 +963,7 @@ public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceCont setValue(bean, collection); } } catch (Exception e) { - CoreLog.log.error("Error setting value from L2 cache", e); + CoreLog.log.log(Level.ERROR, "Error setting value from L2 cache", e); } } @@ -975,7 +976,7 @@ public Object getCacheDataValue(EntityBean bean) { } return jsonWriteCollection(collection); } catch (Exception e) { - CoreLog.log.error("Error building value element collection json for L2 cache", e); + CoreLog.log.log(Level.ERROR, "Error building value element collection json for L2 cache", e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java index 45bced3a22..6eb8d20e32 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanQueryAdapterManager.java @@ -7,6 +7,8 @@ import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Default implementation for creating BeanControllers. */ @@ -28,7 +30,7 @@ int getRegisterCount() { void addQueryAdapter(DeployBeanDescriptor deployDesc) { for (BeanQueryAdapter c : list) { if (c.isRegisterFor(deployDesc.getBeanType())) { - CoreLog.internal.debug("BeanQueryAdapter on[{}] {}", deployDesc.getFullName(), c.getClass().getName()); + CoreLog.internal.log(DEBUG, "BeanQueryAdapter on[{0}] {1}", deployDesc.getFullName(), c.getClass().getName()); deployDesc.addQueryAdapter(c); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java index 0a503314df..80bed85855 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java @@ -6,6 +6,8 @@ import io.ebeaninternal.server.deploy.meta.DeployTableJoin; import io.ebeaninternal.server.deploy.meta.DeployTableJoinColumn; +import java.lang.System.Logger.Level; + /** * Used for associated beans in place of a BeanDescriptor. This is done to avoid @@ -105,7 +107,7 @@ private void addToJoin(String foreignKeyPrefix, DeployTableJoin join, boolean re if (complexKey) { // just to copy the column name rather than prefix with the foreignKeyPrefix. // I think that with complex keys this is the more common approach. - CoreLog.internal.debug("On table[{}] foreign key column [{}]", baseTable, lc); + CoreLog.internal.log(Level.DEBUG, "On table[{0}] foreign key column [{1}]", baseTable, lc); fk = lc; } if (sqlFormulaSelect != null) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistControllerManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistControllerManager.java index 0497d7ef9b..196e4be207 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistControllerManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistControllerManager.java @@ -7,6 +7,8 @@ import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Default implementation for creating BeanControllers. */ @@ -28,7 +30,7 @@ int getRegisterCount() { void addPersistControllers(DeployBeanDescriptor deployDesc) { for (BeanPersistController c : list) { if (c.isRegisterFor(deployDesc.getBeanType())) { - CoreLog.log.debug("BeanPersistController on[{}] {}", deployDesc.getFullName(), c.getClass().getName()); + CoreLog.log.log(DEBUG, "BeanPersistController on[{0}] {1}", deployDesc.getFullName(), c.getClass().getName()); deployDesc.addPersistController(c); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistListenerManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistListenerManager.java index ec0fd3edbf..5c771b0269 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistListenerManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PersistListenerManager.java @@ -7,6 +7,8 @@ import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Manages the assignment/registration of BeanPersistListener with their * respective DeployBeanDescriptor's. @@ -29,7 +31,7 @@ int getRegisterCount() { void addPersistListeners(DeployBeanDescriptor deployDesc) { for (BeanPersistListener listener : list) { if (listener.isRegisterFor(deployDesc.getBeanType())) { - CoreLog.log.debug("BeanPersistListener on[{}] {}", deployDesc.getFullName(), listener.getClass().getName()); + CoreLog.log.log(DEBUG, "BeanPersistListener on[{0}] {1}", deployDesc.getFullName(), listener.getClass().getName()); deployDesc.addPersistListener(listener); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostConstructManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostConstructManager.java index 33b3a5f761..525a87fb34 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostConstructManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostConstructManager.java @@ -7,6 +7,8 @@ import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Default implementation for creating BeanControllers. */ @@ -28,7 +30,7 @@ int getRegisterCount() { void addPostConstructListeners(DeployBeanDescriptor deployDesc) { for (BeanPostConstructListener c : list) { if (c.isRegisterFor(deployDesc.getBeanType())) { - CoreLog.log.debug("BeanPostLoad on[{}] {}", deployDesc.getFullName(), c.getClass().getName()); + CoreLog.log.log(DEBUG, "BeanPostLoad on[{0}] {1}", deployDesc.getFullName(), c.getClass().getName()); deployDesc.addPostConstructListener(c); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostLoadManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostLoadManager.java index babc69c765..1638c1682d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostLoadManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/PostLoadManager.java @@ -7,6 +7,8 @@ import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Default implementation for creating BeanControllers. */ @@ -28,7 +30,7 @@ int getRegisterCount() { void addPostLoad(DeployBeanDescriptor deployDesc) { for (BeanPostLoad c : list) { if (c.isRegisterFor(deployDesc.getBeanType())) { - CoreLog.log.debug("BeanPostLoad on[{}] {}", deployDesc.getFullName(), c.getClass().getName()); + CoreLog.log.log(DEBUG, "BeanPostLoad on[{0}] {1}", deployDesc.getFullName(), c.getClass().getName()); deployDesc.addPostLoad(c); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java index 4605a2d6b1..e33dd310cd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/meta/DeployBeanPropertyLists.java @@ -11,6 +11,8 @@ import java.util.LinkedHashMap; import java.util.List; +import static java.lang.System.Logger.Level.WARNING; + /** * Helper object to classify BeanProperties into appropriate lists. */ @@ -222,7 +224,7 @@ private void allocateToList(BeanProperty prop) { if (versionProperty == null) { versionProperty = prop; } else { - CoreLog.internal.warn("Multiple @Version properties - property " + prop.fullName() + " not treated as a version property"); + CoreLog.internal.log(WARNING, "Multiple @Version properties - property " + prop.fullName() + " not treated as a version property"); } } else if (prop.isDraftDirty()) { draftDirty = prop; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java index 18b0873058..e37d9ea409 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java @@ -15,6 +15,7 @@ import io.ebeaninternal.server.query.SqlJoinType; import javax.persistence.*; +import java.lang.System.Logger.Level; /** * Read the deployment annotations for Associated One beans. @@ -213,10 +214,10 @@ private void readPrimaryKeyJoin(PrimaryKeyJoinColumn primaryKeyJoin, DeployBeanP prop.setPrimaryKeyJoin(true); if (!primaryKeyJoin.name().isEmpty()) { - CoreLog.internal.info("Automatically determining join columns for @PrimaryKeyJoinColumn - ignoring PrimaryKeyJoinColumn.name attribute [{}] on {}", primaryKeyJoin.name(), prop.getFullBeanName()); + CoreLog.internal.log(Level.INFO, "Automatically determining join columns for @PrimaryKeyJoinColumn - ignoring PrimaryKeyJoinColumn.name attribute [{0}] on {1}", primaryKeyJoin.name(), prop.getFullBeanName()); } if (!primaryKeyJoin.referencedColumnName().isEmpty()) { - CoreLog.internal.info("Automatically determining join columns for @PrimaryKeyJoinColumn - Ignoring PrimaryKeyJoinColumn.referencedColumnName attribute [{}] on {}", primaryKeyJoin.referencedColumnName(), prop.getFullBeanName()); + CoreLog.internal.log(Level.INFO, "Automatically determining join columns for @PrimaryKeyJoinColumn - Ignoring PrimaryKeyJoinColumn.referencedColumnName attribute [{0}] on {1}", primaryKeyJoin.referencedColumnName(), prop.getFullBeanName()); } BeanTable baseBeanTable = factory.beanTable(info.getDescriptor().getBeanType()); String localPrimaryKey = baseBeanTable.getIdColumn(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java index 956fa66c7b..36fdc915f2 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java @@ -32,6 +32,8 @@ import javax.persistence.Table; import javax.persistence.UniqueConstraint; +import java.lang.System.Logger.Level; + import static io.ebean.util.AnnotationUtil.typeGet; /** @@ -65,7 +67,7 @@ void parseAttributeOverride() { Column column = override.column(); DeployBeanProperty beanProperty = descriptor.getBeanProperty(propertyName); if (beanProperty == null) { - CoreLog.log.error("AttributeOverride property [" + propertyName + "] not found on " + descriptor.getFullName()); + CoreLog.log.log(Level.ERROR, "AttributeOverride property [" + propertyName + "] not found on " + descriptor.getFullName()); } else { readColumn(column, beanProperty); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java index 426c92048b..14579b621d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java @@ -11,6 +11,7 @@ import javax.persistence.PersistenceException; import javax.persistence.Transient; +import java.lang.System.Logger.Level; import java.lang.reflect.*; /** @@ -84,7 +85,7 @@ private void createProperties(DeployBeanDescriptor desc, Class beanType, i if (replaced != null && !replaced.isTransient()) { String msg = "Huh??? property " + prop.getFullBeanName() + " being defined twice"; msg += " but replaced property was not transient? This is not expected?"; - CoreLog.log.warn(msg); + CoreLog.log.log(Level.WARNING, msg); } } } @@ -111,7 +112,7 @@ private DeployBeanProperty createManyType(DeployBeanDescriptor desc, Class return new DeployBeanPropertySimpleCollection(desc, targetType, manyType); } } catch (NullPointerException e) { - CoreLog.internal.debug("expected non-scalar type {}", e.getMessage()); + CoreLog.internal.log(Level.DEBUG, "expected non-scalar type {0}", e.getMessage()); } return new DeployBeanPropertyAssocMany(desc, targetType, manyType); } @@ -132,7 +133,7 @@ private DeployBeanProperty createProp(DeployBeanDescriptor desc, Field field) // not supporting this field (generic type used) return null; } - CoreLog.internal.warn("Could not find parameter type (via reflection) on " + desc.getFullName() + " " + field.getName()); + CoreLog.internal.log(Level.WARNING, "Could not find parameter type (via reflection) on " + desc.getFullName() + " " + field.getName()); } return createManyType(desc, targetType, manyType); } @@ -151,7 +152,7 @@ private DeployBeanProperty createProp(DeployBeanDescriptor desc, Field field) return new DeployBeanPropertyAssocOne(desc, propertyType); } catch (Exception e) { - CoreLog.log.error("Error with " + desc + " field:" + field.getName(), e); + CoreLog.log.log(Level.ERROR, "Error with " + desc + " field:" + field.getName(), e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java index 43acbf3422..454bc65e1a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java @@ -3,6 +3,7 @@ import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.type.TypeManager; +import java.lang.System.Logger.Level; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -39,7 +40,7 @@ private void readProperties() { final String name = propertyName(method.getName()); properties.add(new DtoMetaProperty(typeManager, dtoType, method, name)); } catch (Exception e) { - CoreLog.log.debug("exclude on " + dtoType + " method " + method, e); + CoreLog.log.log(Level.DEBUG, "exclude on " + dtoType + " method " + method, e); } } } @@ -77,7 +78,7 @@ private void readConstructors() { constructorList.add(new DtoMetaConstructor(typeManager, constructor, dtoType)); } catch (Exception e) { // we don't want that constructor - CoreLog.log.debug("exclude on " + dtoType + " constructor " + constructor, e); + CoreLog.log.log(Level.DEBUG, "exclude on " + dtoType + " constructor " + constructor, e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java index af23a086d4..de9b959ef4 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java @@ -1,9 +1,8 @@ package io.ebeaninternal.server.executor; +import io.avaje.applog.AppLog; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import java.lang.System.Logger.Level; import java.util.concurrent.*; import java.util.concurrent.locks.ReentrantLock; @@ -14,7 +13,7 @@ */ final class DaemonExecutorService { - private static final Logger logger = LoggerFactory.getLogger(DaemonExecutorService.class); + private static final System.Logger logger = AppLog.getLogger(DaemonExecutorService.class); private final ReentrantLock lock = new ReentrantLock(false); private final String namePrefix; @@ -44,19 +43,19 @@ void shutdown() { lock.lock(); try { if (service.isShutdown()) { - logger.debug("DaemonExecutorService[{}] already shut down", namePrefix); + logger.log(Level.DEBUG, "DaemonExecutorService[{0}] already shut down", namePrefix); return; } try { - logger.debug("DaemonExecutorService[{}] shutting down...", namePrefix); + logger.log(Level.DEBUG, "DaemonExecutorService[{0}] shutting down...", namePrefix); service.shutdown(); if (!service.awaitTermination(shutdownWaitSeconds, TimeUnit.SECONDS)) { - logger.info("DaemonExecutorService[{}] shut down timeout exceeded. Terminating running threads.", namePrefix); + logger.log(Level.INFO, "DaemonExecutorService[{0}] shut down timeout exceeded. Terminating running threads.", namePrefix); service.shutdownNow(); } } catch (Exception e) { - logger.error("Error during shutdown of DaemonThreadPool[" + namePrefix + "]", e); + logger.log(Level.ERROR, "Error during shutdown of DaemonThreadPool[" + namePrefix + "]", e); e.printStackTrace(); } } finally { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java index 98265905f2..1a7c23b3e4 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java @@ -1,8 +1,8 @@ package io.ebeaninternal.server.executor; import io.ebeaninternal.api.CoreLog; -import org.slf4j.Logger; +import java.lang.System.Logger.Level; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; @@ -12,7 +12,7 @@ */ public final class DaemonScheduleThreadPool extends ScheduledThreadPoolExecutor { - private static final Logger log = CoreLog.log; + private static final System.Logger log = CoreLog.log; private final ReentrantLock lock = new ReentrantLock(); private final String namePrefix; @@ -38,19 +38,19 @@ public void shutdown() { lock.lock(); try { if (super.isShutdown()) { - log.debug("Already shutdown threadPool {}", namePrefix); + log.log(Level.DEBUG, "Already shutdown threadPool {0}", namePrefix); return; } try { - log.trace("shutting down threadPool {}", namePrefix); + log.log(Level.TRACE, "shutting down threadPool {0}", namePrefix); super.shutdown(); if (!super.awaitTermination(shutdownWaitSeconds, TimeUnit.SECONDS)) { - log.info("Shutdown wait timeout exceeded. Terminating running threads for {}", namePrefix); + log.log(Level.INFO, "Shutdown wait timeout exceeded. Terminating running threads for {0}", namePrefix); super.shutdownNow(); } - log.trace("shutdown complete for threadPool {}", namePrefix); + log.log(Level.TRACE, "shutdown complete for threadPool {0}", namePrefix); } catch (Exception e) { - log.error("Error during shutdown of threadPool " + namePrefix, e); + log.log(Level.ERROR, "Error during shutdown of threadPool " + namePrefix, e); e.printStackTrace(); } } finally { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java index b4c13a8bdf..ce0254a22d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java @@ -1,21 +1,20 @@ package io.ebeaninternal.server.executor; +import io.avaje.applog.AppLog; import io.avaje.lang.NonNullApi; import io.ebean.config.BackgroundExecutorWrapper; import io.ebeaninternal.api.SpiBackgroundExecutor; +import java.lang.System.Logger.Level; import java.util.concurrent.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * The default implementation of the BackgroundExecutor. */ @NonNullApi public final class DefaultBackgroundExecutor implements SpiBackgroundExecutor { - private static final Logger log = LoggerFactory.getLogger("io.ebean.BackgroundExecutor"); + private static final System.Logger log = AppLog.getLogger("io.ebean.BackgroundExecutor"); private final ScheduledExecutorService schedulePool; private final DaemonExecutorService pool; @@ -28,7 +27,7 @@ public DefaultBackgroundExecutor(int schedulePoolSize, int shutdownWaitSeconds, this.schedulePool = new DaemonScheduleThreadPool(schedulePoolSize, shutdownWaitSeconds, namePrefix + "-periodic-"); this.pool = new DaemonExecutorService(shutdownWaitSeconds, namePrefix); this.wrapper = wrapper; - log.debug("Created backgroundExecutor {} (schedulePoolSize={}, shutdownWaitSeconds={})", namePrefix, schedulePoolSize, shutdownWaitSeconds); + log.log(Level.DEBUG, "Created backgroundExecutor {0} (schedulePoolSize={1}, shutdownWaitSeconds={2})", namePrefix, schedulePoolSize, shutdownWaitSeconds); } /** @@ -59,20 +58,20 @@ Runnable wrap(Runnable task) { * This is used in methods that accepts a Runnable and return * either void or ScheduledFuture, as there is * normally no Future.get() call. - * + *

* Note: When submitting a Callable, you must check * Future.get() for exceptions. */ private Runnable logExceptions(Runnable task) { long queued = System.nanoTime(); - log.trace("Queued {}", task); + log.log(Level.TRACE, "Queued {0}", task); return () -> { try { - if (log.isTraceEnabled()) { + if (log.isLoggable(Level.TRACE)) { long start = System.nanoTime(); - log.trace("Start {} (delay time {} us)", task, (start - queued) / 1000L); + log.log(Level.TRACE, "Start {0} (delay time {1} us)", task, (start - queued) / 1000L); task.run(); - log.trace("Stop {} (exec time {} us)", task, (System.nanoTime() - start) / 1000L); + log.log(Level.TRACE, "Stop {0} (exec time {1} us)", task, (System.nanoTime() - start) / 1000L); } else { task.run(); } @@ -80,7 +79,7 @@ private Runnable logExceptions(Runnable task) { // log any exception here. Note they will not bubble up to the calling user // unless Future.get() is checked. (Which is almost never done on scheduled // background executions) - log.error("Error while executing the task {}", task, t); + log.log(Level.ERROR, "Error while executing the task " + task, t); throw t; } }; @@ -128,10 +127,10 @@ public ScheduledFuture schedule(Callable task, long delay, TimeUnit un @Override public void shutdown() { - log.trace("BackgroundExecutor shutting down"); + log.log(Level.TRACE, "BackgroundExecutor shutting down"); schedulePool.shutdown(); pool.shutdown(); - log.debug("BackgroundExecutor stopped"); + log.log(Level.DEBUG, "BackgroundExecutor stopped"); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java index 083e08df2e..c7ae7e0d36 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java @@ -1,6 +1,7 @@ package io.ebeaninternal.server.idgen; import java.io.*; +import java.lang.System.Logger.Level; import java.net.NetworkInterface; import java.net.SocketException; import java.util.*; @@ -8,12 +9,11 @@ /** * IdGenerator for java util UUID. - * + *

* It extends the UuidV1RndIdGenerator so that it can generate rfc4122 compliant Type 1 UUIDs. - * + *

* This generator produces real Type 1 UUIDs (best for sqlserver) - You should use this generator only, * if you can guarantee, that mac addess is uniqe or specify 'ebean.uuidNodeId' in your config file. - * */ public class UuidV1IdGenerator extends UuidV1RndIdGenerator { @@ -34,7 +34,7 @@ public static UuidV1IdGenerator getInstance(String file, String nodeId) { * Returns an instance for given file. */ public static UuidV1IdGenerator getInstance(File file, String nodeId) { - return INSTANCES.computeIfAbsent(file, f ->new UuidV1IdGenerator(f, nodeId == null ? null : nodeId.toLowerCase())); + return INSTANCES.computeIfAbsent(file, f -> new UuidV1IdGenerator(f, nodeId == null ? null : nodeId.toLowerCase())); } /** @@ -60,7 +60,7 @@ private static byte[] parseAlternativeNodeId(String altNodeId) { /** * Find hardware ID. - * + *

* We check all non-loopback networkinterfaces for valid hardwareAddresses * We prefer to take the first non virtual "up" device. If no device (with valid addr) is up, * we take the first down device. @@ -71,21 +71,18 @@ private static byte[] getHardwareId() throws SocketException { while (e.hasMoreElements()) { NetworkInterface network = e.nextElement(); try { - log.trace("Probing interface {}", network); if (!network.isLoopback()) { byte[] addr = network.getHardwareAddress(); if (validAddr(addr)) { if (network.isUp() && !network.isVirtual()) { - log.debug("Using interface {}", network); return addr; } else if (fallbackAddr == null) { - log.debug("Using interface {} as fallback", network); fallbackAddr = addr; } } } } catch (SocketException ex) { - log.debug("Skipping {}", network, ex); + log.log(Level.DEBUG, "Skipping " + network, ex); } } return fallbackAddr; @@ -98,7 +95,7 @@ private static boolean validAddr(byte[] addr) { if (addr != null && addr.length >= 6) { // valid addr has 6 bytes // check if vendor is != 0x000000 or 0xFFFFFF return (addr[0] != 0x00 && addr[1] != 0x00 && addr[2] != 0x00) - ||(addr[0] != 0xFF && addr[1] != 0xFF && addr[2] != 0xFF); + || (addr[0] != 0xFF && addr[1] != 0xFF && addr[2] != 0xFF); } return false; } @@ -122,7 +119,7 @@ private UuidV1IdGenerator(final File stateFile, String altNodeId) { // See, if there is an alternative MAC address set. nodeId = parseAlternativeNodeId(altNodeId); restoreState(); - log.info("Explicitly using ID {} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(Level.INFO, "Explicitly using ID {0} to generate Type 1 UUIDs", getNodeIdentifier()); } UUID uuid = nextId(null); long ts = timeStamp.get(); @@ -130,9 +127,9 @@ private UuidV1IdGenerator(final File stateFile, String altNodeId) { ts /= MILLIS_TO_UUID; saveState(); - log.debug("Saved state: clockSeq {}, timestamp {}, uuid {}, stateFile: {})", clockSeq.get(), new Date(ts), uuid, stateFile); + log.log(Level.DEBUG, "Saved state: clockSeq {0}, timestamp {1}, uuid {2}, stateFile: {3})", clockSeq.get(), new Date(ts), uuid, stateFile); } catch (IOException e) { - log.error("There was a problem while detecting the nodeId. Falling back to random mode. Try using to specify 'ebean.uuidNodeId' property", e); + log.log(Level.ERROR, "There was a problem while detecting the nodeId. Falling back to random mode. Try using to specify 'ebean.uuidNodeId' property", e); useRandomMode(); } } @@ -141,7 +138,7 @@ private UuidV1IdGenerator(final File stateFile, String altNodeId) { * Tries to initialize the generator by retrieving the MAC address from * hardware. If there is no suitable network interface found, it will fall back * to "generate" mode. - * + * * @throws IOException if state file is not readable or tryGenerateMode also * fails. */ @@ -149,16 +146,16 @@ private void tryHardwareId() throws IOException { try { nodeId = getHardwareId(); } catch (IOException e) { - log.error("Error while reading MAC address. Fall back to 'generate' mode", e); + log.log(Level.ERROR, "Error while reading MAC address. Fall back to 'generate' mode", e); tryGenerateMode(); } if (nodeId != null) { restoreState(); - log.info("Using MAC {} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(Level.INFO, "Using MAC {0} to generate Type 1 UUIDs", getNodeIdentifier()); return; } - log.warn("No suitable network interface found. Fall back to 'generate' mode"); + log.log(Level.WARNING, "No suitable network interface found. Fall back to 'generate' mode"); tryGenerateMode(); } @@ -168,11 +165,11 @@ private void tryHardwareId() throws IOException { */ private void tryGenerateMode() throws IOException { if (restoreState()) { - log.info("Using recently generated nodeId {} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(Level.INFO, "Using recently generated nodeId {0} to generate Type 1 UUIDs", getNodeIdentifier()); } else { // RFC 4.5 use random portion for node nodeId = super.getNodeIdBytes(); - log.info("Using a newly generated nodeId {} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(Level.INFO, "Using a newly generated nodeId {0} to generate Type 1 UUIDs", getNodeIdentifier()); } } @@ -183,7 +180,7 @@ private void tryGenerateMode() throws IOException { private void useRandomMode() { canSaveState = false; nodeId = super.getNodeIdBytes(); - log.info("Explicitly using a new random ID {} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(Level.INFO, "Explicitly using a new random ID {0} to generate Type 1 UUIDs", getNodeIdentifier()); } /** @@ -206,7 +203,6 @@ public String getNodeIdentifier() { private boolean restoreState() throws IOException { Properties prop = new Properties(); if (!stateFile.exists()) { - log.debug("State file '{}' does not exist", stateFile); return false; } try (InputStream is = new FileInputStream(stateFile)) { @@ -215,28 +211,27 @@ private boolean restoreState() throws IOException { String propNodeId = prop.getProperty("nodeId"); if (propNodeId == null || propNodeId.isEmpty()) { - log.warn("State file '{}' is incomplete", stateFile); + log.log(Level.WARNING, "State file '{0}' is incomplete", stateFile); return false; // we cannot restore } try { if (nodeId == null) { nodeId = parseAlternativeNodeId(propNodeId); } else if (!getNodeIdentifier().equals(propNodeId)) { - log.warn( - "The nodeId in the state file '{}' has changed from {} to {}. " - + "This can happen when MAC address changes or when two containers share the same state file", - stateFile, propNodeId, getNodeIdentifier()); + log.log(Level.WARNING, + "The nodeId in the state file '{0}' has changed from {1} to {2}. " + + "This can happen when MAC address changes or when two containers share the same state file", + stateFile, propNodeId, getNodeIdentifier()); return false; } Integer seq = Integer.valueOf(prop.getProperty("clockSeq")) & 0x3FFF; Long ts = Long.valueOf(prop.getProperty("timeStamp")); clockSeq.set(seq); timeStamp.set(ts); - log.debug("State successfully restored: {}", prop); return true; - + } catch (IllegalArgumentException nfe) { - log.error("State file '{}' is corrupt", stateFile, nfe); + log.log(Level.ERROR, "State file corrupt: " + stateFile, nfe); } return false; } @@ -259,9 +254,8 @@ protected void saveState() { } try (OutputStream os = new FileOutputStream(stateFile)) { prop.store(os, "ebean uuid state file"); - log.debug("Persisted state to '{}'", stateFile); } catch (IOException e) { - log.error("Could not persist uuid state to '{}'", stateFile, e); + log.log(Level.ERROR, "Could not persist uuid state to: " + stateFile, e); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java index a8fd0b52b0..e5a34d135a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java @@ -1,17 +1,16 @@ package io.ebeaninternal.server.idgen; +import io.avaje.applog.AppLog; import io.ebean.Transaction; import io.ebean.config.dbplatform.PlatformIdGenerator; +import java.lang.System.Logger.Level; import java.security.SecureRandom; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * IdGenerator for (pseudo) type 1 UUIDs. * @@ -27,7 +26,7 @@ */ public class UuidV1RndIdGenerator implements PlatformIdGenerator { - protected static final Logger log = LoggerFactory.getLogger("io.ebean.IDGEN"); + protected static final System.Logger log = AppLog.getLogger("io.ebean.IDGEN"); // UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. protected static final long UUID_EPOCH_OFFSET = 0x01B21DD213814000L; @@ -106,7 +105,7 @@ public UUID nextId(Transaction t) { delta = current - last; if (delta < -10000 * 20000) { - log.info("Clock skew of {} ms detected", delta / -10000); + log.log(Level.INFO, "Clock skew of {} ms detected", delta / -10000); // The clock was adjusted back about 2 seconds, or we were generating a lot of ids too fast // if so, we try to set the current as last and also increment the clockSeq. lock.lock(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/logger/DLoggerFactory.java b/ebean-core/src/main/java/io/ebeaninternal/server/logger/DLoggerFactory.java index 90f6cbafa5..d52e8cb3bd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/logger/DLoggerFactory.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/logger/DLoggerFactory.java @@ -1,8 +1,8 @@ package io.ebeaninternal.server.logger; +import io.avaje.applog.AppLog; import io.ebeaninternal.api.SpiLogger; import io.ebeaninternal.api.SpiLoggerFactory; -import org.slf4j.LoggerFactory; /** * Default SpiLoggerFactory implementation. @@ -14,6 +14,6 @@ public final class DLoggerFactory implements SpiLoggerFactory { */ @Override public SpiLogger create(String name) { - return new DSpiLogger(LoggerFactory.getLogger(name)); + return new DSpiLogger(AppLog.getLogger(name)); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java b/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java index 7c59031ae7..adc6482758 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java @@ -1,33 +1,34 @@ package io.ebeaninternal.server.logger; import io.ebeaninternal.api.SpiLogger; -import org.slf4j.Logger; + +import java.lang.System.Logger.Level; final class DSpiLogger implements SpiLogger { - private final Logger logger; + private final System.Logger logger; - DSpiLogger(Logger logger) { + DSpiLogger(System.Logger logger) { this.logger = logger; } @Override public boolean isDebug() { - return logger.isDebugEnabled(); + return logger.isLoggable(Level.DEBUG); } @Override public boolean isTrace() { - return logger.isTraceEnabled(); + return logger.isLoggable(Level.TRACE); } @Override public void debug(String msg) { - logger.debug(msg); + logger.log(Level.DEBUG, msg); } @Override public void trace(String msg) { - logger.trace(msg); + logger.log(Level.TRACE, msg); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java index 7b3e740859..ccf0689734 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -135,7 +136,7 @@ public void close() { try { pstmt.close(); } catch (SQLException e) { - CoreLog.log.warn("BatchedPstmt Error closing statement", e); + CoreLog.log.log(Level.WARNING, "BatchedPstmt Error closing statement", e); } finally { pstmt = null; } @@ -201,7 +202,7 @@ private void closeInputStreams() { try { inputStream.close(); } catch (IOException e) { - CoreLog.log.warn("BatchedPstmt Error closing inputStream ", e); + CoreLog.log.log(Level.WARNING, "BatchedPstmt Error closing inputStream ", e); } } inputStreams = null; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java index ca81e4ac8a..779362ee89 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java @@ -12,6 +12,7 @@ import io.ebeaninternal.server.type.*; import javax.persistence.PersistenceException; +import java.lang.System.Logger.Level; import java.math.BigDecimal; import java.sql.*; import java.util.Collection; @@ -132,7 +133,7 @@ private void bind(List list, DataBind dataBind, StringBuilder } } catch (SQLException ex) { - CoreLog.log.warn("error binding parameter [{}][{}]", (dataBind.currentPos() - 1), value); + CoreLog.log.log(Level.WARNING, "error binding parameter [{0}][{1}]", (dataBind.currentPos() - 1), value); throw ex; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java index aa2fc8bc26..728c4efcb0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.persist; +import io.avaje.applog.AppLog; import io.ebean.*; import io.ebean.bean.BeanCollection; import io.ebean.bean.BeanCollection.ModifyListenMode; @@ -11,9 +12,8 @@ import io.ebeaninternal.server.core.*; import io.ebeaninternal.server.core.PersistRequest.Type; import io.ebeaninternal.server.deploy.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.sql.SQLException; import java.util.*; @@ -33,8 +33,8 @@ */ public final class DefaultPersister implements Persister { - private static final Logger PUB = LoggerFactory.getLogger("io.ebean.PUB"); - private static final Logger log = CoreLog.internal; + private static final System.Logger PUB = AppLog.getLogger("io.ebean.PUB"); + private static final System.Logger log = CoreLog.internal; /** * Actually does the persisting work. @@ -143,7 +143,7 @@ public List draftRestore(Query query, Transaction transaction) { DraftHandler draftHandler = new DraftHandler<>(desc, transaction); List liveBeans = draftHandler.fetchSourceBeans(query, false); - PUB.debug("draftRestore [{}] count[{}]", desc.name(), liveBeans.size()); + PUB.log(Level.DEBUG, "draftRestore [{0}] count[{1}]", desc.name(), liveBeans.size()); if (liveBeans.isEmpty()) { return Collections.emptyList(); } @@ -156,11 +156,11 @@ public List draftRestore(Query query, Transaction transaction) { // reset @DraftDirty and @DraftReset properties draftHandler.resetDraft(draftBean); - PUB.trace("draftRestore bean [{}] id[{}]", desc.name(), draftHandler.getId()); + PUB.log(Level.TRACE, "draftRestore bean [{0}] id[{1}]", desc.name(), draftHandler.getId()); update(createRequest(draftBean, transaction, null, mgr, Type.UPDATE, Flags.RECURSE)); } - PUB.debug("draftRestore - complete for [{}]", desc.name()); + PUB.log(Level.DEBUG, "draftRestore - complete for [{0}]", desc.name()); return draftHandler.getDrafts(); } @@ -185,7 +185,7 @@ public List publish(Query query, Transaction transaction) { DraftHandler draftHandler = new DraftHandler<>(desc, transaction); List draftBeans = draftHandler.fetchSourceBeans(query, true); - PUB.debug("publish [{}] count[{}]", desc.name(), draftBeans.size()); + PUB.log(Level.DEBUG, "publish [{0}] count[{1}]", desc.name(), draftBeans.size()); if (draftBeans.isEmpty()) { return Collections.emptyList(); } @@ -202,7 +202,7 @@ public List publish(Query query, Transaction transaction) { draftHandler.resetDraft(draftBean); Type persistType = draftHandler.isInsert() ? Type.INSERT : Type.UPDATE; - PUB.trace("publish bean [{}] id[{}] type[{}]", desc.name(), draftHandler.getId(), persistType); + PUB.log(Level.TRACE, "publish bean [{0}] id[{1}] type[{2}]", desc.name(), draftHandler.getId(), persistType); PersistRequestBean request = createRequest(liveBean, transaction, null, mgr, persistType, Flags.PUBLISH_RECURSE); if (persistType == Type.INSERT) { @@ -214,7 +214,7 @@ public List publish(Query query, Transaction transaction) { } draftHandler.updateDrafts(transaction, mgr); - PUB.debug("publish - complete for [{}]", desc.name()); + PUB.log(Level.DEBUG, "publish - complete for [{0}]", desc.name()); return livePublish; } @@ -270,7 +270,7 @@ void resetDraft(T draftBean) { void updateDrafts(Transaction transaction, BeanManager mgr) { if (!draftUpdates.isEmpty()) { // update the dirty status on the drafts that have been published - PUB.debug("publish - update dirty status on [{}] drafts", draftUpdates.size()); + PUB.log(Level.DEBUG, "publish - update dirty status on [{0}] drafts", draftUpdates.size()); for (T draftUpdate : draftUpdates) { update(createRequest(draftUpdate, transaction, null, mgr, Type.UPDATE, Flags.ZERO)); } @@ -491,8 +491,8 @@ private void update(PersistRequestBean request) { } if (request.isDirty()) { request.executeOrQueue(); - } else if (log.isDebugEnabled()) { - log.debug("Update skipped as bean is unchanged: {}", request.bean()); + } else if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "Update skipped as bean is unchanged: {0}", request.bean()); } if (request.isPersistCascade()) { // save all the beans in assocMany's after @@ -538,8 +538,8 @@ private int deleteRequest(PersistRequestBean req, PersistRequestBean draft if (req.isRegisteredForDeleteBean()) { // skip deleting bean. Used where cascade is on // both sides of a relationship - if (log.isDebugEnabled()) { - log.debug("skipping delete on alreadyRegistered {}", req.bean()); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "skipping delete on alreadyRegistered {0}", req.bean()); } return 0; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java index be42d42c23..c839ac9e60 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java @@ -9,6 +9,7 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; import java.io.IOException; +import java.lang.System.Logger.Level; /** * Base for saving entity bean collections and element collections. @@ -71,7 +72,7 @@ final void postElementCollectionUpdate() { String asJson = many.jsonWriteCollection(value); request.addCollectionChange(many.name(), asJson); } catch (IOException e) { - CoreLog.log.error("Error build element collection entry for L2 cache", e); + CoreLog.log.log(Level.ERROR, "Error build element collection entry for L2 cache", e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java index 7b7c2d970d..5b6858e784 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBeans.java @@ -318,7 +318,7 @@ private void saveAssocManyIntersection(boolean queue) { if (transaction.isLogSummary()) { transaction.logSummary(m); } - CoreLog.log.warn(m); + CoreLog.log.log(System.Logger.Level.WARNING, m); } else { if (!many.hasImportedId(otherBean)) { throw new PersistenceException("ManyToMany bean " + otherBean + " does not have an Id value."); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DmlHandler.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DmlHandler.java index 7b82e7faa0..ef3d9d0986 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DmlHandler.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/dml/DmlHandler.java @@ -15,6 +15,8 @@ import java.sql.PreparedStatement; import java.sql.SQLException; +import static java.lang.System.Logger.Level.ERROR; + /** * Base class for Handler implementations. */ @@ -123,7 +125,7 @@ public void close() { dataBind.close(); } } catch (SQLException ex) { - CoreLog.log.error(null, ex); + CoreLog.log.log(ERROR, "Error closing DataBind", ex); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java index b7457bbbb8..6fc84bfb55 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQuery.java @@ -25,6 +25,8 @@ import java.util.*; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.ERROR; + /** * An object that represents a SqlSelect statement. *

@@ -344,7 +346,7 @@ public void close() { auditIterateLogMessage(); } } catch (Throwable e) { - CoreLog.log.error("Error logging read audit logs", e); + CoreLog.log.log(ERROR, "Error logging read audit logs", e); } try { if (dataReader != null) { @@ -352,7 +354,7 @@ public void close() { dataReader = null; } } catch (SQLException e) { - CoreLog.log.error("Error closing dataReader", e); + CoreLog.log.log(ERROR, "Error closing dataReader", e); } JdbcClose.close(pstmt); pstmt = null; @@ -548,7 +550,7 @@ private void updateStatistics() { } transaction().profileEvent(this); } catch (Exception e) { - CoreLog.log.error("Error updating execution statistics", e); + CoreLog.log.log(ERROR, "Error updating execution statistics", e); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java index 894bcfce5e..ad2cdbae86 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryEngine.java @@ -11,16 +11,14 @@ import io.ebean.config.dbplatform.DatabasePlatform; import io.ebean.util.JdbcClose; import io.ebean.util.StringHelper; -import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.api.SpiQuery; import io.ebeaninternal.api.SpiTransaction; import io.ebeaninternal.server.core.DiffHelp; import io.ebeaninternal.server.core.OrmQueryRequest; import io.ebeaninternal.server.core.SpiResultSet; import io.ebeaninternal.server.deploy.BeanDescriptor; -import io.ebeaninternal.server.util.Str; import io.ebeaninternal.server.persist.Binder; -import org.slf4j.Logger; +import io.ebeaninternal.server.util.Str; import javax.persistence.PersistenceException; import java.sql.ResultSet; @@ -32,7 +30,6 @@ */ public final class CQueryEngine { - private static final Logger log = CoreLog.log; private static final String T0 = "t0"; private final int defaultFetchSizeFindList; @@ -195,7 +192,6 @@ public QueryIterator findIterate(OrmQueryRequest request) { } if (!cquery.prepareBindExecuteQueryForwardOnly(forwardOnlyHintOnFindIterate)) { // query has been cancelled already - log.trace("Future fetch already cancelled"); return null; } if (request.logSql()) { @@ -349,7 +345,6 @@ BeanCollection findMany(OrmQueryRequest request) { } if (!cquery.prepareBindExecuteQuery()) { // query has been cancelled already - log.trace("Future fetch already cancelled"); return null; } if (request.logSql()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java index f2fb587f23..78b20dc1c2 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryFetchSingleAttribute.java @@ -19,6 +19,8 @@ import java.util.Set; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.ERROR; + /** * Base compiled query request for single attribute queries. */ @@ -153,7 +155,7 @@ private void close() { dataReader = null; } } catch (SQLException e) { - CoreLog.log.error("Error closing DataReader", e); + CoreLog.log.log(ERROR, "Error closing DataReader", e); } JdbcClose.close(pstmt); pstmt = null; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlan.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlan.java index 7ab1b8a397..490949ab17 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlan.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlan.java @@ -23,6 +23,8 @@ import java.sql.SQLException; import java.util.Set; +import static java.lang.System.Logger.Level.ERROR; + /** * Represents a query for a given SQL statement. *

@@ -313,7 +315,7 @@ final void captureBindForQueryPlan(CQueryPredicates predicates, long executionTi predicates.bind(capture); bindCapture.setBind(capture.bindCapture(), executionTimeMicros, startNanos); } catch (SQLException e) { - CoreLog.log.error("Error capturing bind values", e); + CoreLog.log.log(ERROR, "Error capturing bind values", e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java index e1cb2d3c3e..33f3531761 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java @@ -7,6 +7,7 @@ import io.ebeaninternal.server.transaction.TransactionManager; import io.ebeaninternal.server.type.bindcapture.BindCapture; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.List; @@ -64,7 +65,7 @@ private List collectPlans(QueryPlanRequest request) { } return req.plans(); } catch (SQLException e) { - CoreLog.log.error("Error during query plan collection", e); + CoreLog.log.log(Level.ERROR, "Error during query plan collection", e); return emptyList(); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPredicates.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPredicates.java index 414484d1ea..01e64642f5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPredicates.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPredicates.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Set; +import static java.lang.System.Logger.Level.WARNING; + /** * Compile Query Predicates. *

@@ -339,7 +341,7 @@ private String deriveOrderByWithMany(BeanPropertyAssocMany manyProp) { msg += "] with an incorrect orderBy [" + orderBy + "]. The id property [" + orderById + "]"; msg += " must come before the many property [" + manyProp.name() + "] in the orderBy."; msg += " Ebean has automatically modified the orderBy clause to do this."; - CoreLog.log.warn(msg); + CoreLog.log.log(WARNING, msg); } // the id needs to come before the manyPropName orderBy = orderBy.substring(0, manyPos) + orderById + ", " + orderBy.substring(manyPos); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerExplain.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerExplain.java index d87f66ed63..70c0df722f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerExplain.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerExplain.java @@ -10,6 +10,8 @@ import java.sql.ResultSet; import java.sql.SQLException; +import static java.lang.System.Logger.Level.WARNING; + /** * A QueryPlanLogger that prefixes "EXPLAIN " to the query. This works for Postgres, H2 and MySql. */ @@ -23,7 +25,7 @@ public SpiDbQueryPlan collectPlan(Connection conn, SpiQueryPlan plan, BindCaptur return readQueryPlan(plan, bind, rset); } } catch (SQLException e) { - CoreLog.log.warn("Could not log query plan", e); + CoreLog.log.log(WARNING, "Could not log query plan", e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerOracle.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerOracle.java index f5454bb76c..45c3094afb 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerOracle.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerOracle.java @@ -12,6 +12,8 @@ import java.sql.SQLException; import java.sql.Statement; +import static java.lang.System.Logger.Level.WARNING; + /** * A QueryPlanLogger for oracle. * @@ -30,7 +32,7 @@ public SpiDbQueryPlan collectPlan(Connection conn, SpiQueryPlan plan, BindCaptur return readQueryPlan(plan, bind, rset); } } catch (SQLException e) { - CoreLog.log.warn("Could not log query plan", e); + CoreLog.log.log(WARNING, "Could not log query plan", e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerPostgres.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerPostgres.java index db99ef6721..8b5253c901 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerPostgres.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerPostgres.java @@ -10,6 +10,8 @@ import java.sql.ResultSet; import java.sql.SQLException; +import static java.lang.System.Logger.Level.WARNING; + /** * A QueryPlanLogger for Postgres that prefixes "EXPLAIN ANALYZE" to the query. */ @@ -24,7 +26,7 @@ public SpiDbQueryPlan collectPlan(Connection conn, SpiQueryPlan plan, BindCaptur return readQueryPlanBasic(plan, bind, rset); } } catch (SQLException e) { - CoreLog.log.warn("Could not log query plan: " + explain, e); + CoreLog.log.log(WARNING, "Could not log query plan: " + explain, e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerSqlServer.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerSqlServer.java index 75df42bc16..2da90d98fd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerSqlServer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/QueryPlanLoggerSqlServer.java @@ -11,6 +11,8 @@ import java.sql.SQLException; import java.sql.Statement; +import static java.lang.System.Logger.Level.WARNING; + /** * A QueryPlanLogger for SqlServer. It will return the plan as XML, which can be opened in * Microsoft SQL Server Management Studio. @@ -42,13 +44,13 @@ public SpiDbQueryPlan collectPlan(Connection conn, SpiQueryPlan plan, BindCaptur return createPlan(plan, bind.toString(), xml); } catch (SQLException e) { - CoreLog.log.warn("Could not log query plan", e); + CoreLog.log.log(WARNING, "Could not log query plan", e); return null; } finally { stmt.execute("set statistics xml off"); } } catch (SQLException e) { - CoreLog.log.warn("Could not log query plan", e); + CoreLog.log.log(WARNING, "Could not log query plan", e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java index a018b081f1..30586c4f7f 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java @@ -11,23 +11,16 @@ import io.ebeaninternal.server.deploy.TableJoin; import io.ebeaninternal.server.querydefn.OrmQueryDetail; import io.ebeaninternal.server.querydefn.OrmQueryProperties; -import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.lang.System.Logger.Level; +import java.util.*; /** * Factory for SqlTree. */ public final class SqlTreeBuilder { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final SpiQuery query; private final STreeType desc; @@ -92,10 +85,10 @@ public final class SqlTreeBuilder { this.disableLazyLoad = query.isDisableLazyLoading(); this.readOnly = Boolean.TRUE.equals(query.isReadOnly()); this.subQuery = Type.SQ_EXISTS == query.getType() - || Type.SQ_IN == query.getType() - || Type.ID_LIST == query.getType() - || Type.DELETE == query.getType() - || query.isCountDistinct(); + || Type.SQ_IN == query.getType() + || Type.ID_LIST == query.getType() + || Type.DELETE == query.getType() + || query.isCountDistinct(); this.includeJoin = query.getM2mIncludeJoin(); this.manyWhereJoins = query.getManyWhereJoins(); this.queryDetail = query.getDetail(); @@ -392,7 +385,7 @@ private void buildExtraJoins(STreeType desc, List myList) { private void addPropertyToSubQuery(SqlTreeProperties selectProps, STreeType desc, String propName, String path) { STreeProperty p = desc.findPropertyWithDynamic(propName, path); if (p == null) { - log.error("property [" + propName + "]not found on " + desc + " for query - excluding it."); + log.log(Level.ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); return; } else if (p instanceof STreePropertyAssoc && p.isEmbedded()) { // if the property is embedded we need to lookup the real column name @@ -427,13 +420,13 @@ private void addProperty(SqlTreeProperties selectProps, STreeType desc, OrmQuery if (p != null) { selectProps.add(p); } else { - log.error("property [" + propName + "] not found on " + desc + " for query - excluding it."); + log.log(Level.ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); } } else if (p.isEmbedded() || (p instanceof STreePropertyAssoc && !queryProps.isIncludedBeanJoin(p.name()))) { // add the embedded bean or the *ToOne assoc bean. We skip the check that the *ToOne propName maps to Id property ... selectProps.add(p); } else { - log.error("property [" + p.fullName() + "] expected to be an embedded or *ToOne bean for query - excluding it."); + log.log(Level.ERROR, "property [{0}] expected to be an embedded or *ToOne bean for query - excluding it.", p.fullName()); } } @@ -442,7 +435,7 @@ private void addProperty(SqlTreeProperties selectProps, STreeType desc, OrmQuery // sub class hierarchy if required STreeProperty p = desc.findPropertyWithDynamic(propName, queryProps.getPath()); if (p == null) { - log.error("property [" + propName + "] not found on " + desc + " for query - excluding it."); + log.log(Level.ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); p = desc.findProperty("id"); selectProps.add(p); @@ -542,9 +535,6 @@ private boolean isIncludeMany(String propName, STreePropertyAssocMany manyProp) if (queryDetail.includesPath(propName)) { if (manyProperty != null) { // only one many associated allowed to be included in fetch - if (log.isDebugEnabled()) { - log.debug("Not joining [" + propName + "] as already joined to a Many[" + manyProperty + "]."); - } return false; } manyProperty = manyProp; @@ -559,7 +549,6 @@ private boolean isIncludeMany(String propName, STreePropertyAssocMany manyProp) * Return true if this node is FULLY included resulting in table join. If the * node is not included but its parent has been included then a "bean proxy" * is added and false is returned. - *

*/ private boolean isIncludeBean(String prefix) { if (queryDetail.includesPath(prefix)) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java b/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java index 72b5ee85f5..b49f3baf4e 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java @@ -1,17 +1,17 @@ package io.ebeaninternal.server.readaudit; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; +import io.avaje.applog.AppLog; import io.ebean.event.readaudit.ReadAuditLogger; import io.ebean.event.readaudit.ReadAuditQueryPlan; import io.ebean.event.readaudit.ReadEvent; import io.ebean.text.json.EJson; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonGenerator; import io.ebeaninternal.api.CoreLog; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.StringWriter; +import java.lang.System.Logger.Level; import java.util.Map; /** @@ -19,8 +19,8 @@ */ public class DefaultReadAuditLogger implements ReadAuditLogger { - private static final Logger queryLogger = LoggerFactory.getLogger("io.ebean.ReadAuditQuery"); - private static final Logger auditLogger = LoggerFactory.getLogger("io.ebean.ReadAudit"); + private static final System.Logger queryLogger = AppLog.getLogger("io.ebean.ReadAuditQuery"); + private static final System.Logger auditLogger = AppLog.getLogger("io.ebean.ReadAudit"); protected final JsonFactory jsonFactory = new JsonFactory(); protected int defaultQueryBuffer = 500; @@ -48,9 +48,9 @@ public void queryPlan(ReadAuditQueryPlan queryPlan) { } gen.writeEndObject(); gen.flush(); - queryLogger.info(writer.toString()); + queryLogger.log(Level.INFO, writer.toString()); } catch (IOException e) { - CoreLog.log.error("Error writing Read audit event", e); + CoreLog.log.log(Level.ERROR, "Error writing Read audit event", e); } } @@ -75,9 +75,9 @@ protected void writeEvent(ReadEvent event) { StringWriter writer = new StringWriter(defaultReadBuffer); JsonGenerator gen = jsonFactory.createGenerator(writer); writeDetails(gen, event); - auditLogger.info(writer.toString()); + auditLogger.log(Level.INFO, writer.toString()); } catch (IOException e) { - CoreLog.log.error("Error writing Read audit event", e); + CoreLog.log.log(Level.ERROR, "Error writing Read audit event", e); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java index 16c4aafad4..028b40c19c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java @@ -7,9 +7,11 @@ import io.ebean.util.IOUtils; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.api.SpiProfileHandler; -import org.slf4j.Logger; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.lang.System.Logger.Level; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; @@ -31,8 +33,9 @@ */ public final class DefaultProfileHandler implements SpiProfileHandler, Plugin { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private static final DateTimeFormatter DTF; + static { DTF = new DateTimeFormatterBuilder() .parseCaseInsensitive() @@ -76,7 +79,7 @@ public DefaultProfileHandler(ProfilingConfig config) { this.executor = Executors.newSingleThreadExecutor(); this.dir = new File(config.getDirectory()); if (!dir.exists() && !dir.mkdirs()) { - log.error("failed to mkdirs " + dir.getAbsolutePath()); + log.log(Level.ERROR, "failed to mkdirs " + dir.getAbsolutePath()); } incrementFile(); } @@ -106,7 +109,7 @@ private void flushCurrentFile() { out.close(); out = null; } catch (IOException e) { - log.error("Failed to flush and close transaction profiling file ", e); + log.log(Level.ERROR, "Failed to flush and close transaction profiling file ", e); } } } finally { @@ -126,7 +129,7 @@ private void incrementFile() { File file = new File(dir, "txprofile-" + now + ".tprofile"); out = IOUtils.newWriter(file); } catch (IOException e) { - log.error("Not expected", e); + log.log(Level.ERROR, "Not expected", e); } } finally { lock.unlock(); @@ -149,7 +152,7 @@ private void collect() { } flushCurrentFile(); } catch (Exception e) { - log.warn("Error on collect", e); + log.log(Level.WARNING, "Error on collect", e); } } @@ -180,10 +183,10 @@ private void write(TransactionProfile profile) { if (profileCounter % profilesPerFile == 0) { incrementFile(); - log.debug("profiled {} transactions", profileCounter); + log.log(Level.DEBUG, "profiled {0} transactions", profileCounter); } } catch (IOException e) { - log.warn("Error writing transaction profiling", e); + log.log(Level.WARNING, "Error writing transaction profiling", e); } } @@ -247,16 +250,16 @@ public void online(boolean online) { @Override public void shutdown() { shutdown = true; - log.trace("shutting down"); + log.log(Level.TRACE, "shutting down"); try { executor.shutdown(); if (!executor.awaitTermination(4, TimeUnit.SECONDS)) { - log.info("Shut down timeout exceeded. Terminating profiling consumer thread."); + log.log(Level.INFO, "Shut down timeout exceeded. Terminating profiling consumer thread."); executor.shutdownNow(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); - log.warn("Interrupt on shutdown", e); + log.log(Level.WARNING, "Interrupt on shutdown", e); } flushCurrentFile(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java index 42f5857078..9ee5aa5a00 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java @@ -12,6 +12,7 @@ import io.ebeanservice.docstore.api.DocStoreTransaction; import javax.persistence.PersistenceException; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; @@ -483,7 +484,7 @@ private void deactivate() { } catch (Exception ex) { // the connection pool will automatically remove the // connection if it does not pass the test - CoreLog.log.error("Error closing connection", ex); + CoreLog.log.log(Level.ERROR, "Error closing connection", ex); } connection = null; active = false; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java index 4fb74db18e..38021986f9 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java @@ -14,10 +14,10 @@ import io.ebeaninternal.server.persist.BatchedSqlException; import io.ebeaninternal.server.util.Str; import io.ebeanservice.docstore.api.DocStoreTransaction; -import org.slf4j.Logger; import javax.persistence.PersistenceException; import javax.persistence.RollbackException; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.*; @@ -28,7 +28,7 @@ */ class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes { - private static final Logger log = CoreLog.log; + private static final System.Logger log = CoreLog.log; private static final Object PLACEHOLDER = new Object(); private static final String illegalStateMessage = "Transaction is Inactive"; @@ -356,7 +356,7 @@ private void withEachCallback(Consumer consumer) { try { consumer.accept(callbackList.get(i)); } catch (Exception e) { - log.error("Error executing transaction callback", e); + log.log(Level.ERROR, "Error executing transaction callback", e); } } } @@ -884,7 +884,7 @@ void deactivate() { connection.setReadOnly(false); } } catch (SQLException e) { - log.error("Error setting to readOnly?", e); + log.log(Level.ERROR, "Error setting to readOnly?", e); } try { if (autoCommit) { @@ -892,14 +892,14 @@ void deactivate() { connection.setAutoCommit(true); } } catch (SQLException e) { - log.error("Error setting to readOnly?", e); + log.log(Level.ERROR, "Error setting to readOnly?", e); } try { connection.close(); } catch (Exception ex) { // the connection pool will automatically remove the // connection if it does not pass the test - log.error("Error closing connection", ex); + log.log(Level.ERROR, "Error closing connection", ex); } connection = null; active = false; @@ -932,7 +932,7 @@ private void connectionEndForQueryOnly() { } withEachCallback(TransactionCallback::postCommit); } catch (SQLException e) { - log.error("Error when ending a query only transaction via " + onQueryOnly, e); + log.log(Level.ERROR, "Error when ending a query only transaction via " + onQueryOnly, e); } } @@ -1056,7 +1056,7 @@ public void commit() { private RuntimeException wrapIfNeeded(Exception e) { if (e instanceof PersistenceException) { // keep more specific exception if we have it - return (PersistenceException)e; + return (PersistenceException) e; } return new RollbackException(e); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java index f5edf2688e..3845d0776a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java @@ -4,7 +4,6 @@ import io.ebean.util.JdbcClose; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.api.SpiTransaction; -import org.slf4j.Logger; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -14,13 +13,14 @@ import javax.transaction.Synchronization; import javax.transaction.TransactionSynchronizationRegistry; import javax.transaction.UserTransaction; +import java.lang.System.Logger.Level; /** * Hook into external JTA transaction manager. */ public final class JtaTransactionManager implements ExternalTransactionManager { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private static final String EBEAN_TXN_RESOURCE = "EBEAN_TXN_RESOURCE"; private TransactionManager transactionManager; @@ -87,15 +87,15 @@ public Object getCurrentTransaction() { SpiTransaction currentEbeanTransaction = scope.inScope(); if (currentEbeanTransaction != null) { // NOT expecting this so log WARNING - log.warn("JTA Transaction - no current txn BUT using current Ebean one {}", currentEbeanTransaction.getId()); + log.log(Level.WARNING, "JTA Transaction - no current txn BUT using current Ebean one {0}", currentEbeanTransaction.getId()); return currentEbeanTransaction; } UserTransaction ut = getUserTransaction(); if (ut == null) { // no current JTA transaction - if (log.isDebugEnabled()) { - log.debug("JTA Transaction - no current txn"); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "JTA Transaction - no current txn"); } return null; } @@ -181,27 +181,21 @@ public void beforeCompletion() { public void afterCompletion(int status) { switch (status) { case Status.STATUS_COMMITTED: - if (log.isDebugEnabled()) { - log.debug("Jta Txn [" + transaction.getId() + "] committed"); - } + log.log(Level.DEBUG, "Jta Txn [{0}] committed", transaction.getId()); transaction.postCommit(); // Remove this transaction object as it is completed transactionManager.scope().clearExternal(); break; case Status.STATUS_ROLLEDBACK: - if (log.isDebugEnabled()) { - log.debug("Jta Txn [" + transaction.getId() + "] rollback"); - } + log.log(Level.DEBUG, "Jta Txn [{0}] rollback", transaction.getId()); transaction.postRollback(null); // Remove this transaction object as it is completed transactionManager.scope().clearExternal(); break; default: - if (log.isDebugEnabled()) { - log.debug("Jta Txn [" + transaction.getId() + "] status:" + status); - } + log.log(Level.DEBUG, "Jta Txn [{0}] status:{1}", transaction.getId(), status); } // No matter the completion status of the transaction, we release the connection we got from the pool. diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java index 51f3ece39b..b1a3ee4f8c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java @@ -10,8 +10,8 @@ import io.ebeaninternal.server.cluster.ClusterManager; import io.ebeaninternal.server.core.PersistRequestBean; import io.ebeanservice.docstore.api.DocStoreUpdates; -import org.slf4j.Logger; +import java.lang.System.Logger.Level; import java.util.List; import java.util.Set; @@ -23,7 +23,7 @@ */ final class PostCommitProcessing { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final ClusterManager clusterManager; private final TransactionEvent event; @@ -104,8 +104,8 @@ private boolean isDocStoreUpdate() { private void notifyCluster() { if (remoteTransactionEvent != null && !remoteTransactionEvent.isEmpty()) { // send the interesting events to the cluster - if (log.isDebugEnabled()) { - log.debug("Cluster Send: {}", remoteTransactionEvent); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "Cluster Send: {0}", remoteTransactionEvent); } clusterManager.broadcast(remoteTransactionEvent); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java index d3793a8e4c..c1ba2e773c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java @@ -1,12 +1,12 @@ package io.ebeaninternal.server.transaction; +import io.avaje.applog.AppLog; import io.ebean.cache.QueryCacheEntry; import io.ebean.cache.QueryCacheEntryValidate; import io.ebean.cache.ServerCacheNotification; import io.ebean.cache.ServerCacheNotify; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -19,7 +19,7 @@ */ public final class TableModState implements QueryCacheEntryValidate, ServerCacheNotify { - private static final Logger log = LoggerFactory.getLogger("io.ebean.cache.TABLEMOD"); + private static final System.Logger log = AppLog.getLogger("io.ebean.cache.TABLEMOD"); private final Map tableModStamp = new ConcurrentHashMap<>(); @@ -34,8 +34,8 @@ void touch(Set touchedTables) { for (String tableName : touchedTables) { tableModStamp.put(tableName, modNanoTime); } - if (log.isDebugEnabled()) { - log.debug("TableModState updated - touched:{} modNanoTime:{}", touchedTables, modNanoTime); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "TableModState updated - touched:{0} modNanoTime:{1}", touchedTables, modNanoTime); } } @@ -46,8 +46,8 @@ boolean isValid(Set tables, long sinceNanoTime) { for (String tableName : tables) { Long modTime = tableModStamp.get(tableName); if (modTime != null && modTime >= sinceNanoTime) { - if (log.isTraceEnabled()) { - log.trace("Invalidate on table:{}", tableName); + if (log.isLoggable(Level.TRACE)) { + log.log(Level.TRACE, "Invalidate on table:{0}", tableName); } return false; } @@ -68,15 +68,13 @@ public boolean isValid(QueryCacheEntry entry) { * Update the table modification timestamps based on remote table modification events. *

* Generally this is used with distributed caches (Hazelcast, Ignite etc) via topic. - *

*/ @Override public void notify(ServerCacheNotification notification) { - // use local clock - for slightly more aggressive invalidation (as later) // that removes any concern regarding clock syncing across cluster - if (log.isDebugEnabled()) { - log.debug("ServerCacheNotification:{}", notification); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "ServerCacheNotification:{0}", notification); } touch(notification.getDependentTables()); } @@ -85,14 +83,12 @@ public void notify(ServerCacheNotification notification) { * Update from Remote transaction event. *

* Generally this is used with Clustering (ebean-cluster, k8scache). - *

*/ public void notify(RemoteTableMod tableMod) { - // use local clock - for slightly more aggressive invalidation (as later) // that removes any concern regarding clock syncing across cluster - if (log.isDebugEnabled()) { - log.debug("RemoteTableMod:{}", tableMod); + if (log.isLoggable(Level.DEBUG)) { + log.log(Level.DEBUG, "RemoteTableMod:{0}", tableMod); } touch(tableMod.getTables()); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java index 381ecea412..ace9d4f77a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java @@ -1,5 +1,6 @@ package io.ebeaninternal.server.transaction; +import io.avaje.applog.AppLog; import io.ebean.BackgroundExecutor; import io.ebean.ProfileLocation; import io.ebean.TxScope; @@ -28,11 +29,10 @@ import io.ebeanservice.docstore.api.DocStoreTransaction; import io.ebeanservice.docstore.api.DocStoreUpdateProcessor; import io.ebeanservice.docstore.api.DocStoreUpdates; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.persistence.PersistenceException; import javax.sql.DataSource; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.List; @@ -47,8 +47,8 @@ */ public class TransactionManager implements SpiTransactionManager { - private static final Logger log = CoreLog.log; - private static final Logger clusterLogger = LoggerFactory.getLogger("io.ebean.Cluster"); + private static final System.Logger log = CoreLog.log; + private static final System.Logger clusterLogger = AppLog.getLogger("io.ebean.Cluster"); private final SpiServer server; private final BeanDescriptorManager beanDescriptorManager; @@ -365,7 +365,7 @@ public final void notifyOfRollback(SpiTransaction transaction, Throwable cause) txnLogger.debug(msg); } } catch (Exception ex) { - log.error("Error while notifying TransactionEventListener of rollback event", ex); + log.log(Level.ERROR, "Error while notifying TransactionEventListener of rollback event", ex); } } @@ -416,7 +416,7 @@ public final void notifyOfCommit(SpiTransaction transaction) { postCommit.notifyLocalCache(); backgroundExecutor.execute(postCommit.backgroundNotify()); } catch (Exception ex) { - log.error("NotifyOfCommit failed. L2 Cache potentially not notified.", ex); + log.log(Level.ERROR, "NotifyOfCommit failed. L2 Cache potentially not notified.", ex); } } @@ -442,8 +442,8 @@ private void externalModificationEvent(TransactionEventTable tableEvents) { * Notify local BeanPersistListeners etc of events from another server in the cluster. */ public final void remoteTransactionEvent(RemoteTransactionEvent remoteEvent) { - if (clusterLogger.isDebugEnabled()) { - clusterLogger.debug("processing {}", remoteEvent); + if (clusterLogger.isLoggable(Level.DEBUG)) { + clusterLogger.log(Level.DEBUG, "processing {0}", remoteEvent); } CacheChangeSet changeSet = new CacheChangeSet(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java index ab17244e42..a334942771 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java @@ -4,18 +4,10 @@ import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.core.timezone.DataTimeZone; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.io.StringReader; +import java.io.*; +import java.lang.System.Logger.Level; import java.math.BigDecimal; -import java.sql.Array; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.sql.Time; -import java.sql.Timestamp; +import java.sql.*; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -109,7 +101,7 @@ private void closeInputStreams() { try { inputStream.close(); } catch (IOException e) { - CoreLog.log.warn("Error closing InputStream that was bound to PreparedStatement", e); + CoreLog.log.log(Level.WARNING, "Error closing InputStream that was bound to PreparedStatement", e); } } inputStreams = null; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java index 165d86c5a1..c44670c73c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java @@ -25,11 +25,11 @@ import org.joda.time.LocalDate; import org.joda.time.LocalDateTime; import org.joda.time.LocalTime; -import org.slf4j.Logger; import javax.persistence.AttributeConverter; import javax.persistence.EnumType; import java.io.File; +import java.lang.System.Logger.Level; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; @@ -52,7 +52,7 @@ */ public final class DefaultTypeManager implements TypeManager { - private static final Logger log = CoreLog.internal; + private static final System.Logger log = CoreLog.internal; private final ConcurrentHashMap, ScalarType> typeMap; private final ConcurrentHashMap> nativeMap; @@ -194,7 +194,6 @@ private void loadTypesFromProviders(DatabaseConfig config, Object objectMapper) ExtraTypeFactory plugin = iterator.next(); List> types = plugin.createTypes(config, objectMapper); for (ScalarType type : types) { - log.debug("adding ScalarType {}", type.getClass()); add(type); } } @@ -220,10 +219,10 @@ public void add(ScalarType scalarType) { } private void logAdd(ScalarType scalarType) { - if (log.isTraceEnabled()) { + if (log.isLoggable(Level.TRACE)) { String msg = "ScalarType register [" + scalarType.getClass().getName() + "]"; msg += " for [" + scalarType.getType().getName() + "]"; - log.trace(msg); + log.log(Level.TRACE, msg); } } @@ -676,7 +675,7 @@ private void initialiseCustomScalarTypes(BootupClasses bootupClasses) { } add(scalarType); } catch (Exception e) { - log.error("Error loading ScalarType [" + cls.getName() + "]", e); + log.log(Level.ERROR, "Error loading ScalarType [" + cls.getName() + "]", e); } } } @@ -707,10 +706,10 @@ private void initialiseScalarConverters(BootupClasses bootupClasses) { } ScalarTypeConverter converter = foundType.getDeclaredConstructor().newInstance(); ScalarTypeWrapper stw = new ScalarTypeWrapper(logicalType, wrappedType, converter); - log.debug("Register ScalarTypeWrapper from {} -> {} using:{}", logicalType, persistType, foundType); + log.log(Level.DEBUG, "Register ScalarTypeWrapper from {0} -> {1} using:{2}", logicalType, persistType, foundType); add(stw); } catch (Exception e) { - log.error("Error registering ScalarTypeConverter [" + foundType.getName() + "]", e); + log.log(Level.ERROR, "Error registering ScalarTypeConverter [" + foundType.getName() + "]", e); } } } @@ -731,10 +730,10 @@ private void initialiseAttributeConverters(BootupClasses bootupClasses) { } AttributeConverter converter = foundType.getDeclaredConstructor().newInstance(); ScalarTypeWrapper stw = new ScalarTypeWrapper(logicalType, wrappedType, new AttributeConverterAdapter(converter)); - log.debug("Register ScalarTypeWrapper from {} -> {} using:{}", logicalType, persistType, foundType); + log.log(Level.DEBUG, "Register ScalarTypeWrapper from {0} -> {1} using:{2}", logicalType, persistType, foundType); add(stw); } catch (Exception e) { - log.error("Error registering AttributeConverter [" + foundType.getName() + "]", e); + log.log(Level.ERROR, "Error registering AttributeConverter [" + foundType.getName() + "]", e); } } } @@ -744,7 +743,6 @@ private void initialiseAttributeConverters(BootupClasses bootupClasses) { */ private void initialiseJacksonTypes(DatabaseConfig config) { if (objectMapper != null) { - log.trace("Registering JsonNode type support"); ObjectMapper mapper = (ObjectMapper) objectMapper; jsonNodeClob = new ScalarTypeJsonNode.Clob(mapper); jsonNodeBlob = new ScalarTypeJsonNode.Blob(mapper); @@ -807,7 +805,7 @@ private void initialiseJodaTypes(DatabaseConfig config) { // detect if Joda classes are in the classpath if (config.getClassLoadConfig().isJodaTimePresent()) { // Joda classes are in the classpath so register the types - log.debug("Registering Joda data types"); + log.log(Level.DEBUG, "Registering Joda data types"); addType(LocalDateTime.class, new ScalarTypeJodaLocalDateTime(jsonDateTime)); addType(DateTime.class, new ScalarTypeJodaDateTime(jsonDateTime)); if (config.getDatabasePlatform().supportsNativeJavaTime()) { @@ -822,11 +820,9 @@ private void initialiseJodaTypes(DatabaseConfig config) { if ("normal".equalsIgnoreCase(jodaLocalTimeMode)) { // use the expected/normal local time zone addType(LocalTime.class, new ScalarTypeJodaLocalTime()); - log.debug("registered ScalarTypeJodaLocalTime"); } else if ("utc".equalsIgnoreCase(jodaLocalTimeMode)) { // use the old UTC based addType(LocalTime.class, new ScalarTypeJodaLocalTimeUTC()); - log.debug("registered ScalarTypeJodaLocalTimeUTC"); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java index be712b6591..cddd892310 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java @@ -9,6 +9,7 @@ import io.ebeaninternal.api.CoreLog; import java.io.*; +import java.lang.System.Logger.Level; import java.sql.SQLException; import java.sql.Types; @@ -169,14 +170,14 @@ public long pump(InputStream is, OutputStream out) throws IOException { try { output.close(); } catch (IOException e) { - CoreLog.log.error("Error when closing outputstream", e); + CoreLog.log.log(Level.ERROR, "Error when closing outputStream", e); } } if (input != null) { try { input.close(); } catch (IOException e) { - CoreLog.log.error("Error when closing inputstream ", e); + CoreLog.log.log(Level.ERROR, "Error when closing inputStream ", e); } } } diff --git a/ebean-core/src/main/java/module-info.java b/ebean-core/src/main/java/module-info.java index a0462e27bc..7511a8d0be 100644 --- a/ebean-core/src/main/java/module-info.java +++ b/ebean-core/src/main/java/module-info.java @@ -27,7 +27,6 @@ requires io.avaje.classpath.scanner.api; requires io.avaje.classpath.scanner; requires io.ebean.types; - requires org.slf4j; requires static io.avaje.jsr305x; requires static com.fasterxml.jackson.annotation; diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java index 74ae5a64c8..e91a067f4c 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java @@ -1,5 +1,6 @@ package io.ebeaninternal.dbmigration; +import io.avaje.applog.AppLog; import io.ebean.annotation.Platform; import io.ebean.config.DatabaseConfig; import io.ebean.config.dbplatform.DatabasePlatform; @@ -11,11 +12,10 @@ import io.ebeaninternal.api.SpiEbeanServer; import io.ebeaninternal.dbmigration.model.CurrentModel; import io.ebeaninternal.extraddl.model.ExtraDdlXmlReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.persistence.PersistenceException; import java.io.*; +import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; @@ -27,7 +27,7 @@ */ public class DdlGenerator implements SpiDdlGenerator { - private static final Logger log = LoggerFactory.getLogger(DdlGenerator.class); + private static final System.Logger log = AppLog.getLogger(DdlGenerator.class); private static final String[] BUILD_DIRS = {"target", "build"}; private final SpiEbeanServer server; @@ -60,7 +60,7 @@ public DdlGenerator(SpiEbeanServer server) { this.platform = databasePlatform.getPlatform(); this.platformName = platform.base().name(); if (!config.getTenantMode().isDdlEnabled() && config.isDdlRun()) { - log.warn("DDL can't be run on startup with TenantMode " + config.getTenantMode()); + log.log(Level.WARNING, "DDL can't be run on startup with TenantMode " + config.getTenantMode()); this.runDdl = false; this.useMigrationStoredProcedures = false; } else { @@ -224,7 +224,7 @@ protected void runResourceScript(Connection connection, String sqlScript) throws if (sqlScript != null) { try (InputStream is = getClassLoader().getResourceAsStream(sqlScript)) { if (is == null) { - log.warn("sql script {} was not found as a resource", sqlScript); + log.log(Level.WARNING, "sql script {0} was not found as a resource", sqlScript); } else { String content = readContent(IOUtils.newReader(is)); // 'is' is closed runScript(connection, false, content, sqlScript); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java index ed592e9d2e..9f9384d0d1 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java @@ -1,5 +1,6 @@ package io.ebeaninternal.dbmigration; +import io.avaje.applog.AppLog; import io.ebean.DB; import io.ebean.Database; import io.ebean.annotation.Platform; @@ -21,12 +22,11 @@ import io.ebeaninternal.extraddl.model.DdlScript; import io.ebeaninternal.extraddl.model.ExtraDdl; import io.ebeaninternal.extraddl.model.ExtraDdlXmlReader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.io.Writer; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; import java.util.Properties; @@ -57,7 +57,7 @@ */ public class DefaultDbMigration implements DbMigration { - protected static final Logger logger = LoggerFactory.getLogger("io.ebean.GenerateMigration"); + protected static final System.Logger logger = AppLog.getLogger("io.ebean.GenerateMigration"); private static final String initialVersion = "1.0"; private static final String GENERATED_COMMENT = "THIS IS A GENERATED FILE - DO NOT MODIFY"; @@ -402,7 +402,7 @@ private void generateExtraDdlFor(File migrationDir, DatabasePlatform dbPlatform, */ private void writeExtraDdl(File migrationDir, DdlScript script) throws IOException { String fullName = repeatableMigrationName(script.isInit(), script.getName()); - logger.debug("writing repeatable script {}", fullName); + logger.log(Level.DEBUG, "writing repeatable script {0}", fullName); File file = new File(migrationDir, fullName); try (Writer writer = IOUtils.newWriter(file)) { writer.write(script.getValue()); @@ -419,7 +419,7 @@ private void logError(String message) { if (logToSystemOut) { System.out.println("DbMigration> " + message); } else { - logger.error(message); + logger.log(Level.ERROR, message); } } @@ -430,7 +430,7 @@ private void logInfo(String message, Object value) { if (logToSystemOut) { System.out.println("DbMigration> " + message); } else { - logger.info(message); + logger.log(Level.INFO, message); } } @@ -792,7 +792,7 @@ protected DatabasePlatform platform(Platform platform) { case SQLSERVER: throw new IllegalArgumentException("Please choose the more specific SQLSERVER16 or SQLSERVER17 platform. Refer to issue #1340 for details"); case DB2: - logger.warn("Using DB2LegacyPlatform. It is recommended to migrate to db2luw/db2zos/db2fori. Refer to issue #2514 for details"); + logger.log(Level.WARNING, "Using DB2LegacyPlatform. It is recommended to migrate to db2luw/db2zos/db2fori. Refer to issue #2514 for details"); case GENERIC: return new DatabasePlatform(); default: diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java index 4350bdc836..83b41a4fcd 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MTable.java @@ -1,16 +1,16 @@ package io.ebeaninternal.dbmigration.model; +import io.avaje.applog.AppLog; import io.ebeaninternal.dbmigration.ddlgeneration.platform.DdlHelp; import io.ebeaninternal.dbmigration.migration.*; import io.ebeaninternal.server.deploy.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.*; import static io.ebeaninternal.dbmigration.ddlgeneration.platform.SplitColumns.split; import static io.ebeaninternal.dbmigration.model.MTableIdentity.fromCreateTable; import static io.ebeaninternal.dbmigration.model.MTableIdentity.toCreateTable; +import static java.lang.System.Logger.Level.TRACE; /** * Holds the logical model for a given Table and everything associated to it. @@ -26,7 +26,7 @@ */ public class MTable { - private static final Logger logger = LoggerFactory.getLogger(MTable.class); + private static final System.Logger logger = AppLog.getLogger(MTable.class); private String name; private MTable draftTable; @@ -298,7 +298,7 @@ private void compareColumns(ModelDiff modelDiff, MTable newTable) { diffDropColumn(modelDiff, existingColumn); } else if (newColumn.isDraftOnly() && !draft) { // effectively a drop column (draft only column on a non-draft table) - logger.trace("... drop column {} from table {} as now draftOnly", newColumn.getName(), name); + logger.log(TRACE, "... drop column {0} from table {1} as now draftOnly", newColumn.getName(), name); diffDropColumn(modelDiff, existingColumn); } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java index 9c49ad0aae..e949b17de9 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java @@ -1,11 +1,10 @@ package io.ebeaninternal.dbmigration.model; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import io.avaje.applog.AppLog; import io.ebean.migration.MigrationVersion; import java.io.File; +import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -15,7 +14,7 @@ */ public class MigrationModel { - private static final Logger logger = LoggerFactory.getLogger(MigrationModel.class); + private static final System.Logger logger = AppLog.getLogger(MigrationModel.class); private final ModelContainer model = new ModelContainer(); private final File modelDirectory; @@ -53,7 +52,7 @@ private void readMigrations(boolean initMigration) { if (!initMigration) { for (MigrationResource migrationResource : resources) { - logger.debug("read {}", migrationResource); + logger.log(Level.DEBUG, "read {0}", migrationResource); model.apply(migrationResource.read(), migrationResource.version()); } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java index 83de7e4591..00df18cf84 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java @@ -1,5 +1,6 @@ package io.ebeaninternal.dbmigration.model; +import io.avaje.applog.AppLog; import io.ebean.config.DatabaseConfig; import io.ebean.config.dbplatform.DatabasePlatform; import io.ebean.util.IOUtils; @@ -10,12 +11,11 @@ import io.ebeaninternal.dbmigration.migration.ChangeSet; import io.ebeaninternal.dbmigration.migration.ChangeSetType; import io.ebeaninternal.dbmigration.migration.Migration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; import java.io.Writer; +import java.lang.System.Logger.Level; import java.util.List; /** @@ -23,7 +23,7 @@ */ public class PlatformDdlWriter { - private static final Logger logger = LoggerFactory.getLogger(PlatformDdlWriter.class); + private static final System.Logger logger = AppLog.getLogger(PlatformDdlWriter.class); private final DatabaseConfig databaseConfig; private final PlatformDdl platformDdl; @@ -107,7 +107,7 @@ public File subPath(File path, String suffix) { File subPath = new File(path, suffix); if (!subPath.exists()) { if (!subPath.mkdirs()) { - logger.error("failed to create directories for " + subPath.getAbsolutePath()); + logger.log(Level.ERROR, "failed to create directories for " + subPath.getAbsolutePath()); } } return subPath; diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java index eac6284d5d..379e33bd7a 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java @@ -1,14 +1,14 @@ package io.ebeaninternal.extraddl.model; +import io.avaje.applog.AppLog; import io.ebean.annotation.Platform; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import java.io.IOException; import java.io.InputStream; +import java.lang.System.Logger.Level; import static io.ebeaninternal.api.PlatformMatch.matchPlatform; @@ -17,7 +17,7 @@ */ public class ExtraDdlXmlReader { - private static final Logger logger = LoggerFactory.getLogger(ExtraDdlXmlReader.class); + private static final System.Logger logger = AppLog.getLogger(ExtraDdlXmlReader.class); /** * Return the combined extra DDL that should be run given the platform name. @@ -42,7 +42,7 @@ private static String buildExtra(Platform platform, boolean drops, ExtraDdl read StringBuilder sb = new StringBuilder(300); for (DdlScript script : read.getDdlScript()) { if (script.isDrop() == drops && matchPlatform(platform, script.getPlatforms())) { - logger.debug("include script {}", script.getName()); + logger.log(Level.DEBUG, "include script {}", script.getName()); String value = script.getValue(); sb.append(value); if (value.lastIndexOf(';') == -1) { diff --git a/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java b/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java index 22b03d983f..a523774238 100644 --- a/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java +++ b/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java @@ -1,24 +1,24 @@ package io.localtest; +import io.avaje.applog.AppLog; import io.ebean.DB; import io.ebean.Database; import io.ebean.annotation.PersistBatch; import io.ebean.annotation.Platform; import io.ebeaninternal.api.SpiEbeanServer; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.sql.Types; public abstract class BaseTestCase { - protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class); + protected static System.Logger logger = AppLog.getLogger(BaseTestCase.class); /** * this is the clock delta that may occur between testing machine and db server. * If the clock delta of DB server is in future, an "asOf" query may not find the * correct entry. - * + *

* Note: That some tests may use a Thread.sleep to wait, so that the local system clock * can catch up. So don't set that to a too high value. */ @@ -35,7 +35,7 @@ public abstract class BaseTestCase { // First try, if we get the default server. If this fails, all tests will fail. DB.getDefault(); } catch (Throwable e) { - logger.error("Fatal error while getting ebean-server. Exiting...", e); + logger.log(Level.ERROR, "Fatal error while getting ebean-server. Exiting...", e); System.exit(1); } } @@ -47,7 +47,7 @@ public abstract class BaseTestCase { public boolean isSqlServer() { return Platform.SQLSERVER == platform(); } - + public boolean isDB2() { return Platform.DB2 == platform(); } diff --git a/ebean-externalmapping-xml/pom.xml b/ebean-externalmapping-xml/pom.xml index 0973886bcd..5a5bf08f12 100644 --- a/ebean-externalmapping-xml/pom.xml +++ b/ebean-externalmapping-xml/pom.xml @@ -18,13 +18,6 @@ - - org.slf4j - slf4j-api - 1.7.33 - provided - - io.ebean ebean-externalmapping-api diff --git a/ebean-externalmapping-xml/src/main/java/io/ebeaninternal/xmlmapping/InternalConfigXmlRead.java b/ebean-externalmapping-xml/src/main/java/io/ebeaninternal/xmlmapping/InternalConfigXmlRead.java index 7880b10ae9..19ebdfa09d 100644 --- a/ebean-externalmapping-xml/src/main/java/io/ebeaninternal/xmlmapping/InternalConfigXmlRead.java +++ b/ebean-externalmapping-xml/src/main/java/io/ebeaninternal/xmlmapping/InternalConfigXmlRead.java @@ -4,8 +4,6 @@ import io.avaje.classpath.scanner.ClassPathScannerFactory; import io.avaje.classpath.scanner.Resource; import io.ebeaninternal.xmapping.api.XmapEbean; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -16,8 +14,6 @@ */ class InternalConfigXmlRead { - private static final Logger log = LoggerFactory.getLogger(InternalConfigXmlRead.class); - private final ToXmapEbean to = new ToXmapEbean(); private final ClassLoader classLoader; private final List mappingLocations; @@ -40,7 +36,6 @@ List read() { private List xmlMappingResources() { List scanners = scanners(); List resourceList = new ArrayList<>(); - long st = System.currentTimeMillis(); if (mappingLocations != null && !mappingLocations.isEmpty()) { for (ClassPathScanner finder : scanners) { for (String mappingLocation : mappingLocations) { @@ -48,8 +43,6 @@ private List xmlMappingResources() { } } } - long searchTime = System.currentTimeMillis() - st; - log.debug("Classpath search mappings[{}] searchTime[{}]", resourceList.size(), searchTime); return resourceList; } diff --git a/ebean-externalmapping-xml/src/main/java/module-info.java b/ebean-externalmapping-xml/src/main/java/module-info.java index de792b2dfb..420f85c537 100644 --- a/ebean-externalmapping-xml/src/main/java/module-info.java +++ b/ebean-externalmapping-xml/src/main/java/module-info.java @@ -14,7 +14,6 @@ requires transitive java.xml.bind; requires io.avaje.classpath.scanner.api; requires io.avaje.classpath.scanner; - requires static org.slf4j; requires static java.sql; // for testing uses ClassPathScannerFactory; diff --git a/ebean-postgis/pom.xml b/ebean-postgis/pom.xml index 5e00d8e38d..493d5d33b7 100644 --- a/ebean-postgis/pom.xml +++ b/ebean-postgis/pom.xml @@ -54,14 +54,6 @@ provided - - - org.slf4j - slf4j-api - 1.7.33 - provided - - org.geolatte diff --git a/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java b/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java index 83633aaebd..a934b84119 100644 --- a/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java +++ b/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java @@ -1,5 +1,6 @@ package io.ebean.redis; +import io.avaje.applog.AppLog; import io.ebean.cache.ServerCache; import io.ebean.cache.ServerCacheConfig; import io.ebean.cache.ServerCacheOptions; @@ -11,19 +12,20 @@ import io.ebean.metric.TimedMetricStats; import io.ebean.redis.encode.Encode; import io.ebean.redis.encode.EncodePrefixKey; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import redis.clients.jedis.*; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.Transaction; import redis.clients.jedis.params.ScanParams; import redis.clients.jedis.params.SetParams; import redis.clients.jedis.resps.ScanResult; import redis.clients.jedis.util.SafeEncoder; +import java.lang.System.Logger.Level; import java.util.*; final class RedisCache implements ServerCache { - private static final Logger log = LoggerFactory.getLogger(RedisCache.class); + private static final System.Logger log = AppLog.getLogger(RedisCache.class); private static final String CURSOR_0 = "0"; private static final byte[] CURSOR_0_BYTES = SafeEncoder.encode(CURSOR_0); @@ -67,7 +69,7 @@ private SetParams expiration(ServerCacheConfig config) { if (cacheOptions != null) { final int maxSecsToLive = cacheOptions.getMaxSecsToLive(); if (maxSecsToLive > 0) { - return new SetParams().ex((long)maxSecsToLive); + return new SetParams().ex((long) maxSecsToLive); } } return null; @@ -104,17 +106,17 @@ private Object valueDecode(byte[] data) { } return valueEncode.decode(data); } catch (Exception e) { - log.error("Error decoding data, treated as cache miss", e); + log.log(Level.ERROR, "Error decoding data, treated as cache miss", e); return null; } } private void errorOnRead(Exception e) { - log.warn("Error when reading redis cache", e); + log.log(Level.WARNING, "Error when reading redis cache", e); } private void errorOnWrite(Exception e) { - log.warn("Error when writing redis cache", e); + log.log(Level.WARNING, "Error when writing redis cache", e); } @Override diff --git a/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java b/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java index 3b08ef21f9..4dd991c054 100644 --- a/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java +++ b/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java @@ -1,11 +1,8 @@ package io.ebean.redis; +import io.avaje.applog.AppLog; import io.ebean.BackgroundExecutor; -import io.ebean.cache.ServerCache; -import io.ebean.cache.ServerCacheConfig; -import io.ebean.cache.ServerCacheFactory; -import io.ebean.cache.ServerCacheNotification; -import io.ebean.cache.ServerCacheNotify; +import io.ebean.cache.*; import io.ebean.config.DatabaseConfig; import io.ebean.meta.MetricVisitor; import io.ebean.metric.MetricFactory; @@ -18,18 +15,13 @@ import io.ebeaninternal.server.cache.DefaultServerCache; import io.ebeaninternal.server.cache.DefaultServerCacheConfig; import io.ebeaninternal.server.cache.DefaultServerQueryCache; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import redis.clients.jedis.BinaryJedisPubSub; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.util.SafeEncoder; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; +import java.io.*; +import java.lang.System.Logger.Level; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; @@ -41,11 +33,11 @@ final class RedisCacheFactory implements ServerCacheFactory { - private static final Logger log = LoggerFactory.getLogger(RedisCacheFactory.class); + private static final System.Logger log = AppLog.getLogger(RedisCacheFactory.class); - private static final Logger queryLogger = LoggerFactory.getLogger("io.ebean.cache.QUERY"); - private static final Logger logger = LoggerFactory.getLogger("io.ebean.cache.CACHE"); - private static final Logger tableModLogger = LoggerFactory.getLogger("io.ebean.cache.TABLEMODS"); + private static final System.Logger queryLogger = AppLog.getLogger("io.ebean.cache.QUERY"); + private static final System.Logger logger = AppLog.getLogger("io.ebean.cache.CACHE"); + private static final System.Logger tableModLogger = AppLog.getLogger("io.ebean.cache.TABLEMODS"); private static final int MSG_NEARCACHE_CLEAR = 1; private static final int MSG_NEARCACHE_KEYS = 2; @@ -113,7 +105,7 @@ private JedisPool getJedisPool(DatabaseConfig config) { redisConfig = new RedisConfig(); } redisConfig.loadProperties(config.getProperties()); - log.info("using l2cache redis host {}:{}", redisConfig.getServer(), redisConfig.getPort()); + log.log(Level.INFO, "using l2cache redis host {0}:{1}", redisConfig.getServer(), redisConfig.getPort()); return redisConfig.createPool(); } @@ -168,7 +160,7 @@ private ServerCache createQueryCache(ServerCacheConfig config) { try { RQueryCache cache = queryCaches.get(config.getCacheKey()); if (cache == null) { - logger.debug("create query cache [{}]", config.getCacheKey()); + logger.log(Level.DEBUG, "create query cache [{0}]", config.getCacheKey()); cache = new RQueryCache(new DefaultServerCacheConfig(config)); cache.periodicTrim(executor); queryCaches.put(config.getCacheKey(), cache); @@ -222,7 +214,7 @@ public void clear() { * Process the invalidation message coming from the cluster. */ private void invalidate() { - queryLogger.debug(" CLEAR {}(*) - cluster invalidate", name); + queryLogger.log(Level.DEBUG, " CLEAR {0}(*) - cluster invalidate", name); super.clear(); } } @@ -241,8 +233,8 @@ public void notify(ServerCacheNotification tableModifications) { msg.append(table).append(","); } String formattedMsg = msg.toString(); - if (tableModLogger.isDebugEnabled()) { - tableModLogger.debug("Publish TableMods - {}", formattedMsg); + if (tableModLogger.isLoggable(Level.DEBUG)) { + tableModLogger.log(Level.DEBUG, "Publish TableMods - {0}", formattedMsg); } sendTableMod(formattedMsg); } @@ -270,8 +262,8 @@ private void queryCacheInvalidate(String key) { private void processTableNotify(String rawMessage) { long nanos = System.nanoTime(); try { - if (logger.isDebugEnabled()) { - logger.debug("processTableNotify {}", rawMessage); + if (logger.isLoggable(Level.DEBUG)) { + logger.log(Level.DEBUG, "processTableNotify {0}", rawMessage); } Set tables = new HashSet<>(asList(rawMessage.split(","))); listener.notify(new ServerCacheNotification(tables)); @@ -290,7 +282,7 @@ public void invalidateKeys(String cacheKey, Set keySet) { try { sendMessage(messageInvalidateKeys(cacheKey, keySet)); } catch (IOException e) { - logger.error("failed to transmit invalidateKeys() message", e); + logger.log(Level.ERROR, "failed to transmit invalidateKeys() message", e); } } @@ -299,7 +291,7 @@ public void invalidateKey(String cacheKey, Object id) { try { sendMessage(messageInvalidateKey(cacheKey, id)); } catch (IOException e) { - logger.error("failed to transmit invalidateKeys() message", e); + logger.log(Level.ERROR, "failed to transmit invalidateKeys() message", e); } } @@ -308,7 +300,7 @@ public void invalidateClear(String cacheKey) { try { sendMessage(messageInvalidateClear(cacheKey)); } catch (IOException e) { - logger.error("failed to transmit invalidateKeys() message", e); + logger.log(Level.ERROR, "failed to transmit invalidateKeys() message", e); } } @@ -372,7 +364,7 @@ public void subscribe(Jedis jedis) { @Override public void notifyConnected() { - logger.info("Established connection to Redis"); + logger.log(Level.INFO, "Established connection to Redis"); } /** @@ -403,8 +395,8 @@ private void processNearCacheMessage(byte[] message) { } msgType = oi.readInt(); cacheKey = oi.readUTF(); - if (logger.isDebugEnabled()) { - logger.debug("processNearCacheMessage serverId:{} type:{} cacheKey:{}", sourceServerId, msgType, cacheKey); + if (logger.isLoggable(Level.DEBUG)) { + logger.log(Level.DEBUG, "processNearCacheMessage serverId:{0} type:{1} cacheKey:{2}", sourceServerId, msgType, cacheKey); } switch (msgType) { @@ -431,7 +423,7 @@ private void processNearCacheMessage(byte[] message) { } } catch (IOException | ClassNotFoundException e) { - logger.error("failed to decode near cache message [" + SafeEncoder.encode(message) + "] for cache:" + cacheKey, e); + logger.log(Level.ERROR, "failed to decode near cache message [" + SafeEncoder.encode(message) + "] for cache:" + cacheKey, e); if (cacheKey != null) { nearCacheInvalidateClear(cacheKey); } @@ -457,10 +449,10 @@ private void processL2Message(String message) { queryCacheInvalidate(split[2]); break; default: - logger.error("Unknown L2 message type[{}] on redis channel - message[{}] ", split[0], message); + logger.log(Level.ERROR, "Unknown L2 message type[{0}] on redis channel - message[{1}] ", split[0], message); } } catch (Exception e) { - logger.error("Error handling L2 message[" + message + "]", e); + logger.log(Level.ERROR, "Error handling L2 message[" + message + "]", e); } } } @@ -503,7 +495,7 @@ private void nearCacheInvalidateClear(String cacheKey) { } private void warnNearCacheNotFound(String cacheKey) { - logger.warn("No near cache found for cacheKey [" + cacheKey + "] yet - probably on startup"); + logger.log(Level.WARNING, "No near cache found for cacheKey [" + cacheKey + "] yet - probably on startup"); } } diff --git a/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java b/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java index a6b682bcec..1eab914022 100644 --- a/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java +++ b/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java @@ -1,11 +1,11 @@ package io.ebean.redis.topic; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import io.avaje.applog.AppLog; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; import redis.clients.jedis.exceptions.JedisException; +import java.lang.System.Logger.Level; import java.util.Timer; import java.util.TimerTask; @@ -18,7 +18,7 @@ */ public final class DaemonTopicRunner { - private static final Logger log = LoggerFactory.getLogger(DaemonTopicRunner.class); + private static final System.Logger log = AppLog.getLogger(DaemonTopicRunner.class); private static final long reconnectWaitMillis = 1000; @@ -49,13 +49,13 @@ private void attemptConnections() { try { subscribe(); } catch (JedisException e) { - log.debug("... redis subscribe connection attempt:{} failed:{}", attempts, e.getMessage()); + log.log(Level.DEBUG, "... redis subscribe connection attempt:{0} failed:{1}", attempts, e.getMessage()); try { // wait a little before retrying Thread.sleep(reconnectWaitMillis); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); - log.warn("Interrupted redis re-connection wait", e1); + log.log(Level.WARNING, "Interrupted redis re-connection wait", e1); } } } @@ -70,13 +70,13 @@ private void subscribe() { try { daemonTopic.subscribe(jedis); } catch (Exception e) { - log.error("Lost connection to topic, starting re-connection loop", e); + log.log(Level.ERROR, "Lost connection to topic, starting re-connection loop", e); attemptConnections(); } finally { try { jedis.close(); } catch (Exception e) { - log.warn("Error closing probably broken Redis connection", e); + log.log(Level.WARNING, "Error closing probably broken Redis connection", e); } } } diff --git a/ebean-test/pom.xml b/ebean-test/pom.xml index 068a8b7055..73ac74db4d 100644 --- a/ebean-test/pom.xml +++ b/ebean-test/pom.xml @@ -14,10 +14,9 @@ - org.slf4j - slf4j-api - 1.7.32 - provided + io.avaje + avaje-applog + 1.0 diff --git a/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java b/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java index aecc770269..71822c136d 100644 --- a/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java +++ b/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java @@ -1,9 +1,10 @@ package io.ebean.test; +import io.avaje.applog.AppLog; import io.ebeaninternal.api.SpiLogger; import io.ebeaninternal.api.SpiLoggerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import java.lang.System.Logger.Level; /** * Create a logger that captures the SQL and register it for later access in tests. @@ -15,7 +16,7 @@ public class CapturingLoggerFactory implements SpiLoggerFactory { @Override public SpiLogger create(String name) { - SpiLogger logger = new LogAdapter(LoggerFactory.getLogger(name)); + SpiLogger logger = new LogAdapter(AppLog.getLogger(name)); if (name.equals("io.ebean.SQL")) { return LoggedSql.register(logger); } @@ -24,30 +25,30 @@ public SpiLogger create(String name) { private static final class LogAdapter implements SpiLogger { - private final Logger logger; + private final System.Logger logger; - LogAdapter(Logger logger) { + LogAdapter(System.Logger logger) { this.logger = logger; } @Override public boolean isDebug() { - return logger.isDebugEnabled(); + return logger.isLoggable(Level.DEBUG); } @Override public boolean isTrace() { - return logger.isTraceEnabled(); + return logger.isLoggable(Level.TRACE); } @Override public void debug(String msg) { - logger.debug(msg); + logger.log(Level.DEBUG, msg); } @Override public void trace(String msg) { - logger.trace(msg); + logger.log(Level.TRACE, msg); } } } diff --git a/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java b/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java index fbe48318d6..32d7df4244 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java +++ b/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java @@ -1,14 +1,14 @@ package io.ebean.test.config; +import io.avaje.applog.AppLog; import io.ebean.config.AutoConfigure; import io.ebean.config.DatabaseConfig; import io.ebean.datasource.DataSourceConfig; import io.ebean.test.config.platform.PlatformAutoConfig; import io.ebean.test.config.provider.ProviderAutoConfig; import io.ebean.test.containers.DockerHost; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.Properties; /** @@ -21,7 +21,7 @@ */ public class AutoConfigureForTesting implements AutoConfigure { - private static final Logger log = LoggerFactory.getLogger("io.ebean.test"); + private static final System.Logger log = AppLog.getLogger("io.ebean.test"); /** * System property that can override the platform. mvn clean test -Ddb=sqlserver @@ -38,7 +38,7 @@ public void preConfigure(DatabaseConfig config) { io.avaje.config.Config.asConfiguration().evalModify(properties); } if (!config.isDefaultServer()) { - log.info("skip automatic testing config on non-default server name:{} register:{}", config.getName(), config.isRegister()); + log.log(Level.INFO, "skip automatic testing config on non-default server name:{0} register:{1}", config.getName(), config.isRegister()); return; } if (isExtraServer(config, properties)) { @@ -46,7 +46,7 @@ public void preConfigure(DatabaseConfig config) { return; } String testPlatform = properties.getProperty("ebean.test.platform"); - log.debug("automatic testing config - with ebean.test.platform:{} name:{} environmentDb:{}", testPlatform, config.getName(), environmentDb); + log.log(Level.DEBUG, "automatic testing config - with ebean.test.platform:{0} name:{1} environmentDb:{2}", testPlatform, config.getName(), environmentDb); if (RunOnceMarker.isRun()) { setupPlatform(environmentDb, config); } diff --git a/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java b/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java index 44207a3931..115a831078 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java +++ b/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java @@ -1,11 +1,11 @@ package io.ebean.test.config.platform; +import io.avaje.applog.AppLog; import io.ebean.config.DatabaseConfig; import io.ebean.datasource.DataSourceConfig; import io.ebean.test.containers.DockerHost; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.Properties; /** @@ -13,7 +13,7 @@ */ class Config { - private static final Logger log = LoggerFactory.getLogger("io.ebean.test"); + private static final System.Logger log = AppLog.getLogger("io.ebean.test"); /** * Common optional docker parameters that we just transfer to docker properties. @@ -193,7 +193,7 @@ private DataSourceConfig datasourceDefaults(String platform) { ds.setDriver(driverClass); config.setDataSourceConfig(ds); - log.info("Using jdbc settings - username:{} url:{} driver:{}", ds.getUsername(), ds.getUrl(), ds.getDriver()); + log.log(Level.INFO, "Using jdbc settings - username:{0} url:{1} driver:{2}", ds.getUsername(), ds.getUrl(), ds.getDriver()); if (driverClass != null) { try { diff --git a/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java b/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java index 97ce65e38d..f378f517cd 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java +++ b/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java @@ -1,10 +1,10 @@ package io.ebean.test.config.platform; +import io.avaje.applog.AppLog; import io.ebean.config.DatabaseConfig; import io.ebean.test.containers.ContainerFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -14,7 +14,7 @@ public class PlatformAutoConfig { - private static final Logger log = LoggerFactory.getLogger("io.ebean.test"); + private static final System.Logger log = AppLog.getLogger("io.ebean.test"); /** * Known platforms we can setup locally or via docker container. @@ -62,7 +62,7 @@ public void configExtraDataSource() { Config config = new Config(db, platform, databaseName, this.config); platformSetup.setupExtraDbDataSource(config); - log.debug("configured dataSource for extraDb name:{} url:{}", db, this.config.getDataSourceConfig().getUrl()); + log.log(Level.DEBUG, "configured dataSource for extraDb name:{0} url:{1}", db, this.config.getDataSourceConfig().getUrl()); } } @@ -92,9 +92,9 @@ private void setupDatabase() { Properties dockerProperties = platformSetup.setup(config); if (!dockerProperties.isEmpty()) { if (isDebug()) { - log.info("Docker properties: {}", dockerProperties); + log.log(Level.INFO, "Docker properties: {0}", dockerProperties); } else { - log.debug("Docker properties: {}", dockerProperties); + log.log(Level.DEBUG, "Docker properties: {0}", dockerProperties); } // start the docker container with appropriate configuration new ContainerFactory(dockerProperties, config.getDockerPlatform()).startContainers(); @@ -130,7 +130,7 @@ private boolean isKnownPlatform() { } this.platformSetup = KNOWN_PLATFORMS.get(platform); if (platformSetup == null) { - log.warn("unknown platform {} - skipping platform setup", platform); + log.log(Level.WARNING, "unknown platform {0} - skipping platform setup", platform); } return platformSetup != null; } diff --git a/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java b/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java index 21219ef658..48abb54cf7 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java +++ b/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java @@ -1,12 +1,12 @@ package io.ebean.test.config.provider; +import io.avaje.applog.AppLog; import io.ebean.config.CurrentTenantProvider; import io.ebean.config.CurrentUserProvider; import io.ebean.config.DatabaseConfig; import io.ebean.config.EncryptKeyManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import java.lang.System.Logger.Level; import java.util.Properties; /** @@ -14,7 +14,7 @@ */ public class ProviderAutoConfig { - private static final Logger log = LoggerFactory.getLogger("io.ebean.test"); + private static final System.Logger log = AppLog.getLogger("io.ebean.test"); private final DatabaseConfig config; private final Properties properties; @@ -44,12 +44,12 @@ public void run() { if (keyManager == null) { // Must be 16 Chars for Oracle function String keyVal = properties.getProperty("ebean.test.encryptKey", "simple0123456789"); - log.debug("for testing - using FixedEncryptKeyManager() keyVal:{}", keyVal); + log.log(Level.DEBUG, "for testing - using FixedEncryptKeyManager() keyVal:{0}", keyVal); config.setEncryptKeyManager(new FixedEncryptKeyManager(keyVal)); } if (providerSetFlag > 0) { - log.info(msg(providerSetFlag)); + log.log(Level.INFO, msg(providerSetFlag)); } } diff --git a/ebean-test/src/main/java/module-info.java b/ebean-test/src/main/java/module-info.java index a23d1e65b8..823483a0e9 100644 --- a/ebean-test/src/main/java/module-info.java +++ b/ebean-test/src/main/java/module-info.java @@ -9,7 +9,6 @@ provides io.ebeaninternal.api.SpiLoggerFactory with io.ebean.test.CapturingLoggerFactory; provides io.ebean.config.AutoConfigure with io.ebean.test.config.AutoConfigureForTesting; - requires transitive org.slf4j; requires transitive io.ebean.datasource; requires transitive io.ebean.core; requires transitive io.ebean.ddl.generator; @@ -24,6 +23,7 @@ requires transitive com.h2database; // support testing + requires static org.slf4j; requires static org.junit.jupiter.api; requires static jdk.management; requires static io.avaje.jsr305x; diff --git a/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java b/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java index 1cd6b8848b..9cab33032e 100644 --- a/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java +++ b/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java @@ -1,19 +1,21 @@ package io.ebean.platform.h2; +import io.avaje.applog.AppLog; import org.h2.api.Trigger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.sql.*; +import java.lang.System.Logger.Level; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.time.LocalDateTime; -import java.util.Arrays; /** * H2 database trigger used to populate history tables to support the @History feature. */ public class H2HistoryTrigger implements Trigger { - private static final Logger log = LoggerFactory.getLogger(H2HistoryTrigger.class); + private static final System.Logger log = AppLog.getLogger(H2HistoryTrigger.class); /** * Hardcoding the column and history table suffix for now. Not sure how to get that @@ -70,7 +72,7 @@ public void init(Connection conn, String schemaName, String triggerName, String insertSql.append(");"); this.insertHistorySql = insertSql.toString(); - log.debug("History table insert sql: {}", insertHistorySql); + log.log(Level.DEBUG, "History table insert sql: {0}", insertHistorySql); } @Override @@ -83,9 +85,6 @@ public void fire(Connection connection, Object[] oldRow, Object[] newRow) throws // update event. Set the effective start timestamp to now. newRow[effectStartPosition] = now; } - if (log.isTraceEnabled()) { - log.trace("History insert: {}", Arrays.toString(oldRow)); - } insertIntoHistory(connection, oldRow); } } diff --git a/pom.xml b/pom.xml index 85ab5a776a..1962119806 100644 --- a/pom.xml +++ b/pom.xml @@ -56,13 +56,6 @@ - - org.slf4j - slf4j-api - 1.7.36 - provided - - ch.qos.logback logback-classic From 4252445eb48c5aeb91b9f6e1808a3af68711cb72 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Tue, 23 Aug 2022 15:18:46 +1200 Subject: [PATCH 2/2] Use AppLog and System.Logger for logging - static imports --- .../src/main/java/io/ebean/DbContext.java | 5 +- .../src/main/java/io/ebean/EbeanVersion.java | 11 +- .../config/dbplatform/DatabasePlatform.java | 9 +- .../dbplatform/SequenceIdGenerator.java | 8 +- .../java/io/ebean/event/ShutdownManager.java | 15 +- .../io/ebean/text/csv/DefaultCsvCallback.java | 7 +- .../main/java/io/ebean/util/JdbcClose.java | 13 +- .../service/DefaultAutoTuneService.java | 25 ++-- .../service/ProfileOriginNodeUsage.java | 7 +- .../server/cache/DefaultCacheHolder.java | 10 +- .../server/cache/DefaultServerCache.java | 10 +- .../cache/DefaultServerCacheManager.java | 12 +- .../changelog/DefaultChangeLogListener.java | 8 +- .../server/cluster/ClusterManager.java | 7 +- .../server/core/BeanRequest.java | 4 +- .../server/core/DatabasePlatformFactory.java | 8 +- .../server/core/DefaultBeanLoader.java | 7 +- .../server/core/DefaultContainer.java | 11 +- .../server/core/DefaultServer.java | 10 +- .../server/core/InternalConfigXmlMap.java | 5 +- .../server/core/InternalConfiguration.java | 9 +- .../core/bootup/BootupClassPathSearch.java | 5 +- .../server/core/bootup/BootupClasses.java | 8 +- .../server/core/bootup/ManifestReader.java | 5 +- .../server/deploy/BeanDescriptor.java | 13 +- .../deploy/BeanDescriptorCacheHelp.java | 135 +++++++++--------- .../server/deploy/BeanDescriptorManager.java | 21 +-- .../server/deploy/BeanProperty.java | 5 +- .../server/deploy/BeanPropertyAssoc.java | 5 +- .../server/deploy/BeanPropertyAssocMany.java | 9 +- .../server/deploy/BeanTable.java | 4 +- .../deploy/parse/AnnotationAssocOnes.java | 7 +- .../server/deploy/parse/AnnotationClass.java | 28 +--- .../deploy/parse/DeployCreateProperties.java | 11 +- .../server/dto/DtoMetaBuilder.java | 7 +- .../executor/DaemonExecutorService.java | 11 +- .../executor/DaemonScheduleThreadPool.java | 13 +- .../executor/DefaultBackgroundExecutor.java | 19 +-- .../server/idgen/UuidV1IdGenerator.java | 31 ++-- .../server/idgen/UuidV1RndIdGenerator.java | 5 +- .../server/logger/DSpiLogger.java | 11 +- .../server/persist/BatchedPstmt.java | 7 +- .../ebeaninternal/server/persist/Binder.java | 5 +- .../server/persist/DefaultPersister.java | 26 ++-- .../server/persist/SaveManyBase.java | 5 +- .../server/query/CQueryPlanManager.java | 4 +- .../server/query/SqlTreeBuilder.java | 11 +- .../readaudit/DefaultReadAuditLogger.java | 12 +- .../transaction/DefaultProfileHandler.java | 20 +-- .../ImplicitReadOnlyTransaction.java | 5 +- .../server/transaction/JdbcTransaction.java | 13 +- .../transaction/JtaTransactionManager.java | 16 ++- .../transaction/PostCommitProcessing.java | 7 +- .../server/transaction/TableModState.java | 20 +-- .../transaction/TransactionManager.java | 12 +- .../ebeaninternal/server/type/DataBind.java | 5 +- .../server/type/DefaultTypeManager.java | 19 +-- .../server/type/ScalarTypeFile.java | 7 +- .../dbmigration/DdlGenerator.java | 7 +- .../dbmigration/DefaultDbMigration.java | 10 +- .../dbmigration/model/MigrationModel.java | 5 +- .../dbmigration/model/PlatformDdlWriter.java | 5 +- .../extraddl/model/ExtraDdlXmlReader.java | 4 +- .../test/java/io/localtest/BaseTestCase.java | 5 +- .../main/java/io/ebean/redis/RedisCache.java | 10 +- .../io/ebean/redis/RedisCacheFactory.java | 36 ++--- .../ebean/redis/topic/DaemonTopicRunner.java | 11 +- .../io/ebean/test/CapturingLoggerFactory.java | 11 +- .../test/config/AutoConfigureForTesting.java | 8 +- .../io/ebean/test/config/platform/Config.java | 6 +- .../config/platform/PlatformAutoConfig.java | 10 +- .../config/provider/ProviderAutoConfig.java | 8 +- .../ebean/platform/h2/H2HistoryTrigger.java | 5 +- 73 files changed, 473 insertions(+), 416 deletions(-) diff --git a/ebean-api/src/main/java/io/ebean/DbContext.java b/ebean-api/src/main/java/io/ebean/DbContext.java index c098f079a4..3dca530a61 100644 --- a/ebean-api/src/main/java/io/ebean/DbContext.java +++ b/ebean-api/src/main/java/io/ebean/DbContext.java @@ -4,11 +4,12 @@ import io.ebean.datasource.DataSourceConfigurationException; import javax.persistence.PersistenceException; -import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.ERROR; + /** * Holds Database instances. */ @@ -52,7 +53,7 @@ private DbContext() { throw new DataSourceConfigurationException(msg, e); } catch (Throwable e) { - log.log(Level.ERROR, "Error trying to create the default Database", e); + log.log(ERROR, "Error trying to create the default Database", e); throw new RuntimeException(e); } } diff --git a/ebean-api/src/main/java/io/ebean/EbeanVersion.java b/ebean-api/src/main/java/io/ebean/EbeanVersion.java index 7eaf5a52a7..aeb855efce 100644 --- a/ebean-api/src/main/java/io/ebean/EbeanVersion.java +++ b/ebean-api/src/main/java/io/ebean/EbeanVersion.java @@ -6,9 +6,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.LineNumberReader; -import java.lang.System.Logger.Level; import java.util.Properties; +import static java.lang.System.Logger.Level.*; + /** * Class to determine the ebean version. * @@ -36,12 +37,12 @@ private static void readVersion() { if (in != null) { try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(in))) { version = reader.readLine(); - log.log(Level.INFO, "ebean version: {0}", version); + log.log(INFO, "ebean version: {0}", version); } } } } catch (IOException e) { - log.log(Level.WARNING, "Could not determine ebean version: {0}", e.getMessage()); + log.log(WARNING, "Could not determine ebean version: {0}", e.getMessage()); } } @@ -53,13 +54,13 @@ private static void checkAgentVersion() { String agentVersion = readVersion(in); if (agentVersion != null) { if (checkMinAgentVersion(agentVersion)) { - log.log(Level.ERROR, "Expected minimum ebean-agent version {0}.{1}.0 but we have {2}, please update the ebean-agent", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, agentVersion); + log.log(ERROR, "Expected minimum ebean-agent version {0}.{1}.0 but we have {2}, please update the ebean-agent", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, agentVersion); } } } } } catch (IOException e) { - log.log(Level.WARNING, "Could not check minimum ebean-agent version {0}.{1}.0 required due to - {2}", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, e.getMessage()); + log.log(WARNING, "Could not check minimum ebean-agent version {0}.{1}.0 required due to - {2}", MIN_AGENT_MAJOR_VERSION, MIN_AGENT_MINOR_VERSION, e.getMessage()); } } diff --git a/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java b/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java index 53d4163726..3bb2cced81 100644 --- a/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java +++ b/ebean-api/src/main/java/io/ebean/config/dbplatform/DatabasePlatform.java @@ -11,9 +11,10 @@ import javax.persistence.PersistenceException; import javax.sql.DataSource; -import java.lang.System.Logger.Level; import java.sql.*; +import static java.lang.System.Logger.Level.*; + /** * Database platform specific settings. */ @@ -659,7 +660,7 @@ public String convertQuotedIdentifiers(String dbName) { if (isQuote(dbName.charAt(dbName.length() - 1))) { return openQuote + dbName.substring(1, dbName.length() - 1) + closeQuote; } else { - log.log(Level.ERROR, "Missing backquote on [" + dbName + "]"); + log.log(ERROR, "Missing backquote on [" + dbName + "]"); } } else if (allQuotedIdentifiers) { return openQuote + dbName + closeQuote; @@ -722,7 +723,7 @@ public String fromForUpdate(Query.LockWait lockWait) { protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType) { // silently assume the database does not support the "for update" clause. - log.log(Level.INFO, "it seems your database does not support the 'for update' clause"); + log.log(INFO, "it seems your database does not support the 'for update' clause"); return sql; } @@ -756,7 +757,7 @@ public void createSchemaIfNotExists(String dbSchema, Connection connection) thro if (!schemaExists(dbSchema, connection)) { Statement query = connection.createStatement(); try { - log.log(Level.DEBUG, "create schema:{0}", dbSchema); + log.log(DEBUG, "create schema:{0}", dbSchema); query.executeUpdate("create schema " + dbSchema); } finally { JdbcClose.close(query); diff --git a/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java b/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java index 658c5e94e6..246e8f1c05 100644 --- a/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java +++ b/ebean-api/src/main/java/io/ebean/config/dbplatform/SequenceIdGenerator.java @@ -7,7 +7,6 @@ import javax.persistence.PersistenceException; import javax.sql.DataSource; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -19,6 +18,9 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.ERROR; + /** * Database sequence based IdGenerator. */ @@ -120,7 +122,7 @@ private void loadMore(int requestSize) { protected void loadInBackground(final int requestSize) { if (currentlyBackgroundLoading.get()) { // skip as already background loading - log.log(Level.DEBUG, "... skip background sequence load (another load in progress)"); + log.log(DEBUG, "... skip background sequence load (another load in progress)"); return; } currentlyBackgroundLoading.set(true); @@ -161,7 +163,7 @@ protected List getMoreIds(int requestSize) { } catch (SQLException e) { if (e.getMessage().contains("Database is already closed")) { String msg = "Error getting SEQ when DB shutting down " + e.getMessage(); - log.log(Level.ERROR, msg); + log.log(ERROR, msg); System.out.println(msg); return Collections.emptyList(); } else { diff --git a/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java b/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java index 2547ee5423..3de1bb10b7 100644 --- a/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java +++ b/ebean-api/src/main/java/io/ebean/event/ShutdownManager.java @@ -4,7 +4,6 @@ import io.ebean.EbeanVersion; import io.ebean.service.SpiContainer; -import java.lang.System.Logger.Level; import java.sql.Driver; import java.sql.DriverManager; import java.sql.SQLException; @@ -13,6 +12,8 @@ import java.util.List; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; + /** * Manages the shutdown of Ebean. *

@@ -121,8 +122,8 @@ public static void shutdown() { // Already run shutdown... return; } - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "Ebean shutting down"); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "Ebean shutting down"); } stopping = true; deregisterShutdownHook(); @@ -134,7 +135,7 @@ public static void shutdown() { Runnable r = (Runnable) ClassUtil.newInstance(shutdownRunner); r.run(); } catch (Exception e) { - log.log(Level.ERROR, "Error running custom shutdown runnable", e); + log.log(ERROR, "Error running custom shutdown runnable", e); } } @@ -148,7 +149,7 @@ public static void shutdown() { try { server.shutdown(); } catch (Exception ex) { - log.log(Level.ERROR, "Error executing shutdown runnable", ex); + log.log(ERROR, "Error executing shutdown runnable", ex); ex.printStackTrace(); } } @@ -166,10 +167,10 @@ private static void deregisterAllJdbcDrivers() { while (drivers.hasMoreElements()) { Driver driver = drivers.nextElement(); try { - log.log(Level.INFO, "De-registering jdbc driver: " + driver); + log.log(INFO, "De-registering jdbc driver: " + driver); DriverManager.deregisterDriver(driver); } catch (SQLException e) { - log.log(Level.ERROR, "Error de-registering driver " + driver, e); + log.log(ERROR, "Error de-registering driver " + driver, e); } } } diff --git a/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java b/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java index d2e6d3f98e..3fcc8cc51d 100644 --- a/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java +++ b/ebean-api/src/main/java/io/ebean/text/csv/DefaultCsvCallback.java @@ -4,7 +4,8 @@ import io.ebean.EbeanVersion; import io.ebean.Transaction; -import java.lang.System.Logger.Level; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.INFO; /** * Provides the default implementation of CsvCallback. @@ -129,7 +130,7 @@ public void processBean(int row, String[] line, T bean) { // related beans (e.g. customer -> customer.billingAddress server.save(bean, transaction); if (logInfoFrequency > 0 && (row % logInfoFrequency == 0)) { - log.log(Level.DEBUG, "processed {0} rows", row); + log.log(DEBUG, "processed {0} rows", row); } } @@ -140,7 +141,7 @@ public void processBean(int row, String[] line, T bean) { public void end(int row) { commitTransactionIfCreated(); exeTime = System.currentTimeMillis() - startTime; - log.log(Level.INFO, "Csv finished, rows[{0}] exeMillis[{1}]", row, exeTime); + log.log(INFO, "Csv finished, rows[{0}] exeMillis[{1}]", row, exeTime); } /** diff --git a/ebean-api/src/main/java/io/ebean/util/JdbcClose.java b/ebean-api/src/main/java/io/ebean/util/JdbcClose.java index b450db79ab..d6b35539c1 100644 --- a/ebean-api/src/main/java/io/ebean/util/JdbcClose.java +++ b/ebean-api/src/main/java/io/ebean/util/JdbcClose.java @@ -2,12 +2,13 @@ import io.ebean.EbeanVersion; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import static java.lang.System.Logger.Level.WARNING; + /** * Utility for closing raw Jdbc resources. */ @@ -24,7 +25,7 @@ public static void close(Statement statement) { statement.close(); } } catch (SQLException e) { - log.log(Level.WARNING, "Error closing statement", e); + log.log(WARNING, "Error closing statement", e); } } @@ -37,7 +38,7 @@ public static void close(ResultSet resultSet) { resultSet.close(); } } catch (SQLException e) { - log.log(Level.WARNING, "Error closing resultSet", e); + log.log(WARNING, "Error closing resultSet", e); } } @@ -50,7 +51,7 @@ public static void close(Connection connection) { connection.close(); } } catch (SQLException e) { - log.log(Level.WARNING, "Error closing connection", e); + log.log(WARNING, "Error closing connection", e); } } @@ -63,7 +64,7 @@ public static void rollback(Connection connection) { connection.rollback(); } } catch (SQLException e) { - log.log(Level.WARNING, "Error on connection rollback", e); + log.log(WARNING, "Error on connection rollback", e); } } @@ -76,7 +77,7 @@ public static void cancel(Statement stmt) { stmt.cancel(); } } catch (SQLException e) { - log.log(Level.WARNING, "Error on cancelling statement", e); + log.log(WARNING, "Error on cancelling statement", e); } } } diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java index be43c42afb..a0031f9388 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java @@ -12,10 +12,11 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.lang.System.Logger.Level; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; + /** * Implementation of the AutoTuneService which is comprised of profiling and query tuning. */ @@ -111,7 +112,7 @@ private void loadTuningFile() { if (stream != null) { loadAutoTuneProfiling(AutoTuneXmlReader.read(stream)); } else { - logger.log(Level.WARNING, "AutoTune file {0} not found - no initial automatic query tuning", tuningFile); + logger.log(WARNING, "AutoTune file {0} not found - no initial automatic query tuning", tuningFile); } } catch (IOException e) { throw new IllegalStateException("Error on auto close of " + tuningFile, e); @@ -120,7 +121,7 @@ private void loadTuningFile() { } private void loadAutoTuneProfiling(Autotune profiling) { - logger.log(Level.INFO, "AutoTune loading {0} tuning entries", profiling.getOrigin().size()); + logger.log(INFO, "AutoTune loading {0} tuning entries", profiling.getOrigin().size()); for (Origin origin : profiling.getOrigin()) { queryTuner.put(origin); } @@ -141,17 +142,17 @@ private void runtimeTuningUpdate() { event.process(); if (event.isEmpty()) { long exeMillis = System.currentTimeMillis() - start; - logger.log(Level.DEBUG, "No query tuning updates for server:{0} executionMillis:{1}", serverName, exeMillis); + logger.log(DEBUG, "No query tuning updates for server:{0} executionMillis:{1}", serverName, exeMillis); } else { // report the query tuning changes that have been made runtimeChangeCount += event.getChangeCount(); event.writeFile(profilingFile + "-" + serverName + "-update"); long exeMillis = System.currentTimeMillis() - start; - logger.log(Level.INFO, "query tuning updates - new:{0} diff:{1} for server:{2} executionMillis:{3}", event.getNewCount(), event.getDiffCount(), serverName, exeMillis); + logger.log(INFO, "query tuning updates - new:{0} diff:{1} for server:{2} executionMillis:{3}", event.getNewCount(), event.getDiffCount(), serverName, exeMillis); } } catch (Throwable e) { - logger.log(Level.ERROR, "Error collecting or applying automatic query tuning", e); + logger.log(ERROR, "Error collecting or applying automatic query tuning", e); } } finally { lock.unlock(); @@ -172,11 +173,11 @@ private void saveProfilingOnShutdown(boolean reset) { AutoTuneDiffCollection event = new AutoTuneDiffCollection(profiling, queryTuner, false); event.process(); if (event.isEmpty()) { - logger.log(Level.INFO, "No new or diff entries for profiling server:{0}", serverName); + logger.log(INFO, "No new or diff entries for profiling server:{0}", serverName); } else { event.writeFile(profilingFile + "-" + serverName); - logger.log(Level.INFO, "writing new:{0} diff:{1} profiling entries for server:{2}", event.getNewCount(), event.getDiffCount(), serverName); + logger.log(INFO, "writing new:{0} diff:{1} profiling entries for server:{2}", event.getNewCount(), event.getDiffCount(), serverName); } } } finally { @@ -196,7 +197,7 @@ private void saveProfilingOnShutdown(boolean reset) { private void outputAllTuning() { if (runtimeChangeCount == 0) { - logger.log(Level.INFO, "no runtime query tuning changes for server:{0}", serverName); + logger.log(INFO, "no runtime query tuning changes for server:{0}", serverName); } else { AutoTuneAllCollection event = new AutoTuneAllCollection(queryTuner); @@ -205,12 +206,12 @@ private void outputAllTuning() { if (existingTuning.exists()) { // rename the existing autotune.xml file (appending 'now') if (!existingTuning.renameTo(new File(tuningFile + "." + AutoTuneXmlWriter.now()))) { - logger.log(Level.WARNING, "Failed to rename autotune file [{0}]", tuningFile); + logger.log(WARNING, "Failed to rename autotune file [{0}]", tuningFile); } } event.writeFile(tuningFile, false); - logger.log(Level.INFO, "query tuning detected [{0}] changes, writing all [{1}] tuning entries for server:{2}", runtimeChangeCount, size, serverName); + logger.log(INFO, "query tuning detected [{0}] changes, writing all [{1}] tuning entries for server:{2}", runtimeChangeCount, size, serverName); } } @@ -279,7 +280,7 @@ public void collectProfiling(long waitMillis) { } catch (InterruptedException e) { // restore the interrupted status Thread.currentThread().interrupt(); - logger.log(Level.WARNING, "Error while sleeping after System.gc() request.", e); + logger.log(WARNING, "Error while sleeping after System.gc() request.", e); } } diff --git a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java index fb9007ebfa..408d9c1ff7 100644 --- a/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java +++ b/ebean-autotune/src/main/java/io/ebeaninternal/server/autotune/service/ProfileOriginNodeUsage.java @@ -9,11 +9,12 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssoc; import io.ebeaninternal.server.el.ElPropertyValue; -import java.lang.System.Logger.Level; import java.util.LinkedHashSet; import java.util.Set; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.WARNING; + /** * Collects usages statistics for a given node in the object graph. */ @@ -45,7 +46,7 @@ protected void buildTunedFetch(PathProperties pathProps, BeanDescriptor rootD if (path != null) { ElPropertyValue elGetValue = rootDesc.elGetValue(path); if (elGetValue == null) { - logger.log(Level.WARNING, "AutoTune: Can't find join for path[" + path + "] for " + rootDesc.name()); + logger.log(WARNING, "AutoTune: Can't find join for path[" + path + "] for " + rootDesc.name()); return; } else { BeanProperty beanProperty = elGetValue.beanProperty(); @@ -61,7 +62,7 @@ protected void buildTunedFetch(PathProperties pathProps, BeanDescriptor rootD for (String propName : aggregateUsed) { BeanProperty beanProp = desc.findPropertyFromPath(propName); if (beanProp == null) { - logger.log(Level.WARNING, "AutoTune: Can't find property[" + propName + "] for " + desc.name()); + logger.log(WARNING, "AutoTune: Can't find property[" + propName + "] for " + desc.name()); } else { if (beanProp.isId()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java index cf6a02089b..aff1929b63 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultCacheHolder.java @@ -9,12 +9,14 @@ import io.ebean.meta.MetricVisitor; import io.ebean.util.AnnotationUtil; -import java.lang.System.Logger.Level; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.TRACE; + /** * Manages the construction of caches. */ @@ -89,7 +91,7 @@ private ServerCache createCache(Class beanType, ServerCacheType type, String } void clearAll() { - log.log(Level.DEBUG, "clearAll"); + log.log(DEBUG, "clearAll"); for (ServerCache serverCache : allCaches.values()) { serverCache.clear(); } @@ -97,7 +99,7 @@ void clearAll() { public void clear(String name) { - log.log(Level.DEBUG, "clear {0}", name); + log.log(DEBUG, "clear {0}", name); clearIfExists(key(name, ServerCacheType.QUERY)); clearIfExists(key(name, ServerCacheType.BEAN)); clearIfExists(key(name, ServerCacheType.NATURAL_KEY)); @@ -112,7 +114,7 @@ public void clear(String name) { private void clearIfExists(String fullKey) { ServerCache cache = allCaches.get(fullKey); if (cache != null) { - log.log(Level.TRACE, "clear cache {0}", fullKey); + log.log(TRACE, "clear cache {0}", fullKey); cache.clear(); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java index e5bfd2628e..e68c9a3089 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCache.java @@ -9,13 +9,15 @@ import io.ebean.metric.MetricFactory; import java.io.Serializable; -import java.lang.System.Logger.Level; import java.lang.ref.SoftReference; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.TRACE; +import static java.lang.System.Logger.Level.WARNING; + /** * The default cache implementation. *

@@ -287,13 +289,13 @@ public void runEviction() { evictCount.add(trimmedByGC); evictCount.add(trimmedByTTL); evictCount.add(trimmedByLRU); - if (logger.isLoggable(Level.TRACE)) { + if (logger.isLoggable(TRACE)) { long exeMicros = TimeUnit.MICROSECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS); - logger.log(Level.TRACE, "Executed trim of cache {0} in [{1}]millis idle[{2}] timeToLive[{3}] accessTime[{4}] gc[{5}]", + logger.log(TRACE, "Executed trim of cache {0} in [{1}]millis idle[{2}] timeToLive[{3}] accessTime[{4}] gc[{5}]", name, exeMicros, trimmedByIdle, trimmedByTTL, trimmedByLRU, trimmedByGC); } } catch (Throwable e) { - logger.log(Level.WARNING, "Error during trim of DefaultServerCache [" + name + "]. Cache might be bigger than desired.", e); + logger.log(WARNING, "Error during trim of DefaultServerCache [" + name + "]. Cache might be bigger than desired.", e); } } finally { lock.unlock(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java index 6142f6d500..0b7264ff90 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cache/DefaultServerCacheManager.java @@ -9,9 +9,11 @@ import io.ebeaninternal.server.cluster.ClusterManager; import io.ebeaninternal.server.deploy.DCacheRegion; -import java.lang.System.Logger.Level; import java.util.*; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.INFO; + /** * Manages the bean and query caches. */ @@ -65,23 +67,23 @@ public void setEnabledRegions(String regions) { enabled.add(region.name()); if (!region.isEnabled()) { region.setEnabled(true); - log.log(Level.DEBUG, "Cache region[{0}] enabled", region.name()); + log.log(DEBUG, "Cache region[{0}] enabled", region.name()); } } else { disabled.add(region.name()); if (region.isEnabled()) { region.setEnabled(false); - log.log(Level.DEBUG, "Cache region[{0}] disabled", region.name()); + log.log(DEBUG, "Cache region[{0}] disabled", region.name()); } } } - log.log(Level.INFO, "Cache regions enabled:{0} disabled:{1}", enabled, disabled); + log.log(INFO, "Cache regions enabled:{0} disabled:{1}", enabled, disabled); } } @Override public void setAllRegionsEnabled(boolean enabled) { - log.log(Level.DEBUG, "All cache regions enabled[{0}]", enabled); + log.log(DEBUG, "All cache regions enabled[{0}]", enabled); for (SpiCacheRegion region : regionMap.values()) { region.setEnabled(enabled); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java b/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java index c85edd3158..7ababb99f5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/changelog/DefaultChangeLogListener.java @@ -10,9 +10,11 @@ import io.ebeaninternal.api.CoreLog; import java.io.StringWriter; -import java.lang.System.Logger.Level; import java.util.Properties; +import static java.lang.System.Logger.Level.ERROR; +import static java.lang.System.Logger.Level.INFO; + /** * Simply logs the change sets in JSON form to logger named io.ebean.ChangeLog. */ @@ -65,9 +67,9 @@ public void log(ChangeSet changeSet) { try { StringWriter writer = new StringWriter(getBufferSize(beanChange)); jsonBuilder.writeBeanJson(writer, beanChange, changeSet); - changeLog.log(Level.INFO, writer.toString()); + changeLog.log(INFO, writer.toString()); } catch (Exception e) { - CoreLog.log.log(Level.ERROR, "Exception logging beanChange " + beanChange, e); + CoreLog.log.log(ERROR, "Exception logging beanChange " + beanChange, e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java index 4af7e1fce1..e370534d9a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/cluster/ClusterManager.java @@ -5,12 +5,13 @@ import io.ebean.config.ContainerConfig; import io.ebeaninternal.server.transaction.RemoteTransactionEvent; -import java.lang.System.Logger.Level; import java.util.Iterator; import java.util.ServiceLoader; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.DEBUG; + /** * Manages the cluster service. */ @@ -112,8 +113,8 @@ public boolean isClustering() { */ public void broadcast(RemoteTransactionEvent event) { if (broadcast != null) { - if (clusterLogger.isLoggable(Level.DEBUG)) { - clusterLogger.log(Level.DEBUG, "sending: {0}", event); + if (clusterLogger.isLoggable(DEBUG)) { + clusterLogger.log(DEBUG, "sending: {0}", event); } broadcast.broadcast(event); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java index 6d68210bde..b8224bc23b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/BeanRequest.java @@ -6,7 +6,7 @@ import io.ebeaninternal.api.SpiTransaction; import io.ebeaninternal.server.core.timezone.DataTimeZone; -import java.lang.System.Logger.Level; +import static java.lang.System.Logger.Level.ERROR; /** * Base class for find and persist requests. @@ -63,7 +63,7 @@ public void rollbackTransIfRequired() { // Just log this and carry on. A previous exception has been // thrown and if this rollback throws exception it likely means // that the connection is broken (and the dataSource and db will cleanup) - CoreLog.log.log(Level.ERROR, "Error trying to rollback a transaction (after a prior exception thrown)", e); + CoreLog.log.log(ERROR, "Error trying to rollback a transaction (after a prior exception thrown)", e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java index 265e71cba4..8fa1093be9 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DatabasePlatformFactory.java @@ -8,7 +8,6 @@ import javax.persistence.PersistenceException; import javax.sql.DataSource; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.SQLException; @@ -16,6 +15,9 @@ import java.util.List; import java.util.ServiceLoader; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.INFO; + /** * Create a DatabasePlatform from the configuration. *

@@ -39,7 +41,7 @@ public DatabasePlatform create(DatabaseConfig config) { try { String offlinePlatform = DbOffline.getPlatform(); if (offlinePlatform != null) { - CoreLog.log.log(Level.INFO, "offline platform [{0}]", offlinePlatform); + CoreLog.log.log(INFO, "offline platform [{0}]", offlinePlatform); return byDatabaseName(offlinePlatform); } if (config.getDatabasePlatformName() != null) { @@ -88,7 +90,7 @@ private DatabasePlatform byDatabaseMeta(DatabaseMetaData metaData, Connection co String dbProductName = metaData.getDatabaseProductName().toLowerCase(); final int majorVersion = metaData.getDatabaseMajorVersion(); final int minorVersion = metaData.getDatabaseMinorVersion(); - CoreLog.log.log(Level.DEBUG, "platform for productName[{0}] version[{1}.{2}]", dbProductName, majorVersion, minorVersion); + CoreLog.log.log(DEBUG, "platform for productName[{0}] version[{1}.{2}]", dbProductName, majorVersion, minorVersion); for (DatabasePlatformProvider provider : providers) { if (provider.matchByProductName(dbProductName)) { return provider.create(majorVersion, minorVersion, metaData, connection); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java index 7cd82edebd..8e1f2fb840 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultBeanLoader.java @@ -14,10 +14,11 @@ import io.ebeaninternal.server.transaction.DefaultPersistenceContext; import javax.persistence.EntityNotFoundException; -import java.lang.System.Logger.Level; import java.util.List; import java.util.Set; +import static java.lang.System.Logger.Level.DEBUG; + /** * Helper to handle lazy loading and refreshing of beans. */ @@ -108,8 +109,8 @@ private void loadManyInternal(EntityBean parentBean, String propertyName, boolea server.findOne(query, null); if (beanCollection != null) { if (beanCollection.checkEmptyLazyLoad()) { - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "BeanCollection after load was empty. Owner:" + beanCollection.getOwnerBean()); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "BeanCollection after load was empty. Owner:" + beanCollection.getOwnerBean()); } } else if (useManyIdCache) { parentDesc.cacheManyPropPut(many, beanCollection, parentId); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java index eb1cb1fe2a..16df24f4cc 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultContainer.java @@ -14,7 +14,6 @@ import io.ebeaninternal.server.executor.DefaultBackgroundExecutor; import javax.persistence.PersistenceException; -import java.lang.System.Logger.Level; import java.net.URL; import java.sql.Connection; import java.sql.SQLException; @@ -22,6 +21,8 @@ import java.util.ServiceLoader; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; + /** * Default Server side implementation of ServerFactory. */ @@ -107,7 +108,7 @@ public SpiEbeanServer createServer(DatabaseConfig config) { startServer(online, server); } DbOffline.reset(); - log.log(Level.INFO, "Started database[{0}] platform[{1}] in {2}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start); + log.log(INFO, "Started database[{0}] platform[{1}] in {2}ms", config.getName(), config.getDatabasePlatform().getPlatform(), System.currentTimeMillis() - start); return server; } finally { lock.unlock(); @@ -136,7 +137,7 @@ private void applyConfigServices(DatabaseConfig config) { private void checkMissingModulePathProvides() { URL servicesFile = ClassLoader.getSystemResource("META-INF/services/io.ebean.config.EntityClassRegister"); if (servicesFile != null) { - log.log(Level.ERROR, "module-info.java is probably missing 'provides io.ebean.config.EntityClassRegister with EbeanEntityRegister' clause. EntityClassRegister exists but was not service loaded."); + log.log(ERROR, "module-info.java is probably missing 'provides io.ebean.config.EntityClassRegister with EbeanEntityRegister' clause. EntityClassRegister exists but was not service loaded."); } } @@ -214,7 +215,7 @@ private void setDatabasePlatform(DatabaseConfig config) { */ private void setDataSource(DatabaseConfig config) { if (isOfflineMode(config)) { - log.log(Level.DEBUG, "... DbOffline using platform [{0}]", DbOffline.getPlatform()); + log.log(DEBUG, "... DbOffline using platform [{0}]", DbOffline.getPlatform()); } else { InitDataSource.init(config); } @@ -250,7 +251,7 @@ private boolean checkDataSource(DatabaseConfig config) { } try (Connection connection = config.getDataSource().getConnection()) { if (connection.getAutoCommit()) { - log.log(Level.WARNING, "DataSource [{0}] has autoCommit defaulting to true!", config.getName()); + log.log(WARNING, "DataSource [{0}] has autoCommit defaulting to true!", config.getName()); } return true; } catch (SQLException ex) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java index b6b498b0d3..d0333acda1 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/DefaultServer.java @@ -51,7 +51,6 @@ import javax.persistence.OptimisticLockException; import javax.persistence.PersistenceException; import javax.sql.DataSource; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; @@ -65,6 +64,7 @@ import java.util.function.Predicate; import java.util.stream.Stream; +import static java.lang.System.Logger.Level.*; import static java.util.Spliterators.spliteratorUnknownSize; import static java.util.stream.StreamSupport.stream; @@ -331,7 +331,7 @@ private void startQueryPlanCapture() { if (config.isQueryPlanCapture()) { long secs = config.getQueryPlanCapturePeriodSecs(); if (secs > 10) { - log.log(Level.INFO, "capture query plan enabled, every {0}secs", secs); + log.log(INFO, "capture query plan enabled, every {0}secs", secs); backgroundExecutor.scheduleWithFixedDelay(this::collectQueryPlans, secs, secs, TimeUnit.SECONDS); } } @@ -379,7 +379,7 @@ public void shutdown(boolean shutdownDataSource, boolean deregisterDriver) { * Shutdown the services like threads and DataSource. */ private void shutdownInternal(boolean shutdownDataSource, boolean deregisterDriver) { - log.log(Level.TRACE, "shutting down instance {0}", serverName); + log.log(TRACE, "shutting down instance {0}", serverName); if (shutdown) { // already shutdown return; @@ -408,7 +408,7 @@ private void shutdownPlugins() { try { plugin.shutdown(); } catch (Exception e) { - log.log(Level.ERROR, "Error when shutting down plugin", e); + log.log(ERROR, "Error when shutting down plugin", e); } } } @@ -2075,7 +2075,7 @@ private void processRemoteCacheEvent(RemoteTransactionEvent event) { try { serverCacheManager.clearLocal(Class.forName(cache)); } catch (Exception e) { - log.log(Level.ERROR, "Error clearing local cache for type " + cache, e); + log.log(ERROR, "Error clearing local cache for type " + cache, e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java index 4bd2545eda..c55467ce4d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfigXmlMap.java @@ -6,11 +6,12 @@ import io.ebeaninternal.xmapping.api.XmapEbean; import io.ebeaninternal.xmapping.api.XmapRawSql; -import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.List; import java.util.Map; +import static java.lang.System.Logger.Level.ERROR; + /** * Reads the Xml deployment information. */ @@ -56,7 +57,7 @@ private void readDtoMapping(XmapDto dto) { try { dtoClass = Class.forName(dto.getClazz(), false, classLoader); } catch (Exception e) { - CoreLog.internal.log(Level.ERROR, "Could not load dto bean class " + dto.getClazz() + " for ebean xml entry"); + CoreLog.internal.log(ERROR, "Could not load dto bean class " + dto.getClazz() + " for ebean xml entry"); return; } DtoNamedQueries namedQueries = dtoNamedQueries.computeIfAbsent(dtoClass, aClass -> new DtoNamedQueries()); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index c8b7f8810f..51e4a7d5f3 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -57,9 +57,10 @@ import io.ebeanservice.docstore.api.DocStoreUpdateProcessor; import io.ebeanservice.docstore.none.NoneDocStoreFactory; -import java.lang.System.Logger.Level; import java.util.*; +import static java.lang.System.Logger.Level.*; + /** * Used to extend the DatabaseConfig with additional objects used to configure and * construct an Database. @@ -433,7 +434,7 @@ private TransactionScopeManager createTransactionScopeManager() { externalTransactionManager = new JtaTransactionManager(); } if (externalTransactionManager != null) { - log.log(Level.INFO, "Using Transaction Manager {0}", externalTransactionManager.getClass()); + log.log(INFO, "Using Transaction Manager {0}", externalTransactionManager.getClass()); return new ExternalTransactionScopeManager(externalTransactionManager); } else { return new DefaultTransactionScopeManager(); @@ -523,7 +524,7 @@ private ServerCachePlugin initServerCachePlugin() { if (iterator.hasNext()) { // use the cacheFactory (via classpath service loader) plugin = iterator.next(); - log.log(Level.DEBUG, "using ServerCacheFactory {0}", plugin.getClass()); + log.log(DEBUG, "using ServerCacheFactory {0}", plugin.getClass()); } else { // use the built in default l2 caching which is local cache based localL2Caching = true; @@ -613,7 +614,7 @@ private static class NoopDdl implements SpiDdlGenerator { @Override public void execute(boolean online) { if (online && ddlRun) { - CoreLog.log.log(Level.ERROR, "Configured to run DDL but ebean-ddl-generator is not in the classpath (or ebean-test in the test classpath?)"); + CoreLog.log.log(ERROR, "Configured to run DDL but ebean-ddl-generator is not in the classpath (or ebean-test in the test classpath?)"); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java index 031c87688e..8e2dd4d7f6 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClassPathSearch.java @@ -5,10 +5,11 @@ import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.core.ClassPathScanners; -import java.lang.System.Logger.Level; import java.util.List; import java.util.Set; +import static java.lang.System.Logger.Level.DEBUG; + /** * Searches for interesting classes such as Entities, Embedded and ScalarTypes. */ @@ -58,7 +59,7 @@ private BootupClasses getBootupClasses() { } long searchTime = System.currentTimeMillis() - st; - log.log(Level.DEBUG, "Classpath search entities[{0}] searchTime[{1}] in packages[{2}]", bc.getEntities().size(), searchTime, packages); + log.log(DEBUG, "Classpath search entities[{0}] searchTime[{1}] in packages[{2}]", bc.getEntities().size(), searchTime, packages); return bc; } catch (Exception ex) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java index b3f777c6fd..40c4ad4424 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/BootupClasses.java @@ -18,13 +18,15 @@ import javax.persistence.Embeddable; import javax.persistence.Entity; import javax.persistence.Table; -import java.lang.System.Logger.Level; import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; import java.util.function.Predicate; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.ERROR; + /** * Interesting classes for a EbeanServer such as Embeddable, Entity, * ScalarTypes, Finders, Listeners and Controllers. @@ -205,13 +207,13 @@ private T create(Class cls, boolean logOnException) { try { return cls.getConstructor().newInstance(); } catch (NoSuchMethodException e) { - log.log(Level.DEBUG, "Ignore/expected - no default constructor: " + e.getMessage()); + log.log(DEBUG, "Ignore/expected - no default constructor: " + e.getMessage()); return null; } catch (Exception e) { if (logOnException) { // not expected but we log and carry on - log.log(Level.ERROR, "Error creating " + cls, e); + log.log(ERROR, "Error creating " + cls, e); return null; } else { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java index a9dbf21abb..456b909872 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/core/bootup/ManifestReader.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.io.InputStream; -import java.lang.System.Logger.Level; import java.net.URL; import java.util.Collections; import java.util.Enumeration; @@ -15,6 +14,8 @@ import java.util.jar.Attributes; import java.util.jar.Manifest; +import static java.lang.System.Logger.Level.WARNING; + /** * Reads all the META-INF/ebean.mf resources with the package locations of entity beans. */ @@ -63,7 +64,7 @@ private Set read(ClassLoader classLoader, String resourcePath) { } } } catch (IOException e) { - log.log(Level.WARNING, "Error reading " + resourcePath + " manifest resources", e); + log.log(WARNING, "Error reading " + resourcePath + " manifest resources", e); } return packageSet; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java index 4fd54268fe..d86e75a7bc 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptor.java @@ -58,7 +58,6 @@ import javax.persistence.PersistenceException; import java.io.IOException; import java.io.StringWriter; -import java.lang.System.Logger.Level; import java.lang.reflect.Modifier; import java.sql.SQLException; import java.sql.Types; @@ -68,6 +67,8 @@ import java.util.stream.Collectors; import static io.ebeaninternal.server.persist.DmlUtil.isNullOrZero; +import static java.lang.System.Logger.Level.ERROR; +import static java.lang.System.Logger.Level.INFO; /** * Describes Beans including their deployment information. @@ -792,7 +793,7 @@ private BeanChange updateBeanChange(PersistRequestBean request) { changeJson.flush(); return beanChange(ChangeType.UPDATE, request.beanId(), changeJson.newJson(), changeJson.oldJson()); } catch (RuntimeException e) { - log.log(Level.ERROR, "Failed to write ChangeLog entry for update", e); + log.log(ERROR, "Failed to write ChangeLog entry for update", e); return null; } } @@ -808,7 +809,7 @@ private BeanChange insertBeanChange(PersistRequestBean request) { jsonWriter.flush(); return beanChange(ChangeType.INSERT, request.beanId(), writer.toString(), null); } catch (IOException e) { - log.log(Level.ERROR, "Failed to write ChangeLog entry for insert", e); + log.log(ERROR, "Failed to write ChangeLog entry for insert", e); return null; } } @@ -2288,11 +2289,11 @@ private ElComparator createComparator(String sortByClause) { private ElComparator createPropertyComparator(SortByClause.Property sortProp) { ElPropertyValue elGetValue = elGetValue(sortProp.getName()); if (elGetValue == null) { - log.log(Level.ERROR, "Sort property [" + sortProp + "] not found in " + beanType + ". Cannot sort."); + log.log(ERROR, "Sort property [" + sortProp + "] not found in " + beanType + ". Cannot sort."); return new ElComparatorNoop<>(); } if (elGetValue.isAssocMany()) { - log.log(Level.ERROR, "Sort property [" + sortProp + "] in " + beanType + " is a many-property. Cannot sort."); + log.log(ERROR, "Sort property [" + sortProp + "] in " + beanType + " is a many-property. Cannot sort."); return new ElComparatorNoop<>(); } Boolean nullsHigh = sortProp.getNullsHigh(); @@ -2768,7 +2769,7 @@ public String softDeletePredicate(String tableAlias) { public void markAsDeleted(EntityBean bean) { if (softDeleteProperty == null) { Object id = getId(bean); - log.log(Level.INFO, "(Lazy) loading unsuccessful for type:{0} id:{1} - expecting when bean has been deleted", name(), id); + log.log(INFO, "(Lazy) loading unsuccessful for type:{0} id:{1} - expecting when bean has been deleted", name(), id); bean._ebean_getIntercept().setLazyLoadFailure(id); } else { softDeleteValue(bean); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java index 4e0c39b394..015fcbe708 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorCacheHelp.java @@ -16,9 +16,10 @@ import io.ebeaninternal.server.transaction.DefaultPersistenceContext; import java.io.IOException; -import java.lang.System.Logger.Level; import java.util.*; +import static java.lang.System.Logger.Level.*; + /** * Helper for BeanDescriptor that manages the bean, query and collection caches. * @@ -104,10 +105,10 @@ final class BeanDescriptorCacheHelp { void deriveNotifyFlags() { cacheNotifyOnAll = (invalidateQueryCache || beanCache != null || queryCache != null); cacheNotifyOnDelete = !cacheNotifyOnAll && isNotifyOnDeletes(); - if (log.isLoggable(Level.DEBUG)) { + if (log.isLoggable(DEBUG)) { if (cacheNotifyOnAll || cacheNotifyOnDelete) { String notifyMode = cacheNotifyOnAll ? "All" : "Delete"; - log.log(Level.DEBUG, "l2 caching on {0} - beanCaching:{1} queryCaching:{2} notifyMode:{3} ", + log.log(DEBUG, "l2 caching on {0} - beanCaching:{1} queryCaching:{2} notifyMode:{3} ", desc.fullName(), isBeanCaching(), isQueryCaching(), notifyMode); } } @@ -178,8 +179,8 @@ CacheOptions getCacheOptions() { */ void queryCacheClear() { if (queryCache != null) { - if (queryLog.isLoggable(Level.DEBUG)) { - queryLog.log(Level.DEBUG, " CLEAR {0}", cacheName); + if (queryLog.isLoggable(DEBUG)) { + queryLog.log(DEBUG, " CLEAR {0}", cacheName); } queryCache.clear(); } @@ -202,11 +203,11 @@ Object queryCacheGet(Object id) { throw new IllegalStateException("No query cache enabled on " + desc + ". Need explicit @Cache(enableQueryCache=true)"); } Object queryResult = queryCache.get(id); - if (queryLog.isLoggable(Level.DEBUG)) { + if (queryLog.isLoggable(DEBUG)) { if (queryResult == null) { - queryLog.log(Level.DEBUG, " GET {0}({1}) - cache miss", cacheName, id); + queryLog.log(DEBUG, " GET {0}({1}) - cache miss", cacheName, id); } else { - queryLog.log(Level.DEBUG, " GET {0}({1}) - hit", cacheName, id); + queryLog.log(DEBUG, " GET {0}({1}) - hit", cacheName, id); } } return queryResult; @@ -219,8 +220,8 @@ void queryCachePut(Object id, QueryCacheEntry entry) { if (queryCache == null) { throw new IllegalStateException("No query cache enabled on " + desc + ". Need explicit @Cache(enableQueryCache=true)"); } - if (queryLog.isLoggable(Level.DEBUG)) { - queryLog.log(Level.DEBUG, " PUT {0}({1})", cacheName, id); + if (queryLog.isLoggable(DEBUG)) { + queryLog.log(DEBUG, " PUT {0}({1})", cacheName, id); } queryCache.put(id, entry); } @@ -228,16 +229,16 @@ void queryCachePut(Object id, QueryCacheEntry entry) { void manyPropRemove(String propertyName, Object parentId) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName); - if (manyLog.isLoggable(Level.TRACE)) { - manyLog.log(Level.TRACE, " REMOVE {0}({1}).{2}", cacheName, parentId, propertyName); + if (manyLog.isLoggable(TRACE)) { + manyLog.log(TRACE, " REMOVE {0}({1}).{2}", cacheName, parentId, propertyName); } collectionIdsCache.remove(parentId); } void manyPropClear(String propertyName) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName); - if (manyLog.isLoggable(Level.DEBUG)) { - manyLog.log(Level.DEBUG, " CLEAR {0}(*).{1} ", cacheName, propertyName); + if (manyLog.isLoggable(DEBUG)) { + manyLog.log(DEBUG, " CLEAR {0}(*).{1} ", cacheName, propertyName); } collectionIdsCache.clear(); } @@ -249,11 +250,11 @@ private CachedManyIds manyPropGet(Object parentId, String propertyName) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, propertyName); CachedManyIds entry = (CachedManyIds) collectionIdsCache.get(parentId); if (entry == null) { - if (manyLog.isLoggable(Level.TRACE)) { - manyLog.log(Level.TRACE, " GET {0}({1}).{2} - cache miss", cacheName, parentId, propertyName); + if (manyLog.isLoggable(TRACE)) { + manyLog.log(TRACE, " GET {0}({1}).{2} - cache miss", cacheName, parentId, propertyName); } - } else if (manyLog.isLoggable(Level.DEBUG)) { - manyLog.log(Level.DEBUG, " GET {0}({1}).{2} - hit", cacheName, parentId, propertyName); + } else if (manyLog.isLoggable(DEBUG)) { + manyLog.log(DEBUG, " GET {0}({1}).{2} - hit", cacheName, parentId, propertyName); } return entry; } @@ -303,12 +304,12 @@ void manyPropPut(BeanPropertyAssocMany many, Object details, Object parentId) changes.put(many.name(), asJson); CachedBeanData newData = data.update(changes, data.getVersion()); - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, parentId, changes); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, parentId, changes); } beanCache.put(parentId, newData); } catch (IOException e) { - log.log(Level.ERROR, "Error updating L2 cache", e); + log.log(ERROR, "Error updating L2 cache", e); } } } else { @@ -321,8 +322,8 @@ void manyPropPut(BeanPropertyAssocMany many, Object details, Object parentId) void cachePutManyIds(Object parentId, String manyName, CachedManyIds entry) { ServerCache collectionIdsCache = cacheManager.getCollectionIdsCache(beanType, manyName); - if (manyLog.isLoggable(Level.DEBUG)) { - manyLog.log(Level.DEBUG, " PUT {0}({1}).{2} - ids:{3}", cacheName, parentId, manyName, entry); + if (manyLog.isLoggable(DEBUG)) { + manyLog.log(DEBUG, " PUT {0}({1}).{2} - ids:{3}", cacheName, parentId, manyName, entry); } collectionIdsCache.put(parentId, entry); } @@ -353,8 +354,8 @@ BeanCacheResult cacheIdLookup(PersistenceContext context, Collection ids) return new BeanCacheResult<>(); } Map beanDataMap = beanCache.getAll(keys); - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " MGET {0}({1}) - hits:{2}", cacheName, ids, beanDataMap.keySet()); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " MGET {0}({1}) - hits:{2}", cacheName, ids, beanDataMap.keySet()); } BeanCacheResult result = new BeanCacheResult<>(); for (Map.Entry entry : beanDataMap.entrySet()) { @@ -375,8 +376,8 @@ BeanCacheResult naturalKeyLookup(PersistenceContext context, Set keys // naturalKey -> Id map Map naturalKeyMap = naturalKeyCache.getAll(keys); - if (natLog.isLoggable(Level.TRACE)) { - natLog.log(Level.TRACE, " MLOOKUP {0}({1}) - hits:{2}", cacheName, keys, naturalKeyMap); + if (natLog.isLoggable(TRACE)) { + natLog.log(TRACE, " MLOOKUP {0}({1}) - hits:{2}", cacheName, keys, naturalKeyMap); } BeanCacheResult result = new BeanCacheResult<>(); @@ -392,8 +393,8 @@ BeanCacheResult naturalKeyLookup(PersistenceContext context, Set keys Set ids = new HashSet<>(naturalKeyMap.values()); Map beanDataMap = beanCache.getAll(ids); - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " MGET {0}({1}) - hits:{2}", cacheName, ids, beanDataMap.keySet()); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " MGET {0}({1}) - hits:{2}", cacheName, ids, beanDataMap.keySet()); } // process the hits into beans etc for (Map.Entry entry : beanDataMap.entrySet()) { @@ -437,8 +438,8 @@ private ServerCache getBeanCache() { */ void beanCacheClear() { if (beanCache != null) { - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " CLEAR {0}", cacheName); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " CLEAR {0}", cacheName); } beanCache.clear(); } @@ -507,14 +508,14 @@ void beanCachePutAllDirect(Collection beans) { } } } - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " MPUT {0}({1})", cacheName, map.keySet()); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " MPUT {0}({1})", cacheName, map.keySet()); } getBeanCache().putAll(map); if (natKeys != null && !natKeys.isEmpty()) { - if (natLog.isLoggable(Level.DEBUG)) { - natLog.log(Level.DEBUG, " MPUT {0}({1}, {2})", cacheName, naturalKey, natKeys.keySet()); + if (natLog.isLoggable(DEBUG)) { + natLog.log(DEBUG, " MPUT {0}({1}, {2})", cacheName, naturalKey, natKeys.keySet()); } naturalKeyCache.putAll(natKeys); } @@ -526,15 +527,15 @@ void beanCachePutAllDirect(Collection beans) { void beanCachePutDirect(EntityBean bean) { CachedBeanData beanData = beanExtractData(desc, bean); String key = desc.cacheKeyForBean(bean); - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " PUT {0}({1}) data:{2}", cacheName, key, beanData); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " PUT {0}({1}) data:{2}", cacheName, key, beanData); } getBeanCache().put(key, beanData); if (naturalKey != null) { String naturalKey = calculateNaturalKey(beanData); if (naturalKey != null) { - if (natLog.isLoggable(Level.DEBUG)) { - natLog.log(Level.DEBUG, " PUT {0}({1}, {2})", cacheName, naturalKey, key); + if (natLog.isLoggable(DEBUG)) { + natLog.log(DEBUG, " PUT {0}({1}, {2})", cacheName, naturalKey, key); } naturalKeyCache.put(naturalKey, key); } @@ -575,13 +576,13 @@ T beanCacheGet(String key, Boolean readOnly, PersistenceContext context) { private T beanCacheGetInternal(String key, Boolean readOnly, PersistenceContext context) { CachedBeanData data = (CachedBeanData) getBeanCache().get(key); if (data == null) { - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " GET {0}({1}) - cache miss", cacheName, key); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " GET {0}({1}) - cache miss", cacheName, key); } return null; } - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " GET {0}({1}) - hit", cacheName, key); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " GET {0}({1}) - hit", cacheName, key); } return convertToBean(key, readOnly, context, data); } @@ -591,8 +592,8 @@ private T convertToBean(Object id, Boolean readOnly, PersistenceContext context, if (cacheSharableBeans && !Boolean.FALSE.equals(readOnly)) { Object bean = data.getSharableBean(); if (bean != null) { - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " GET {0}({1}) - hit shared bean", cacheName, id); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " GET {0}({1}) - hit shared bean", cacheName, id); } if (desc.isReadAuditing()) { desc.readAuditBean("l2", "", bean); @@ -680,8 +681,8 @@ EntityBean embeddedBeanLoadDirect(CachedBeanData data, PersistenceContext contex */ void beanCacheApplyInvalidate(Collection keys) { if (beanCache != null) { - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " MREMOVE {0}({1})", cacheName, keys); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " MREMOVE {0}({1})", cacheName, keys); } beanCache.removeAll(new HashSet<>(keys)); } @@ -700,8 +701,8 @@ Set beanCacheLoadAll(Set batch, Persis } Map hits = getBeanCache().getAll(ebis.keySet()); - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " MLOAD {0}({1}) - got hits ({2})", cacheName, ebis.keySet(), hits.size()); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " MLOAD {0}({1}) - got hits ({2})", cacheName, ebis.keySet(), hits.size()); } Set loaded = new HashSet<>(); @@ -713,19 +714,19 @@ Set beanCacheLoadAll(Set batch, Persis CachedBeanData cacheData = (CachedBeanData) hit.getValue(); if (lazyLoadProperty > -1 && !cacheData.isLoaded(propertyName)) { - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " load {0}({1}) - cache miss on property({2})", cacheName, key, propertyName); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " load {0}({1}) - cache miss on property({2})", cacheName, key, propertyName); } } else { CachedBeanDataToBean.load(desc, ebi.getOwner(), cacheData, context); loaded.add(ebi); - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " load {0}({1}) - hit", cacheName, key); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " load {0}({1}) - hit", cacheName, key); } } } - if (!ebis.isEmpty() && beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " load {0}({1}) - cache miss", cacheName, ebis.keySet()); + if (!ebis.isEmpty() && beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " load {0}({1}) - cache miss", cacheName, ebis.keySet()); } return loaded; } @@ -736,21 +737,21 @@ Set beanCacheLoadAll(Set batch, Persis boolean beanCacheLoad(EntityBean bean, EntityBeanIntercept ebi, String key, PersistenceContext context) { CachedBeanData cacheData = (CachedBeanData) getBeanCache().get(key); if (cacheData == null) { - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " LOAD {0}({1}) - cache miss", cacheName, key); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " LOAD {0}({1}) - cache miss", cacheName, key); } return false; } int lazyLoadProperty = ebi.getLazyLoadPropertyIndex(); if (lazyLoadProperty > -1 && !cacheData.isLoaded(ebi.getLazyLoadProperty())) { - if (beanLog.isLoggable(Level.TRACE)) { - beanLog.log(Level.TRACE, " LOAD {0}({1}) - cache miss on property({2})", cacheName, key, ebi.getLazyLoadProperty()); + if (beanLog.isLoggable(TRACE)) { + beanLog.log(TRACE, " LOAD {0}({1}) - cache miss on property({2})", cacheName, key, ebi.getLazyLoadProperty()); } return false; } CachedBeanDataToBean.load(desc, bean, cacheData, context); - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " LOAD {0}({1}) - hit", cacheName, key); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " LOAD {0}({1}) - hit", cacheName, key); } return true; } @@ -874,8 +875,8 @@ void cacheBeanUpdate(String key, Map changes, boolean updateNatu if (existingData != null) { long currentVersion = existingData.getVersion(); if (version > 0 && version < currentVersion) { - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " REMOVE {0}({1}) - version conflict old:{2} new:{3}", cacheName, key, currentVersion, version); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " REMOVE {0}({1}) - version conflict old:{2} new:{3}", cacheName, key, currentVersion, version); } cache.remove(key); } else { @@ -883,16 +884,16 @@ void cacheBeanUpdate(String key, Map changes, boolean updateNatu version = currentVersion; } CachedBeanData newData = existingData.update(changes, version); - if (beanLog.isLoggable(Level.DEBUG)) { - beanLog.log(Level.DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, key, changes); + if (beanLog.isLoggable(DEBUG)) { + beanLog.log(DEBUG, " UPDATE {0}({1}) changes:{2}", cacheName, key, changes); } cache.put(key, newData); } if (updateNaturalKey) { Object oldKey = calculateNaturalKey(existingData); if (oldKey != null) { - if (natLog.isLoggable(Level.DEBUG)) { - natLog.log(Level.DEBUG, ".. update {0} REMOVE({1}) - old key for ({2})", cacheName, oldKey, key); + if (natLog.isLoggable(DEBUG)) { + natLog.log(DEBUG, ".. update {0} REMOVE({1}) - old key for ({2})", cacheName, oldKey, key); } naturalKeyCache.remove(oldKey); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java index 0074b550a1..bfdc4cd17c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanDescriptorManager.java @@ -47,12 +47,13 @@ import javax.persistence.Transient; import javax.sql.DataSource; import java.io.Serializable; -import java.lang.System.Logger.Level; import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.*; import java.util.concurrent.TimeUnit; +import static java.lang.System.Logger.Level.*; + /** * Creates BeanDescriptors. */ @@ -309,7 +310,7 @@ public Map deploy(List mappings) { } catch (BeanNotEnhancedException e) { throw e; } catch (RuntimeException e) { - log.log(Level.ERROR, "Error in deployment", e); + log.log(ERROR, "Error in deployment", e); throw e; } } @@ -332,13 +333,13 @@ private void readEntityMapping(ClassLoader classLoader, XmapEntity entityDeploy) try { entityClass = Class.forName(entityClassName, false, classLoader); } catch (Exception e) { - log.log(Level.ERROR, "Could not load entity bean class " + entityClassName + " for ebean.xml entry"); + log.log(ERROR, "Could not load entity bean class " + entityClassName + " for ebean.xml entry"); return; } DeployBeanInfo info = deployInfoMap.get(entityClass); if (info == null) { - log.log(Level.ERROR, "No entity bean for ebean.xml entry " + entityClassName); + log.log(ERROR, "No entity bean for ebean.xml entry " + entityClassName); } else { for (XmapRawSql sql : entityDeploy.getRawSql()) { @@ -601,11 +602,11 @@ private void createListeners() { int pc = postConstructManager.getRegisterCount(); int lc = persistListenerManager.getRegisterCount(); int fc = beanFinderManager.getRegisterCount(); - log.log(Level.DEBUG, "BeanPersistControllers[{0}] BeanFinders[{1}] BeanPersistListeners[{2}] BeanQueryAdapters[{3}] BeanPostLoaders[{4}] BeanPostConstructors[{5}]", cc, fc, lc, qa, pl, pc); + log.log(DEBUG, "BeanPersistControllers[{0}] BeanFinders[{1}] BeanPersistListeners[{2}] BeanQueryAdapters[{3}] BeanPostLoaders[{4}] BeanPostConstructors[{5}]", cc, fc, lc, qa, pl, pc); } private void logStatus() { - log.log(Level.DEBUG, "Entities[{0}]", entityBeanCount); + log.log(DEBUG, "Entities[{0}]", entityBeanCount); } /** @@ -867,10 +868,10 @@ private boolean findMappedBy(DeployBeanPropertyAssocMany prop) { if (possibleLower.contains(searchName)) { // we have a match prop.setMappedBy(possibleMappedBy); - if (log.isLoggable(Level.DEBUG)) { + if (log.isLoggable(DEBUG)) { String m = "Implicitly found mappedBy for " + targetDesc + "." + prop; m += " by searching for [" + searchName + "] against " + matchSet; - log.log(Level.DEBUG, m); + log.log(DEBUG, m); } return true; } @@ -1207,12 +1208,12 @@ private void setIdGeneration(DeployBeanDescriptor desc) { final DeployIdentityMode identityMode = desc.getIdentityMode(); if (identityMode.isSequence() && !dbIdentity.isSupportsSequence()) { // explicit sequence but not supported by the DatabasePlatform - log.log(Level.INFO, "Explicit sequence on {0} but not supported by DB Platform - ignored", desc.getFullName()); + log.log(INFO, "Explicit sequence on {0} but not supported by DB Platform - ignored", desc.getFullName()); identityMode.setIdType(IdType.AUTO); } if (identityMode.isIdentity() && !dbIdentity.isSupportsIdentity()) { // explicit identity but not supported by the DatabasePlatform - log.log(Level.INFO, "Explicit Identity on {0} but not supported by DB Platform - ignored", desc.getFullName()); + log.log(INFO, "Explicit Identity on {0} but not supported by DB Platform - ignored", desc.getFullName()); identityMode.setIdType(IdType.AUTO); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java index a119ddb90b..2133ef7678 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanProperty.java @@ -44,7 +44,6 @@ import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import java.lang.System.Logger.Level; import java.lang.reflect.Field; import java.sql.SQLException; import java.sql.Types; @@ -52,6 +51,8 @@ import java.util.Map; import java.util.Set; +import static java.lang.System.Logger.Level.ERROR; + /** * Description of a property of a bean. Includes its deployment information such * as database column mapping information. @@ -1434,7 +1435,7 @@ public void jsonRead(SpiJsonReader ctx, EntityBean bean) throws IOException { objValue = null; String msg = "Error trying to use Jackson ObjectMapper to read transient property " + fullName() + " - consider marking this property with @JsonIgnore"; - CoreLog.log.log(Level.ERROR, msg, e); + CoreLog.log.log(ERROR, msg, e); } } if (jsonDeserialize) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java index c2bd2bb4db..d98f6d8496 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssoc.java @@ -27,10 +27,11 @@ import io.ebeanservice.docstore.api.support.DocStructure; import javax.persistence.PersistenceException; -import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; +import static java.lang.System.Logger.Level.ERROR; + /** * Abstract base for properties mapped to an associated bean, list, set or map. */ @@ -433,7 +434,7 @@ ImportedId createImportedId(BeanPropertyAssoc owner, BeanDescriptor target if (!idProp.isEmbedded()) { // simple single scalar id if (cols.length != 1) { - CoreLog.log.log(Level.ERROR, "No Imported Id column for [" + idProp + "] in table [" + join.getTable() + "]"); + CoreLog.log.log(ERROR, "No Imported Id column for [" + idProp + "] in table [" + join.getTable() + "]"); return null; } else { BeanProperty[] idProps = {idProp}; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java index fab75feeab..a96ea496e0 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanPropertyAssocMany.java @@ -24,9 +24,10 @@ import javax.persistence.PersistenceException; import java.io.IOException; import java.io.StringWriter; -import java.lang.System.Logger.Level; import java.util.*; +import static java.lang.System.Logger.Level.ERROR; + /** * Property mapped to a List Set or Map. */ @@ -668,7 +669,7 @@ private ExportedProperty[] createExported() { } } catch (PersistenceException e) { // not found as individual scalar properties - CoreLog.log.log(Level.ERROR, "Could not find a exported property?", e); + CoreLog.log.log(ERROR, "Could not find a exported property?", e); } } else { if (idProp != null) { @@ -963,7 +964,7 @@ public void setCacheDataValue(EntityBean bean, Object cacheData, PersistenceCont setValue(bean, collection); } } catch (Exception e) { - CoreLog.log.log(Level.ERROR, "Error setting value from L2 cache", e); + CoreLog.log.log(ERROR, "Error setting value from L2 cache", e); } } @@ -976,7 +977,7 @@ public Object getCacheDataValue(EntityBean bean) { } return jsonWriteCollection(collection); } catch (Exception e) { - CoreLog.log.log(Level.ERROR, "Error building value element collection json for L2 cache", e); + CoreLog.log.log(ERROR, "Error building value element collection json for L2 cache", e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java index 80bed85855..0cc2f6ccfa 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/BeanTable.java @@ -6,7 +6,7 @@ import io.ebeaninternal.server.deploy.meta.DeployTableJoin; import io.ebeaninternal.server.deploy.meta.DeployTableJoinColumn; -import java.lang.System.Logger.Level; +import static java.lang.System.Logger.Level.DEBUG; /** @@ -107,7 +107,7 @@ private void addToJoin(String foreignKeyPrefix, DeployTableJoin join, boolean re if (complexKey) { // just to copy the column name rather than prefix with the foreignKeyPrefix. // I think that with complex keys this is the more common approach. - CoreLog.internal.log(Level.DEBUG, "On table[{0}] foreign key column [{1}]", baseTable, lc); + CoreLog.internal.log(DEBUG, "On table[{0}] foreign key column [{1}]", baseTable, lc); fk = lc; } if (sqlFormulaSelect != null) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java index e37d9ea409..598962fcfd 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationAssocOnes.java @@ -15,7 +15,8 @@ import io.ebeaninternal.server.query.SqlJoinType; import javax.persistence.*; -import java.lang.System.Logger.Level; + +import static java.lang.System.Logger.Level.INFO; /** * Read the deployment annotations for Associated One beans. @@ -214,10 +215,10 @@ private void readPrimaryKeyJoin(PrimaryKeyJoinColumn primaryKeyJoin, DeployBeanP prop.setPrimaryKeyJoin(true); if (!primaryKeyJoin.name().isEmpty()) { - CoreLog.internal.log(Level.INFO, "Automatically determining join columns for @PrimaryKeyJoinColumn - ignoring PrimaryKeyJoinColumn.name attribute [{0}] on {1}", primaryKeyJoin.name(), prop.getFullBeanName()); + CoreLog.internal.log(INFO, "Automatically determining join columns for @PrimaryKeyJoinColumn - ignoring PrimaryKeyJoinColumn.name attribute [{0}] on {1}", primaryKeyJoin.name(), prop.getFullBeanName()); } if (!primaryKeyJoin.referencedColumnName().isEmpty()) { - CoreLog.internal.log(Level.INFO, "Automatically determining join columns for @PrimaryKeyJoinColumn - Ignoring PrimaryKeyJoinColumn.referencedColumnName attribute [{0}] on {1}", primaryKeyJoin.referencedColumnName(), prop.getFullBeanName()); + CoreLog.internal.log(INFO, "Automatically determining join columns for @PrimaryKeyJoinColumn - Ignoring PrimaryKeyJoinColumn.referencedColumnName attribute [{0}] on {1}", primaryKeyJoin.referencedColumnName(), prop.getFullBeanName()); } BeanTable baseBeanTable = factory.beanTable(info.getDescriptor().getBeanType()); String localPrimaryKey = baseBeanTable.getIdColumn(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java index 36fdc915f2..662b73be80 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/AnnotationClass.java @@ -1,19 +1,7 @@ package io.ebeaninternal.server.deploy.parse; -import io.ebean.annotation.Cache; -import io.ebean.annotation.DbComment; -import io.ebean.annotation.DbPartition; -import io.ebean.annotation.DocStore; -import io.ebean.annotation.Draftable; -import io.ebean.annotation.DraftableElement; -import io.ebean.annotation.History; -import io.ebean.annotation.Identity; import io.ebean.annotation.Index; -import io.ebean.annotation.InvalidateQueryCache; -import io.ebean.annotation.ReadAudit; -import io.ebean.annotation.StorageEngine; -import io.ebean.annotation.Tablespace; -import io.ebean.annotation.View; +import io.ebean.annotation.*; import io.ebean.config.TableName; import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType; @@ -23,18 +11,10 @@ import io.ebeaninternal.server.deploy.TablespaceMeta; import io.ebeaninternal.server.deploy.meta.DeployBeanProperty; -import javax.persistence.AttributeOverride; -import javax.persistence.Column; -import javax.persistence.Embeddable; -import javax.persistence.Entity; -import javax.persistence.IdClass; -import javax.persistence.NamedQuery; -import javax.persistence.Table; -import javax.persistence.UniqueConstraint; - -import java.lang.System.Logger.Level; +import javax.persistence.*; import static io.ebean.util.AnnotationUtil.typeGet; +import static java.lang.System.Logger.Level.ERROR; /** * Read the class level deployment annotations. @@ -67,7 +47,7 @@ void parseAttributeOverride() { Column column = override.column(); DeployBeanProperty beanProperty = descriptor.getBeanProperty(propertyName); if (beanProperty == null) { - CoreLog.log.log(Level.ERROR, "AttributeOverride property [" + propertyName + "] not found on " + descriptor.getFullName()); + CoreLog.log.log(ERROR, "AttributeOverride property [" + propertyName + "] not found on " + descriptor.getFullName()); } else { readColumn(column, beanProperty); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java index 14579b621d..cab0483765 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/deploy/parse/DeployCreateProperties.java @@ -11,9 +11,10 @@ import javax.persistence.PersistenceException; import javax.persistence.Transient; -import java.lang.System.Logger.Level; import java.lang.reflect.*; +import static java.lang.System.Logger.Level.*; + /** * Create the properties for a bean. *

@@ -85,7 +86,7 @@ private void createProperties(DeployBeanDescriptor desc, Class beanType, i if (replaced != null && !replaced.isTransient()) { String msg = "Huh??? property " + prop.getFullBeanName() + " being defined twice"; msg += " but replaced property was not transient? This is not expected?"; - CoreLog.log.log(Level.WARNING, msg); + CoreLog.log.log(WARNING, msg); } } } @@ -112,7 +113,7 @@ private DeployBeanProperty createManyType(DeployBeanDescriptor desc, Class return new DeployBeanPropertySimpleCollection(desc, targetType, manyType); } } catch (NullPointerException e) { - CoreLog.internal.log(Level.DEBUG, "expected non-scalar type {0}", e.getMessage()); + CoreLog.internal.log(DEBUG, "expected non-scalar type {0}", e.getMessage()); } return new DeployBeanPropertyAssocMany(desc, targetType, manyType); } @@ -133,7 +134,7 @@ private DeployBeanProperty createProp(DeployBeanDescriptor desc, Field field) // not supporting this field (generic type used) return null; } - CoreLog.internal.log(Level.WARNING, "Could not find parameter type (via reflection) on " + desc.getFullName() + " " + field.getName()); + CoreLog.internal.log(WARNING, "Could not find parameter type (via reflection) on " + desc.getFullName() + " " + field.getName()); } return createManyType(desc, targetType, manyType); } @@ -152,7 +153,7 @@ private DeployBeanProperty createProp(DeployBeanDescriptor desc, Field field) return new DeployBeanPropertyAssocOne(desc, propertyType); } catch (Exception e) { - CoreLog.log.log(Level.ERROR, "Error with " + desc + " field:" + field.getName(), e); + CoreLog.log.log(ERROR, "Error with " + desc + " field:" + field.getName(), e); return null; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java index 454bc65e1a..67f4d99127 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/dto/DtoMetaBuilder.java @@ -3,13 +3,14 @@ import io.ebeaninternal.api.CoreLog; import io.ebeaninternal.server.type.TypeManager; -import java.lang.System.Logger.Level; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Build the DtoMeta for a bean. *

@@ -40,7 +41,7 @@ private void readProperties() { final String name = propertyName(method.getName()); properties.add(new DtoMetaProperty(typeManager, dtoType, method, name)); } catch (Exception e) { - CoreLog.log.log(Level.DEBUG, "exclude on " + dtoType + " method " + method, e); + CoreLog.log.log(DEBUG, "exclude on " + dtoType + " method " + method, e); } } } @@ -78,7 +79,7 @@ private void readConstructors() { constructorList.add(new DtoMetaConstructor(typeManager, constructor, dtoType)); } catch (Exception e) { // we don't want that constructor - CoreLog.log.log(Level.DEBUG, "exclude on " + dtoType + " constructor " + constructor, e); + CoreLog.log.log(DEBUG, "exclude on " + dtoType + " constructor " + constructor, e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java index de9b959ef4..ea7ce58e48 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonExecutorService.java @@ -2,10 +2,11 @@ import io.avaje.applog.AppLog; -import java.lang.System.Logger.Level; import java.util.concurrent.*; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; + /** * A "CachedThreadPool" based on Daemon threads. *

@@ -43,19 +44,19 @@ void shutdown() { lock.lock(); try { if (service.isShutdown()) { - logger.log(Level.DEBUG, "DaemonExecutorService[{0}] already shut down", namePrefix); + logger.log(DEBUG, "DaemonExecutorService[{0}] already shut down", namePrefix); return; } try { - logger.log(Level.DEBUG, "DaemonExecutorService[{0}] shutting down...", namePrefix); + logger.log(DEBUG, "DaemonExecutorService[{0}] shutting down...", namePrefix); service.shutdown(); if (!service.awaitTermination(shutdownWaitSeconds, TimeUnit.SECONDS)) { - logger.log(Level.INFO, "DaemonExecutorService[{0}] shut down timeout exceeded. Terminating running threads.", namePrefix); + logger.log(INFO, "DaemonExecutorService[{0}] shut down timeout exceeded. Terminating running threads.", namePrefix); service.shutdownNow(); } } catch (Exception e) { - logger.log(Level.ERROR, "Error during shutdown of DaemonThreadPool[" + namePrefix + "]", e); + logger.log(ERROR, "Error during shutdown of DaemonThreadPool[" + namePrefix + "]", e); e.printStackTrace(); } } finally { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java index 1a7c23b3e4..1dd961c6c5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DaemonScheduleThreadPool.java @@ -2,11 +2,12 @@ import io.ebeaninternal.api.CoreLog; -import java.lang.System.Logger.Level; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; + /** * Daemon based ScheduleThreadPool. */ @@ -38,19 +39,19 @@ public void shutdown() { lock.lock(); try { if (super.isShutdown()) { - log.log(Level.DEBUG, "Already shutdown threadPool {0}", namePrefix); + log.log(DEBUG, "Already shutdown threadPool {0}", namePrefix); return; } try { - log.log(Level.TRACE, "shutting down threadPool {0}", namePrefix); + log.log(TRACE, "shutting down threadPool {0}", namePrefix); super.shutdown(); if (!super.awaitTermination(shutdownWaitSeconds, TimeUnit.SECONDS)) { - log.log(Level.INFO, "Shutdown wait timeout exceeded. Terminating running threads for {0}", namePrefix); + log.log(INFO, "Shutdown wait timeout exceeded. Terminating running threads for {0}", namePrefix); super.shutdownNow(); } - log.log(Level.TRACE, "shutdown complete for threadPool {0}", namePrefix); + log.log(TRACE, "shutdown complete for threadPool {0}", namePrefix); } catch (Exception e) { - log.log(Level.ERROR, "Error during shutdown of threadPool " + namePrefix, e); + log.log(ERROR, "Error during shutdown of threadPool " + namePrefix, e); e.printStackTrace(); } } finally { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java index ce0254a22d..f134f9da72 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/executor/DefaultBackgroundExecutor.java @@ -5,9 +5,10 @@ import io.ebean.config.BackgroundExecutorWrapper; import io.ebeaninternal.api.SpiBackgroundExecutor; -import java.lang.System.Logger.Level; import java.util.concurrent.*; +import static java.lang.System.Logger.Level.*; + /** * The default implementation of the BackgroundExecutor. */ @@ -27,7 +28,7 @@ public DefaultBackgroundExecutor(int schedulePoolSize, int shutdownWaitSeconds, this.schedulePool = new DaemonScheduleThreadPool(schedulePoolSize, shutdownWaitSeconds, namePrefix + "-periodic-"); this.pool = new DaemonExecutorService(shutdownWaitSeconds, namePrefix); this.wrapper = wrapper; - log.log(Level.DEBUG, "Created backgroundExecutor {0} (schedulePoolSize={1}, shutdownWaitSeconds={2})", namePrefix, schedulePoolSize, shutdownWaitSeconds); + log.log(DEBUG, "Created backgroundExecutor {0} (schedulePoolSize={1}, shutdownWaitSeconds={2})", namePrefix, schedulePoolSize, shutdownWaitSeconds); } /** @@ -64,14 +65,14 @@ Runnable wrap(Runnable task) { */ private Runnable logExceptions(Runnable task) { long queued = System.nanoTime(); - log.log(Level.TRACE, "Queued {0}", task); + log.log(TRACE, "Queued {0}", task); return () -> { try { - if (log.isLoggable(Level.TRACE)) { + if (log.isLoggable(TRACE)) { long start = System.nanoTime(); - log.log(Level.TRACE, "Start {0} (delay time {1} us)", task, (start - queued) / 1000L); + log.log(TRACE, "Start {0} (delay time {1} us)", task, (start - queued) / 1000L); task.run(); - log.log(Level.TRACE, "Stop {0} (exec time {1} us)", task, (System.nanoTime() - start) / 1000L); + log.log(TRACE, "Stop {0} (exec time {1} us)", task, (System.nanoTime() - start) / 1000L); } else { task.run(); } @@ -79,7 +80,7 @@ private Runnable logExceptions(Runnable task) { // log any exception here. Note they will not bubble up to the calling user // unless Future.get() is checked. (Which is almost never done on scheduled // background executions) - log.log(Level.ERROR, "Error while executing the task " + task, t); + log.log(ERROR, "Error while executing the task " + task, t); throw t; } }; @@ -127,10 +128,10 @@ public ScheduledFuture schedule(Callable task, long delay, TimeUnit un @Override public void shutdown() { - log.log(Level.TRACE, "BackgroundExecutor shutting down"); + log.log(TRACE, "BackgroundExecutor shutting down"); schedulePool.shutdown(); pool.shutdown(); - log.log(Level.DEBUG, "BackgroundExecutor stopped"); + log.log(DEBUG, "BackgroundExecutor stopped"); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java index c7ae7e0d36..d17a8385d5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1IdGenerator.java @@ -1,12 +1,13 @@ package io.ebeaninternal.server.idgen; import java.io.*; -import java.lang.System.Logger.Level; import java.net.NetworkInterface; import java.net.SocketException; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import static java.lang.System.Logger.Level.*; + /** * IdGenerator for java util UUID. *

@@ -82,7 +83,7 @@ private static byte[] getHardwareId() throws SocketException { } } } catch (SocketException ex) { - log.log(Level.DEBUG, "Skipping " + network, ex); + log.log(DEBUG, "Skipping " + network, ex); } } return fallbackAddr; @@ -119,7 +120,7 @@ private UuidV1IdGenerator(final File stateFile, String altNodeId) { // See, if there is an alternative MAC address set. nodeId = parseAlternativeNodeId(altNodeId); restoreState(); - log.log(Level.INFO, "Explicitly using ID {0} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(INFO, "Explicitly using ID {0} to generate Type 1 UUIDs", getNodeIdentifier()); } UUID uuid = nextId(null); long ts = timeStamp.get(); @@ -127,9 +128,9 @@ private UuidV1IdGenerator(final File stateFile, String altNodeId) { ts /= MILLIS_TO_UUID; saveState(); - log.log(Level.DEBUG, "Saved state: clockSeq {0}, timestamp {1}, uuid {2}, stateFile: {3})", clockSeq.get(), new Date(ts), uuid, stateFile); + log.log(DEBUG, "Saved state: clockSeq {0}, timestamp {1}, uuid {2}, stateFile: {3})", clockSeq.get(), new Date(ts), uuid, stateFile); } catch (IOException e) { - log.log(Level.ERROR, "There was a problem while detecting the nodeId. Falling back to random mode. Try using to specify 'ebean.uuidNodeId' property", e); + log.log(ERROR, "There was a problem while detecting the nodeId. Falling back to random mode. Try using to specify 'ebean.uuidNodeId' property", e); useRandomMode(); } } @@ -146,16 +147,16 @@ private void tryHardwareId() throws IOException { try { nodeId = getHardwareId(); } catch (IOException e) { - log.log(Level.ERROR, "Error while reading MAC address. Fall back to 'generate' mode", e); + log.log(ERROR, "Error while reading MAC address. Fall back to 'generate' mode", e); tryGenerateMode(); } if (nodeId != null) { restoreState(); - log.log(Level.INFO, "Using MAC {0} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(INFO, "Using MAC {0} to generate Type 1 UUIDs", getNodeIdentifier()); return; } - log.log(Level.WARNING, "No suitable network interface found. Fall back to 'generate' mode"); + log.log(WARNING, "No suitable network interface found. Fall back to 'generate' mode"); tryGenerateMode(); } @@ -165,11 +166,11 @@ private void tryHardwareId() throws IOException { */ private void tryGenerateMode() throws IOException { if (restoreState()) { - log.log(Level.INFO, "Using recently generated nodeId {0} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(INFO, "Using recently generated nodeId {0} to generate Type 1 UUIDs", getNodeIdentifier()); } else { // RFC 4.5 use random portion for node nodeId = super.getNodeIdBytes(); - log.log(Level.INFO, "Using a newly generated nodeId {0} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(INFO, "Using a newly generated nodeId {0} to generate Type 1 UUIDs", getNodeIdentifier()); } } @@ -180,7 +181,7 @@ private void tryGenerateMode() throws IOException { private void useRandomMode() { canSaveState = false; nodeId = super.getNodeIdBytes(); - log.log(Level.INFO, "Explicitly using a new random ID {0} to generate Type 1 UUIDs", getNodeIdentifier()); + log.log(INFO, "Explicitly using a new random ID {0} to generate Type 1 UUIDs", getNodeIdentifier()); } /** @@ -211,14 +212,14 @@ private boolean restoreState() throws IOException { String propNodeId = prop.getProperty("nodeId"); if (propNodeId == null || propNodeId.isEmpty()) { - log.log(Level.WARNING, "State file '{0}' is incomplete", stateFile); + log.log(WARNING, "State file '{0}' is incomplete", stateFile); return false; // we cannot restore } try { if (nodeId == null) { nodeId = parseAlternativeNodeId(propNodeId); } else if (!getNodeIdentifier().equals(propNodeId)) { - log.log(Level.WARNING, + log.log(WARNING, "The nodeId in the state file '{0}' has changed from {1} to {2}. " + "This can happen when MAC address changes or when two containers share the same state file", stateFile, propNodeId, getNodeIdentifier()); @@ -231,7 +232,7 @@ private boolean restoreState() throws IOException { return true; } catch (IllegalArgumentException nfe) { - log.log(Level.ERROR, "State file corrupt: " + stateFile, nfe); + log.log(ERROR, "State file corrupt: " + stateFile, nfe); } return false; } @@ -255,7 +256,7 @@ protected void saveState() { try (OutputStream os = new FileOutputStream(stateFile)) { prop.store(os, "ebean uuid state file"); } catch (IOException e) { - log.log(Level.ERROR, "Could not persist uuid state to: " + stateFile, e); + log.log(ERROR, "Could not persist uuid state to: " + stateFile, e); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java index e5a34d135a..484d926984 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/idgen/UuidV1RndIdGenerator.java @@ -4,13 +4,14 @@ import io.ebean.Transaction; import io.ebean.config.dbplatform.PlatformIdGenerator; -import java.lang.System.Logger.Level; import java.security.SecureRandom; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.INFO; + /** * IdGenerator for (pseudo) type 1 UUIDs. * @@ -105,7 +106,7 @@ public UUID nextId(Transaction t) { delta = current - last; if (delta < -10000 * 20000) { - log.log(Level.INFO, "Clock skew of {} ms detected", delta / -10000); + log.log(INFO, "Clock skew of {} ms detected", delta / -10000); // The clock was adjusted back about 2 seconds, or we were generating a lot of ids too fast // if so, we try to set the current as last and also increment the clockSeq. lock.lock(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java b/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java index adc6482758..922667037a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/logger/DSpiLogger.java @@ -2,7 +2,8 @@ import io.ebeaninternal.api.SpiLogger; -import java.lang.System.Logger.Level; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.TRACE; final class DSpiLogger implements SpiLogger { @@ -14,21 +15,21 @@ final class DSpiLogger implements SpiLogger { @Override public boolean isDebug() { - return logger.isLoggable(Level.DEBUG); + return logger.isLoggable(DEBUG); } @Override public boolean isTrace() { - return logger.isLoggable(Level.TRACE); + return logger.isLoggable(TRACE); } @Override public void debug(String msg) { - logger.log(Level.DEBUG, msg); + logger.log(DEBUG, msg); } @Override public void trace(String msg) { - logger.log(Level.TRACE, msg); + logger.log(TRACE, msg); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java index ccf0689734..ddd1747a16 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/BatchedPstmt.java @@ -6,13 +6,14 @@ import java.io.IOException; import java.io.InputStream; -import java.lang.System.Logger.Level; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; +import static java.lang.System.Logger.Level.WARNING; + /** * A batched statement that is held in BatchedPstmtHolder. It has a list of * BatchPostExecute which it will process after the statement is executed. @@ -136,7 +137,7 @@ public void close() { try { pstmt.close(); } catch (SQLException e) { - CoreLog.log.log(Level.WARNING, "BatchedPstmt Error closing statement", e); + CoreLog.log.log(WARNING, "BatchedPstmt Error closing statement", e); } finally { pstmt = null; } @@ -202,7 +203,7 @@ private void closeInputStreams() { try { inputStream.close(); } catch (IOException e) { - CoreLog.log.log(Level.WARNING, "BatchedPstmt Error closing inputStream ", e); + CoreLog.log.log(WARNING, "BatchedPstmt Error closing inputStream ", e); } } inputStreams = null; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java index 779362ee89..de8e16eb06 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/Binder.java @@ -12,12 +12,13 @@ import io.ebeaninternal.server.type.*; import javax.persistence.PersistenceException; -import java.lang.System.Logger.Level; import java.math.BigDecimal; import java.sql.*; import java.util.Collection; import java.util.List; +import static java.lang.System.Logger.Level.WARNING; + /** * Binds bean values to a PreparedStatement. */ @@ -133,7 +134,7 @@ private void bind(List list, DataBind dataBind, StringBuilder } } catch (SQLException ex) { - CoreLog.log.log(Level.WARNING, "error binding parameter [{0}][{1}]", (dataBind.currentPos() - 1), value); + CoreLog.log.log(WARNING, "error binding parameter [{0}][{1}]", (dataBind.currentPos() - 1), value); throw ex; } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java index 728c4efcb0..104ccbe74a 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/DefaultPersister.java @@ -13,10 +13,12 @@ import io.ebeaninternal.server.core.PersistRequest.Type; import io.ebeaninternal.server.deploy.*; -import java.lang.System.Logger.Level; import java.sql.SQLException; import java.util.*; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.TRACE; + /** * Persister implementation using DML. *

@@ -143,7 +145,7 @@ public List draftRestore(Query query, Transaction transaction) { DraftHandler draftHandler = new DraftHandler<>(desc, transaction); List liveBeans = draftHandler.fetchSourceBeans(query, false); - PUB.log(Level.DEBUG, "draftRestore [{0}] count[{1}]", desc.name(), liveBeans.size()); + PUB.log(DEBUG, "draftRestore [{0}] count[{1}]", desc.name(), liveBeans.size()); if (liveBeans.isEmpty()) { return Collections.emptyList(); } @@ -156,11 +158,11 @@ public List draftRestore(Query query, Transaction transaction) { // reset @DraftDirty and @DraftReset properties draftHandler.resetDraft(draftBean); - PUB.log(Level.TRACE, "draftRestore bean [{0}] id[{1}]", desc.name(), draftHandler.getId()); + PUB.log(TRACE, "draftRestore bean [{0}] id[{1}]", desc.name(), draftHandler.getId()); update(createRequest(draftBean, transaction, null, mgr, Type.UPDATE, Flags.RECURSE)); } - PUB.log(Level.DEBUG, "draftRestore - complete for [{0}]", desc.name()); + PUB.log(DEBUG, "draftRestore - complete for [{0}]", desc.name()); return draftHandler.getDrafts(); } @@ -185,7 +187,7 @@ public List publish(Query query, Transaction transaction) { DraftHandler draftHandler = new DraftHandler<>(desc, transaction); List draftBeans = draftHandler.fetchSourceBeans(query, true); - PUB.log(Level.DEBUG, "publish [{0}] count[{1}]", desc.name(), draftBeans.size()); + PUB.log(DEBUG, "publish [{0}] count[{1}]", desc.name(), draftBeans.size()); if (draftBeans.isEmpty()) { return Collections.emptyList(); } @@ -202,7 +204,7 @@ public List publish(Query query, Transaction transaction) { draftHandler.resetDraft(draftBean); Type persistType = draftHandler.isInsert() ? Type.INSERT : Type.UPDATE; - PUB.log(Level.TRACE, "publish bean [{0}] id[{1}] type[{2}]", desc.name(), draftHandler.getId(), persistType); + PUB.log(TRACE, "publish bean [{0}] id[{1}] type[{2}]", desc.name(), draftHandler.getId(), persistType); PersistRequestBean request = createRequest(liveBean, transaction, null, mgr, persistType, Flags.PUBLISH_RECURSE); if (persistType == Type.INSERT) { @@ -214,7 +216,7 @@ public List publish(Query query, Transaction transaction) { } draftHandler.updateDrafts(transaction, mgr); - PUB.log(Level.DEBUG, "publish - complete for [{0}]", desc.name()); + PUB.log(DEBUG, "publish - complete for [{0}]", desc.name()); return livePublish; } @@ -270,7 +272,7 @@ void resetDraft(T draftBean) { void updateDrafts(Transaction transaction, BeanManager mgr) { if (!draftUpdates.isEmpty()) { // update the dirty status on the drafts that have been published - PUB.log(Level.DEBUG, "publish - update dirty status on [{0}] drafts", draftUpdates.size()); + PUB.log(DEBUG, "publish - update dirty status on [{0}] drafts", draftUpdates.size()); for (T draftUpdate : draftUpdates) { update(createRequest(draftUpdate, transaction, null, mgr, Type.UPDATE, Flags.ZERO)); } @@ -491,8 +493,8 @@ private void update(PersistRequestBean request) { } if (request.isDirty()) { request.executeOrQueue(); - } else if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "Update skipped as bean is unchanged: {0}", request.bean()); + } else if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "Update skipped as bean is unchanged: {0}", request.bean()); } if (request.isPersistCascade()) { // save all the beans in assocMany's after @@ -538,8 +540,8 @@ private int deleteRequest(PersistRequestBean req, PersistRequestBean draft if (req.isRegisteredForDeleteBean()) { // skip deleting bean. Used where cascade is on // both sides of a relationship - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "skipping delete on alreadyRegistered {0}", req.bean()); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "skipping delete on alreadyRegistered {0}", req.bean()); } return 0; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java index c839ac9e60..b01d685a39 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/persist/SaveManyBase.java @@ -9,7 +9,8 @@ import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; import java.io.IOException; -import java.lang.System.Logger.Level; + +import static java.lang.System.Logger.Level.ERROR; /** * Base for saving entity bean collections and element collections. @@ -72,7 +73,7 @@ final void postElementCollectionUpdate() { String asJson = many.jsonWriteCollection(value); request.addCollectionChange(many.name(), asJson); } catch (IOException e) { - CoreLog.log.log(Level.ERROR, "Error build element collection entry for L2 cache", e); + CoreLog.log.log(ERROR, "Error build element collection entry for L2 cache", e); } } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java index 33f3531761..88818d687c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/CQueryPlanManager.java @@ -7,12 +7,12 @@ import io.ebeaninternal.server.transaction.TransactionManager; import io.ebeaninternal.server.type.bindcapture.BindCapture; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.List; import java.util.concurrent.ConcurrentHashMap; +import static java.lang.System.Logger.Level.ERROR; import static java.util.Collections.emptyList; public final class CQueryPlanManager implements QueryPlanManager { @@ -65,7 +65,7 @@ private List collectPlans(QueryPlanRequest request) { } return req.plans(); } catch (SQLException e) { - CoreLog.log.log(Level.ERROR, "Error during query plan collection", e); + CoreLog.log.log(ERROR, "Error during query plan collection", e); return emptyList(); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java index 30586c4f7f..412c74fc85 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/query/SqlTreeBuilder.java @@ -12,9 +12,10 @@ import io.ebeaninternal.server.querydefn.OrmQueryDetail; import io.ebeaninternal.server.querydefn.OrmQueryProperties; -import java.lang.System.Logger.Level; import java.util.*; +import static java.lang.System.Logger.Level.ERROR; + /** * Factory for SqlTree. */ @@ -385,7 +386,7 @@ private void buildExtraJoins(STreeType desc, List myList) { private void addPropertyToSubQuery(SqlTreeProperties selectProps, STreeType desc, String propName, String path) { STreeProperty p = desc.findPropertyWithDynamic(propName, path); if (p == null) { - log.log(Level.ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); + log.log(ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); return; } else if (p instanceof STreePropertyAssoc && p.isEmbedded()) { // if the property is embedded we need to lookup the real column name @@ -420,13 +421,13 @@ private void addProperty(SqlTreeProperties selectProps, STreeType desc, OrmQuery if (p != null) { selectProps.add(p); } else { - log.log(Level.ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); + log.log(ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); } } else if (p.isEmbedded() || (p instanceof STreePropertyAssoc && !queryProps.isIncludedBeanJoin(p.name()))) { // add the embedded bean or the *ToOne assoc bean. We skip the check that the *ToOne propName maps to Id property ... selectProps.add(p); } else { - log.log(Level.ERROR, "property [{0}] expected to be an embedded or *ToOne bean for query - excluding it.", p.fullName()); + log.log(ERROR, "property [{0}] expected to be an embedded or *ToOne bean for query - excluding it.", p.fullName()); } } @@ -435,7 +436,7 @@ private void addProperty(SqlTreeProperties selectProps, STreeType desc, OrmQuery // sub class hierarchy if required STreeProperty p = desc.findPropertyWithDynamic(propName, queryProps.getPath()); if (p == null) { - log.log(Level.ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); + log.log(ERROR, "property [{0}] not found on {1} for query - excluding it.", propName, desc); p = desc.findProperty("id"); selectProps.add(p); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java b/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java index b49f3baf4e..1e14578de3 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/readaudit/DefaultReadAuditLogger.java @@ -11,9 +11,11 @@ import java.io.IOException; import java.io.StringWriter; -import java.lang.System.Logger.Level; import java.util.Map; +import static java.lang.System.Logger.Level.ERROR; +import static java.lang.System.Logger.Level.INFO; + /** * Default implementation of ReadAuditLogger that writes the event in JSON format to standard loggers. */ @@ -48,9 +50,9 @@ public void queryPlan(ReadAuditQueryPlan queryPlan) { } gen.writeEndObject(); gen.flush(); - queryLogger.log(Level.INFO, writer.toString()); + queryLogger.log(INFO, writer.toString()); } catch (IOException e) { - CoreLog.log.log(Level.ERROR, "Error writing Read audit event", e); + CoreLog.log.log(ERROR, "Error writing Read audit event", e); } } @@ -75,9 +77,9 @@ protected void writeEvent(ReadEvent event) { StringWriter writer = new StringWriter(defaultReadBuffer); JsonGenerator gen = jsonFactory.createGenerator(writer); writeDetails(gen, event); - auditLogger.log(Level.INFO, writer.toString()); + auditLogger.log(INFO, writer.toString()); } catch (IOException e) { - CoreLog.log.log(Level.ERROR, "Error writing Read audit event", e); + CoreLog.log.log(ERROR, "Error writing Read audit event", e); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java index 028b40c19c..c690a80619 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/DefaultProfileHandler.java @@ -11,7 +11,6 @@ import java.io.File; import java.io.IOException; import java.io.Writer; -import java.lang.System.Logger.Level; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; @@ -22,6 +21,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; import static java.time.temporal.ChronoField.*; /** @@ -79,7 +79,7 @@ public DefaultProfileHandler(ProfilingConfig config) { this.executor = Executors.newSingleThreadExecutor(); this.dir = new File(config.getDirectory()); if (!dir.exists() && !dir.mkdirs()) { - log.log(Level.ERROR, "failed to mkdirs " + dir.getAbsolutePath()); + log.log(ERROR, "failed to mkdirs " + dir.getAbsolutePath()); } incrementFile(); } @@ -109,7 +109,7 @@ private void flushCurrentFile() { out.close(); out = null; } catch (IOException e) { - log.log(Level.ERROR, "Failed to flush and close transaction profiling file ", e); + log.log(ERROR, "Failed to flush and close transaction profiling file ", e); } } } finally { @@ -129,7 +129,7 @@ private void incrementFile() { File file = new File(dir, "txprofile-" + now + ".tprofile"); out = IOUtils.newWriter(file); } catch (IOException e) { - log.log(Level.ERROR, "Not expected", e); + log.log(ERROR, "Not expected", e); } } finally { lock.unlock(); @@ -152,7 +152,7 @@ private void collect() { } flushCurrentFile(); } catch (Exception e) { - log.log(Level.WARNING, "Error on collect", e); + log.log(WARNING, "Error on collect", e); } } @@ -183,10 +183,10 @@ private void write(TransactionProfile profile) { if (profileCounter % profilesPerFile == 0) { incrementFile(); - log.log(Level.DEBUG, "profiled {0} transactions", profileCounter); + log.log(DEBUG, "profiled {0} transactions", profileCounter); } } catch (IOException e) { - log.log(Level.WARNING, "Error writing transaction profiling", e); + log.log(WARNING, "Error writing transaction profiling", e); } } @@ -250,16 +250,16 @@ public void online(boolean online) { @Override public void shutdown() { shutdown = true; - log.log(Level.TRACE, "shutting down"); + log.log(TRACE, "shutting down"); try { executor.shutdown(); if (!executor.awaitTermination(4, TimeUnit.SECONDS)) { - log.log(Level.INFO, "Shut down timeout exceeded. Terminating profiling consumer thread."); + log.log(INFO, "Shut down timeout exceeded. Terminating profiling consumer thread."); executor.shutdownNow(); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); - log.log(Level.WARNING, "Interrupt on shutdown", e); + log.log(WARNING, "Interrupt on shutdown", e); } flushCurrentFile(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java index 9ee5aa5a00..2dfa2a4548 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/ImplicitReadOnlyTransaction.java @@ -12,12 +12,13 @@ import io.ebeanservice.docstore.api.DocStoreTransaction; import javax.persistence.PersistenceException; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; +import static java.lang.System.Logger.Level.ERROR; + /** * Read only transaction expected to use autoCommit connection and for implicit use only. *

@@ -484,7 +485,7 @@ private void deactivate() { } catch (Exception ex) { // the connection pool will automatically remove the // connection if it does not pass the test - CoreLog.log.log(Level.ERROR, "Error closing connection", ex); + CoreLog.log.log(ERROR, "Error closing connection", ex); } connection = null; active = false; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java index 38021986f9..35fb61307d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JdbcTransaction.java @@ -17,12 +17,13 @@ import javax.persistence.PersistenceException; import javax.persistence.RollbackException; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.*; import java.util.function.Consumer; +import static java.lang.System.Logger.Level.ERROR; + /** * JDBC Connection based transaction. */ @@ -356,7 +357,7 @@ private void withEachCallback(Consumer consumer) { try { consumer.accept(callbackList.get(i)); } catch (Exception e) { - log.log(Level.ERROR, "Error executing transaction callback", e); + log.log(ERROR, "Error executing transaction callback", e); } } } @@ -884,7 +885,7 @@ void deactivate() { connection.setReadOnly(false); } } catch (SQLException e) { - log.log(Level.ERROR, "Error setting to readOnly?", e); + log.log(ERROR, "Error setting to readOnly?", e); } try { if (autoCommit) { @@ -892,14 +893,14 @@ void deactivate() { connection.setAutoCommit(true); } } catch (SQLException e) { - log.log(Level.ERROR, "Error setting to readOnly?", e); + log.log(ERROR, "Error setting to readOnly?", e); } try { connection.close(); } catch (Exception ex) { // the connection pool will automatically remove the // connection if it does not pass the test - log.log(Level.ERROR, "Error closing connection", ex); + log.log(ERROR, "Error closing connection", ex); } connection = null; active = false; @@ -932,7 +933,7 @@ private void connectionEndForQueryOnly() { } withEachCallback(TransactionCallback::postCommit); } catch (SQLException e) { - log.log(Level.ERROR, "Error when ending a query only transaction via " + onQueryOnly, e); + log.log(ERROR, "Error when ending a query only transaction via " + onQueryOnly, e); } } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java index 3845d0776a..73bc989818 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/JtaTransactionManager.java @@ -13,7 +13,9 @@ import javax.transaction.Synchronization; import javax.transaction.TransactionSynchronizationRegistry; import javax.transaction.UserTransaction; -import java.lang.System.Logger.Level; + +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.WARNING; /** * Hook into external JTA transaction manager. @@ -87,15 +89,15 @@ public Object getCurrentTransaction() { SpiTransaction currentEbeanTransaction = scope.inScope(); if (currentEbeanTransaction != null) { // NOT expecting this so log WARNING - log.log(Level.WARNING, "JTA Transaction - no current txn BUT using current Ebean one {0}", currentEbeanTransaction.getId()); + log.log(WARNING, "JTA Transaction - no current txn BUT using current Ebean one {0}", currentEbeanTransaction.getId()); return currentEbeanTransaction; } UserTransaction ut = getUserTransaction(); if (ut == null) { // no current JTA transaction - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "JTA Transaction - no current txn"); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "JTA Transaction - no current txn"); } return null; } @@ -181,21 +183,21 @@ public void beforeCompletion() { public void afterCompletion(int status) { switch (status) { case Status.STATUS_COMMITTED: - log.log(Level.DEBUG, "Jta Txn [{0}] committed", transaction.getId()); + log.log(DEBUG, "Jta Txn [{0}] committed", transaction.getId()); transaction.postCommit(); // Remove this transaction object as it is completed transactionManager.scope().clearExternal(); break; case Status.STATUS_ROLLEDBACK: - log.log(Level.DEBUG, "Jta Txn [{0}] rollback", transaction.getId()); + log.log(DEBUG, "Jta Txn [{0}] rollback", transaction.getId()); transaction.postRollback(null); // Remove this transaction object as it is completed transactionManager.scope().clearExternal(); break; default: - log.log(Level.DEBUG, "Jta Txn [{0}] status:{1}", transaction.getId(), status); + log.log(DEBUG, "Jta Txn [{0}] status:{1}", transaction.getId(), status); } // No matter the completion status of the transaction, we release the connection we got from the pool. diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java index b1a3ee4f8c..f36dd7edef 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java @@ -11,10 +11,11 @@ import io.ebeaninternal.server.core.PersistRequestBean; import io.ebeanservice.docstore.api.DocStoreUpdates; -import java.lang.System.Logger.Level; import java.util.List; import java.util.Set; +import static java.lang.System.Logger.Level.DEBUG; + /** * Performs post commit processing using a background thread. *

@@ -104,8 +105,8 @@ private boolean isDocStoreUpdate() { private void notifyCluster() { if (remoteTransactionEvent != null && !remoteTransactionEvent.isEmpty()) { // send the interesting events to the cluster - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "Cluster Send: {0}", remoteTransactionEvent); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "Cluster Send: {0}", remoteTransactionEvent); } clusterManager.broadcast(remoteTransactionEvent); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java index c1ba2e773c..37669d3a3c 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TableModState.java @@ -6,11 +6,13 @@ import io.ebean.cache.ServerCacheNotification; import io.ebean.cache.ServerCacheNotify; -import java.lang.System.Logger.Level; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.TRACE; + /** * Holds timestamp of last modification per table. *

@@ -34,8 +36,8 @@ void touch(Set touchedTables) { for (String tableName : touchedTables) { tableModStamp.put(tableName, modNanoTime); } - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "TableModState updated - touched:{0} modNanoTime:{1}", touchedTables, modNanoTime); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "TableModState updated - touched:{0} modNanoTime:{1}", touchedTables, modNanoTime); } } @@ -46,8 +48,8 @@ boolean isValid(Set tables, long sinceNanoTime) { for (String tableName : tables) { Long modTime = tableModStamp.get(tableName); if (modTime != null && modTime >= sinceNanoTime) { - if (log.isLoggable(Level.TRACE)) { - log.log(Level.TRACE, "Invalidate on table:{0}", tableName); + if (log.isLoggable(TRACE)) { + log.log(TRACE, "Invalidate on table:{0}", tableName); } return false; } @@ -73,8 +75,8 @@ public boolean isValid(QueryCacheEntry entry) { public void notify(ServerCacheNotification notification) { // use local clock - for slightly more aggressive invalidation (as later) // that removes any concern regarding clock syncing across cluster - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "ServerCacheNotification:{0}", notification); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "ServerCacheNotification:{0}", notification); } touch(notification.getDependentTables()); } @@ -87,8 +89,8 @@ public void notify(ServerCacheNotification notification) { public void notify(RemoteTableMod tableMod) { // use local clock - for slightly more aggressive invalidation (as later) // that removes any concern regarding clock syncing across cluster - if (log.isLoggable(Level.DEBUG)) { - log.log(Level.DEBUG, "RemoteTableMod:{0}", tableMod); + if (log.isLoggable(DEBUG)) { + log.log(DEBUG, "RemoteTableMod:{0}", tableMod); } touch(tableMod.getTables()); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java index ace9d4f77a..523315eee5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java @@ -32,7 +32,6 @@ import javax.persistence.PersistenceException; import javax.sql.DataSource; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; import java.util.List; @@ -40,6 +39,9 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.ERROR; + /** * Manages transactions. *

@@ -365,7 +367,7 @@ public final void notifyOfRollback(SpiTransaction transaction, Throwable cause) txnLogger.debug(msg); } } catch (Exception ex) { - log.log(Level.ERROR, "Error while notifying TransactionEventListener of rollback event", ex); + log.log(ERROR, "Error while notifying TransactionEventListener of rollback event", ex); } } @@ -416,7 +418,7 @@ public final void notifyOfCommit(SpiTransaction transaction) { postCommit.notifyLocalCache(); backgroundExecutor.execute(postCommit.backgroundNotify()); } catch (Exception ex) { - log.log(Level.ERROR, "NotifyOfCommit failed. L2 Cache potentially not notified.", ex); + log.log(ERROR, "NotifyOfCommit failed. L2 Cache potentially not notified.", ex); } } @@ -442,8 +444,8 @@ private void externalModificationEvent(TransactionEventTable tableEvents) { * Notify local BeanPersistListeners etc of events from another server in the cluster. */ public final void remoteTransactionEvent(RemoteTransactionEvent remoteEvent) { - if (clusterLogger.isLoggable(Level.DEBUG)) { - clusterLogger.log(Level.DEBUG, "processing {0}", remoteEvent); + if (clusterLogger.isLoggable(DEBUG)) { + clusterLogger.log(DEBUG, "processing {0}", remoteEvent); } CacheChangeSet changeSet = new CacheChangeSet(); diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java index a334942771..b4ce613bef 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/DataBind.java @@ -5,13 +5,14 @@ import io.ebeaninternal.server.core.timezone.DataTimeZone; import java.io.*; -import java.lang.System.Logger.Level; import java.math.BigDecimal; import java.sql.*; import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import static java.lang.System.Logger.Level.WARNING; + public class DataBind implements DataBinder { private final DataTimeZone dataTimeZone; @@ -101,7 +102,7 @@ private void closeInputStreams() { try { inputStream.close(); } catch (IOException e) { - CoreLog.log.log(Level.WARNING, "Error closing InputStream that was bound to PreparedStatement", e); + CoreLog.log.log(WARNING, "Error closing InputStream that was bound to PreparedStatement", e); } } inputStreams = null; diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java index c44670c73c..a1b7c37982 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/DefaultTypeManager.java @@ -29,7 +29,6 @@ import javax.persistence.AttributeConverter; import javax.persistence.EnumType; import java.io.File; -import java.lang.System.Logger.Level; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.ParameterizedType; @@ -45,6 +44,8 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import static java.lang.System.Logger.Level.*; + /** * Default implementation of TypeManager. *

@@ -219,10 +220,10 @@ public void add(ScalarType scalarType) { } private void logAdd(ScalarType scalarType) { - if (log.isLoggable(Level.TRACE)) { + if (log.isLoggable(TRACE)) { String msg = "ScalarType register [" + scalarType.getClass().getName() + "]"; msg += " for [" + scalarType.getType().getName() + "]"; - log.log(Level.TRACE, msg); + log.log(TRACE, msg); } } @@ -675,7 +676,7 @@ private void initialiseCustomScalarTypes(BootupClasses bootupClasses) { } add(scalarType); } catch (Exception e) { - log.log(Level.ERROR, "Error loading ScalarType [" + cls.getName() + "]", e); + log.log(ERROR, "Error loading ScalarType [" + cls.getName() + "]", e); } } } @@ -706,10 +707,10 @@ private void initialiseScalarConverters(BootupClasses bootupClasses) { } ScalarTypeConverter converter = foundType.getDeclaredConstructor().newInstance(); ScalarTypeWrapper stw = new ScalarTypeWrapper(logicalType, wrappedType, converter); - log.log(Level.DEBUG, "Register ScalarTypeWrapper from {0} -> {1} using:{2}", logicalType, persistType, foundType); + log.log(DEBUG, "Register ScalarTypeWrapper from {0} -> {1} using:{2}", logicalType, persistType, foundType); add(stw); } catch (Exception e) { - log.log(Level.ERROR, "Error registering ScalarTypeConverter [" + foundType.getName() + "]", e); + log.log(ERROR, "Error registering ScalarTypeConverter [" + foundType.getName() + "]", e); } } } @@ -730,10 +731,10 @@ private void initialiseAttributeConverters(BootupClasses bootupClasses) { } AttributeConverter converter = foundType.getDeclaredConstructor().newInstance(); ScalarTypeWrapper stw = new ScalarTypeWrapper(logicalType, wrappedType, new AttributeConverterAdapter(converter)); - log.log(Level.DEBUG, "Register ScalarTypeWrapper from {0} -> {1} using:{2}", logicalType, persistType, foundType); + log.log(DEBUG, "Register ScalarTypeWrapper from {0} -> {1} using:{2}", logicalType, persistType, foundType); add(stw); } catch (Exception e) { - log.log(Level.ERROR, "Error registering AttributeConverter [" + foundType.getName() + "]", e); + log.log(ERROR, "Error registering AttributeConverter [" + foundType.getName() + "]", e); } } } @@ -805,7 +806,7 @@ private void initialiseJodaTypes(DatabaseConfig config) { // detect if Joda classes are in the classpath if (config.getClassLoadConfig().isJodaTimePresent()) { // Joda classes are in the classpath so register the types - log.log(Level.DEBUG, "Registering Joda data types"); + log.log(DEBUG, "Registering Joda data types"); addType(LocalDateTime.class, new ScalarTypeJodaLocalDateTime(jsonDateTime)); addType(DateTime.class, new ScalarTypeJodaDateTime(jsonDateTime)); if (config.getDatabasePlatform().supportsNativeJavaTime()) { diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java index cddd892310..73037a58a4 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/ScalarTypeFile.java @@ -9,10 +9,11 @@ import io.ebeaninternal.api.CoreLog; import java.io.*; -import java.lang.System.Logger.Level; import java.sql.SQLException; import java.sql.Types; +import static java.lang.System.Logger.Level.ERROR; + /** * ScalarType for streaming between a File and the database. */ @@ -170,14 +171,14 @@ public long pump(InputStream is, OutputStream out) throws IOException { try { output.close(); } catch (IOException e) { - CoreLog.log.log(Level.ERROR, "Error when closing outputStream", e); + CoreLog.log.log(ERROR, "Error when closing outputStream", e); } } if (input != null) { try { input.close(); } catch (IOException e) { - CoreLog.log.log(Level.ERROR, "Error when closing inputStream ", e); + CoreLog.log.log(ERROR, "Error when closing inputStream ", e); } } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java index e91a067f4c..7f9c2ba6b5 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DdlGenerator.java @@ -15,10 +15,11 @@ import javax.persistence.PersistenceException; import java.io.*; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.SQLException; +import static java.lang.System.Logger.Level.WARNING; + /** * Controls the generation and execution of "Create All" and "Drop All" DDL scripts. *

@@ -60,7 +61,7 @@ public DdlGenerator(SpiEbeanServer server) { this.platform = databasePlatform.getPlatform(); this.platformName = platform.base().name(); if (!config.getTenantMode().isDdlEnabled() && config.isDdlRun()) { - log.log(Level.WARNING, "DDL can't be run on startup with TenantMode " + config.getTenantMode()); + log.log(WARNING, "DDL can't be run on startup with TenantMode " + config.getTenantMode()); this.runDdl = false; this.useMigrationStoredProcedures = false; } else { @@ -224,7 +225,7 @@ protected void runResourceScript(Connection connection, String sqlScript) throws if (sqlScript != null) { try (InputStream is = getClassLoader().getResourceAsStream(sqlScript)) { if (is == null) { - log.log(Level.WARNING, "sql script {0} was not found as a resource", sqlScript); + log.log(WARNING, "sql script {0} was not found as a resource", sqlScript); } else { String content = readContent(IOUtils.newReader(is)); // 'is' is closed runScript(connection, false, content, sqlScript); diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java index 9f9384d0d1..f20b39121a 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/DefaultDbMigration.java @@ -26,13 +26,13 @@ import java.io.File; import java.io.IOException; import java.io.Writer; -import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.ServiceLoader; import static io.ebeaninternal.api.PlatformMatch.matchPlatform; +import static java.lang.System.Logger.Level.*; /** * Generates DB Migration xml and sql scripts. @@ -402,7 +402,7 @@ private void generateExtraDdlFor(File migrationDir, DatabasePlatform dbPlatform, */ private void writeExtraDdl(File migrationDir, DdlScript script) throws IOException { String fullName = repeatableMigrationName(script.isInit(), script.getName()); - logger.log(Level.DEBUG, "writing repeatable script {0}", fullName); + logger.log(DEBUG, "writing repeatable script {0}", fullName); File file = new File(migrationDir, fullName); try (Writer writer = IOUtils.newWriter(file)) { writer.write(script.getValue()); @@ -419,7 +419,7 @@ private void logError(String message) { if (logToSystemOut) { System.out.println("DbMigration> " + message); } else { - logger.log(Level.ERROR, message); + logger.log(ERROR, message); } } @@ -430,7 +430,7 @@ private void logInfo(String message, Object value) { if (logToSystemOut) { System.out.println("DbMigration> " + message); } else { - logger.log(Level.INFO, message); + logger.log(INFO, message); } } @@ -792,7 +792,7 @@ protected DatabasePlatform platform(Platform platform) { case SQLSERVER: throw new IllegalArgumentException("Please choose the more specific SQLSERVER16 or SQLSERVER17 platform. Refer to issue #1340 for details"); case DB2: - logger.log(Level.WARNING, "Using DB2LegacyPlatform. It is recommended to migrate to db2luw/db2zos/db2fori. Refer to issue #2514 for details"); + logger.log(WARNING, "Using DB2LegacyPlatform. It is recommended to migrate to db2luw/db2zos/db2fori. Refer to issue #2514 for details"); case GENERIC: return new DatabasePlatform(); default: diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java index e949b17de9..696a9feb8a 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/MigrationModel.java @@ -4,11 +4,12 @@ import io.ebean.migration.MigrationVersion; import java.io.File; -import java.lang.System.Logger.Level; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static java.lang.System.Logger.Level.DEBUG; + /** * Build the model from the series of migrations. */ @@ -52,7 +53,7 @@ private void readMigrations(boolean initMigration) { if (!initMigration) { for (MigrationResource migrationResource : resources) { - logger.log(Level.DEBUG, "read {0}", migrationResource); + logger.log(DEBUG, "read {0}", migrationResource); model.apply(migrationResource.read(), migrationResource.version()); } } diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java index 00df18cf84..6f9e424a5c 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/dbmigration/model/PlatformDdlWriter.java @@ -15,9 +15,10 @@ import java.io.File; import java.io.IOException; import java.io.Writer; -import java.lang.System.Logger.Level; import java.util.List; +import static java.lang.System.Logger.Level.ERROR; + /** * Writes migration changes as platform specific DDL. */ @@ -107,7 +108,7 @@ public File subPath(File path, String suffix) { File subPath = new File(path, suffix); if (!subPath.exists()) { if (!subPath.mkdirs()) { - logger.log(Level.ERROR, "failed to create directories for " + subPath.getAbsolutePath()); + logger.log(ERROR, "failed to create directories for " + subPath.getAbsolutePath()); } } return subPath; diff --git a/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java b/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java index 379e33bd7a..3ff9034d18 100644 --- a/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java +++ b/ebean-ddl-generator/src/main/java/io/ebeaninternal/extraddl/model/ExtraDdlXmlReader.java @@ -8,9 +8,9 @@ import javax.xml.bind.Unmarshaller; import java.io.IOException; import java.io.InputStream; -import java.lang.System.Logger.Level; import static io.ebeaninternal.api.PlatformMatch.matchPlatform; +import static java.lang.System.Logger.Level.DEBUG; /** * Read ExtraDdl from an XML document. @@ -42,7 +42,7 @@ private static String buildExtra(Platform platform, boolean drops, ExtraDdl read StringBuilder sb = new StringBuilder(300); for (DdlScript script : read.getDdlScript()) { if (script.isDrop() == drops && matchPlatform(platform, script.getPlatforms())) { - logger.log(Level.DEBUG, "include script {}", script.getName()); + logger.log(DEBUG, "include script {}", script.getName()); String value = script.getValue(); sb.append(value); if (value.lastIndexOf(';') == -1) { diff --git a/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java b/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java index a523774238..37e701fe65 100644 --- a/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java +++ b/ebean-ddl-generator/src/test/java/io/localtest/BaseTestCase.java @@ -7,9 +7,10 @@ import io.ebean.annotation.Platform; import io.ebeaninternal.api.SpiEbeanServer; -import java.lang.System.Logger.Level; import java.sql.Types; +import static java.lang.System.Logger.Level.ERROR; + public abstract class BaseTestCase { protected static System.Logger logger = AppLog.getLogger(BaseTestCase.class); @@ -35,7 +36,7 @@ public abstract class BaseTestCase { // First try, if we get the default server. If this fails, all tests will fail. DB.getDefault(); } catch (Throwable e) { - logger.log(Level.ERROR, "Fatal error while getting ebean-server. Exiting...", e); + logger.log(ERROR, "Fatal error while getting ebean-server. Exiting...", e); System.exit(1); } } diff --git a/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java b/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java index a934b84119..72aba98d4c 100644 --- a/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java +++ b/ebean-redis/src/main/java/io/ebean/redis/RedisCache.java @@ -20,9 +20,11 @@ import redis.clients.jedis.resps.ScanResult; import redis.clients.jedis.util.SafeEncoder; -import java.lang.System.Logger.Level; import java.util.*; +import static java.lang.System.Logger.Level.ERROR; +import static java.lang.System.Logger.Level.WARNING; + final class RedisCache implements ServerCache { private static final System.Logger log = AppLog.getLogger(RedisCache.class); @@ -106,17 +108,17 @@ private Object valueDecode(byte[] data) { } return valueEncode.decode(data); } catch (Exception e) { - log.log(Level.ERROR, "Error decoding data, treated as cache miss", e); + log.log(ERROR, "Error decoding data, treated as cache miss", e); return null; } } private void errorOnRead(Exception e) { - log.log(Level.WARNING, "Error when reading redis cache", e); + log.log(WARNING, "Error when reading redis cache", e); } private void errorOnWrite(Exception e) { - log.log(Level.WARNING, "Error when writing redis cache", e); + log.log(WARNING, "Error when writing redis cache", e); } @Override diff --git a/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java b/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java index 4dd991c054..808576ea13 100644 --- a/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java +++ b/ebean-redis/src/main/java/io/ebean/redis/RedisCacheFactory.java @@ -21,7 +21,6 @@ import redis.clients.jedis.util.SafeEncoder; import java.io.*; -import java.lang.System.Logger.Level; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Map; @@ -29,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.*; import static java.util.Arrays.asList; final class RedisCacheFactory implements ServerCacheFactory { @@ -105,7 +105,7 @@ private JedisPool getJedisPool(DatabaseConfig config) { redisConfig = new RedisConfig(); } redisConfig.loadProperties(config.getProperties()); - log.log(Level.INFO, "using l2cache redis host {0}:{1}", redisConfig.getServer(), redisConfig.getPort()); + log.log(INFO, "using l2cache redis host {0}:{1}", redisConfig.getServer(), redisConfig.getPort()); return redisConfig.createPool(); } @@ -160,7 +160,7 @@ private ServerCache createQueryCache(ServerCacheConfig config) { try { RQueryCache cache = queryCaches.get(config.getCacheKey()); if (cache == null) { - logger.log(Level.DEBUG, "create query cache [{0}]", config.getCacheKey()); + logger.log(DEBUG, "create query cache [{0}]", config.getCacheKey()); cache = new RQueryCache(new DefaultServerCacheConfig(config)); cache.periodicTrim(executor); queryCaches.put(config.getCacheKey(), cache); @@ -214,7 +214,7 @@ public void clear() { * Process the invalidation message coming from the cluster. */ private void invalidate() { - queryLogger.log(Level.DEBUG, " CLEAR {0}(*) - cluster invalidate", name); + queryLogger.log(DEBUG, " CLEAR {0}(*) - cluster invalidate", name); super.clear(); } } @@ -233,8 +233,8 @@ public void notify(ServerCacheNotification tableModifications) { msg.append(table).append(","); } String formattedMsg = msg.toString(); - if (tableModLogger.isLoggable(Level.DEBUG)) { - tableModLogger.log(Level.DEBUG, "Publish TableMods - {0}", formattedMsg); + if (tableModLogger.isLoggable(DEBUG)) { + tableModLogger.log(DEBUG, "Publish TableMods - {0}", formattedMsg); } sendTableMod(formattedMsg); } @@ -262,8 +262,8 @@ private void queryCacheInvalidate(String key) { private void processTableNotify(String rawMessage) { long nanos = System.nanoTime(); try { - if (logger.isLoggable(Level.DEBUG)) { - logger.log(Level.DEBUG, "processTableNotify {0}", rawMessage); + if (logger.isLoggable(DEBUG)) { + logger.log(DEBUG, "processTableNotify {0}", rawMessage); } Set tables = new HashSet<>(asList(rawMessage.split(","))); listener.notify(new ServerCacheNotification(tables)); @@ -282,7 +282,7 @@ public void invalidateKeys(String cacheKey, Set keySet) { try { sendMessage(messageInvalidateKeys(cacheKey, keySet)); } catch (IOException e) { - logger.log(Level.ERROR, "failed to transmit invalidateKeys() message", e); + logger.log(ERROR, "failed to transmit invalidateKeys() message", e); } } @@ -291,7 +291,7 @@ public void invalidateKey(String cacheKey, Object id) { try { sendMessage(messageInvalidateKey(cacheKey, id)); } catch (IOException e) { - logger.log(Level.ERROR, "failed to transmit invalidateKeys() message", e); + logger.log(ERROR, "failed to transmit invalidateKeys() message", e); } } @@ -300,7 +300,7 @@ public void invalidateClear(String cacheKey) { try { sendMessage(messageInvalidateClear(cacheKey)); } catch (IOException e) { - logger.log(Level.ERROR, "failed to transmit invalidateKeys() message", e); + logger.log(ERROR, "failed to transmit invalidateKeys() message", e); } } @@ -364,7 +364,7 @@ public void subscribe(Jedis jedis) { @Override public void notifyConnected() { - logger.log(Level.INFO, "Established connection to Redis"); + logger.log(INFO, "Established connection to Redis"); } /** @@ -395,8 +395,8 @@ private void processNearCacheMessage(byte[] message) { } msgType = oi.readInt(); cacheKey = oi.readUTF(); - if (logger.isLoggable(Level.DEBUG)) { - logger.log(Level.DEBUG, "processNearCacheMessage serverId:{0} type:{1} cacheKey:{2}", sourceServerId, msgType, cacheKey); + if (logger.isLoggable(DEBUG)) { + logger.log(DEBUG, "processNearCacheMessage serverId:{0} type:{1} cacheKey:{2}", sourceServerId, msgType, cacheKey); } switch (msgType) { @@ -423,7 +423,7 @@ private void processNearCacheMessage(byte[] message) { } } catch (IOException | ClassNotFoundException e) { - logger.log(Level.ERROR, "failed to decode near cache message [" + SafeEncoder.encode(message) + "] for cache:" + cacheKey, e); + logger.log(ERROR, "failed to decode near cache message [" + SafeEncoder.encode(message) + "] for cache:" + cacheKey, e); if (cacheKey != null) { nearCacheInvalidateClear(cacheKey); } @@ -449,10 +449,10 @@ private void processL2Message(String message) { queryCacheInvalidate(split[2]); break; default: - logger.log(Level.ERROR, "Unknown L2 message type[{0}] on redis channel - message[{1}] ", split[0], message); + logger.log(ERROR, "Unknown L2 message type[{0}] on redis channel - message[{1}] ", split[0], message); } } catch (Exception e) { - logger.log(Level.ERROR, "Error handling L2 message[" + message + "]", e); + logger.log(ERROR, "Error handling L2 message[" + message + "]", e); } } } @@ -495,7 +495,7 @@ private void nearCacheInvalidateClear(String cacheKey) { } private void warnNearCacheNotFound(String cacheKey) { - logger.log(Level.WARNING, "No near cache found for cacheKey [" + cacheKey + "] yet - probably on startup"); + logger.log(WARNING, "No near cache found for cacheKey [" + cacheKey + "] yet - probably on startup"); } } diff --git a/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java b/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java index 1eab914022..374eab001b 100644 --- a/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java +++ b/ebean-redis/src/main/java/io/ebean/redis/topic/DaemonTopicRunner.java @@ -5,10 +5,11 @@ import redis.clients.jedis.JedisPool; import redis.clients.jedis.exceptions.JedisException; -import java.lang.System.Logger.Level; import java.util.Timer; import java.util.TimerTask; +import static java.lang.System.Logger.Level.*; + /** * Subscribe to redis topic listening for changes. *

@@ -49,13 +50,13 @@ private void attemptConnections() { try { subscribe(); } catch (JedisException e) { - log.log(Level.DEBUG, "... redis subscribe connection attempt:{0} failed:{1}", attempts, e.getMessage()); + log.log(DEBUG, "... redis subscribe connection attempt:{0} failed:{1}", attempts, e.getMessage()); try { // wait a little before retrying Thread.sleep(reconnectWaitMillis); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); - log.log(Level.WARNING, "Interrupted redis re-connection wait", e1); + log.log(WARNING, "Interrupted redis re-connection wait", e1); } } } @@ -70,13 +71,13 @@ private void subscribe() { try { daemonTopic.subscribe(jedis); } catch (Exception e) { - log.log(Level.ERROR, "Lost connection to topic, starting re-connection loop", e); + log.log(ERROR, "Lost connection to topic, starting re-connection loop", e); attemptConnections(); } finally { try { jedis.close(); } catch (Exception e) { - log.log(Level.WARNING, "Error closing probably broken Redis connection", e); + log.log(WARNING, "Error closing probably broken Redis connection", e); } } } diff --git a/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java b/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java index 71822c136d..c7887dd759 100644 --- a/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java +++ b/ebean-test/src/main/java/io/ebean/test/CapturingLoggerFactory.java @@ -4,7 +4,8 @@ import io.ebeaninternal.api.SpiLogger; import io.ebeaninternal.api.SpiLoggerFactory; -import java.lang.System.Logger.Level; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.TRACE; /** * Create a logger that captures the SQL and register it for later access in tests. @@ -33,22 +34,22 @@ private static final class LogAdapter implements SpiLogger { @Override public boolean isDebug() { - return logger.isLoggable(Level.DEBUG); + return logger.isLoggable(DEBUG); } @Override public boolean isTrace() { - return logger.isLoggable(Level.TRACE); + return logger.isLoggable(TRACE); } @Override public void debug(String msg) { - logger.log(Level.DEBUG, msg); + logger.log(DEBUG, msg); } @Override public void trace(String msg) { - logger.log(Level.TRACE, msg); + logger.log(TRACE, msg); } } } diff --git a/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java b/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java index 32d7df4244..f9a82cd91c 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java +++ b/ebean-test/src/main/java/io/ebean/test/config/AutoConfigureForTesting.java @@ -8,9 +8,11 @@ import io.ebean.test.config.provider.ProviderAutoConfig; import io.ebean.test.containers.DockerHost; -import java.lang.System.Logger.Level; import java.util.Properties; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.INFO; + /** * Automatically configure ServerConfig for testing purposes. *

@@ -38,7 +40,7 @@ public void preConfigure(DatabaseConfig config) { io.avaje.config.Config.asConfiguration().evalModify(properties); } if (!config.isDefaultServer()) { - log.log(Level.INFO, "skip automatic testing config on non-default server name:{0} register:{1}", config.getName(), config.isRegister()); + log.log(INFO, "skip automatic testing config on non-default server name:{0} register:{1}", config.getName(), config.isRegister()); return; } if (isExtraServer(config, properties)) { @@ -46,7 +48,7 @@ public void preConfigure(DatabaseConfig config) { return; } String testPlatform = properties.getProperty("ebean.test.platform"); - log.log(Level.DEBUG, "automatic testing config - with ebean.test.platform:{0} name:{1} environmentDb:{2}", testPlatform, config.getName(), environmentDb); + log.log(DEBUG, "automatic testing config - with ebean.test.platform:{0} name:{1} environmentDb:{2}", testPlatform, config.getName(), environmentDb); if (RunOnceMarker.isRun()) { setupPlatform(environmentDb, config); } diff --git a/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java b/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java index 115a831078..e85edb93ef 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java +++ b/ebean-test/src/main/java/io/ebean/test/config/platform/Config.java @@ -5,9 +5,10 @@ import io.ebean.datasource.DataSourceConfig; import io.ebean.test.containers.DockerHost; -import java.lang.System.Logger.Level; import java.util.Properties; +import static java.lang.System.Logger.Level.INFO; + /** * Config for a database / datasource with associated DDL mode and Docker configuration. */ @@ -193,8 +194,7 @@ private DataSourceConfig datasourceDefaults(String platform) { ds.setDriver(driverClass); config.setDataSourceConfig(ds); - log.log(Level.INFO, "Using jdbc settings - username:{0} url:{1} driver:{2}", ds.getUsername(), ds.getUrl(), ds.getDriver()); - + log.log(INFO, "Using jdbc settings - username:{0} url:{1} driver:{2}", ds.getUsername(), ds.getUrl(), ds.getDriver()); if (driverClass != null) { try { Class.forName(driverClass); diff --git a/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java b/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java index f378f517cd..8321f0825a 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java +++ b/ebean-test/src/main/java/io/ebean/test/config/platform/PlatformAutoConfig.java @@ -4,11 +4,11 @@ import io.ebean.config.DatabaseConfig; import io.ebean.test.containers.ContainerFactory; -import java.lang.System.Logger.Level; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import static java.lang.System.Logger.Level.*; import static java.util.concurrent.CompletableFuture.allOf; import static java.util.concurrent.CompletableFuture.runAsync; @@ -62,7 +62,7 @@ public void configExtraDataSource() { Config config = new Config(db, platform, databaseName, this.config); platformSetup.setupExtraDbDataSource(config); - log.log(Level.DEBUG, "configured dataSource for extraDb name:{0} url:{1}", db, this.config.getDataSourceConfig().getUrl()); + log.log(DEBUG, "configured dataSource for extraDb name:{0} url:{1}", db, this.config.getDataSourceConfig().getUrl()); } } @@ -92,9 +92,9 @@ private void setupDatabase() { Properties dockerProperties = platformSetup.setup(config); if (!dockerProperties.isEmpty()) { if (isDebug()) { - log.log(Level.INFO, "Docker properties: {0}", dockerProperties); + log.log(INFO, "Docker properties: {0}", dockerProperties); } else { - log.log(Level.DEBUG, "Docker properties: {0}", dockerProperties); + log.log(DEBUG, "Docker properties: {0}", dockerProperties); } // start the docker container with appropriate configuration new ContainerFactory(dockerProperties, config.getDockerPlatform()).startContainers(); @@ -130,7 +130,7 @@ private boolean isKnownPlatform() { } this.platformSetup = KNOWN_PLATFORMS.get(platform); if (platformSetup == null) { - log.log(Level.WARNING, "unknown platform {0} - skipping platform setup", platform); + log.log(WARNING, "unknown platform {0} - skipping platform setup", platform); } return platformSetup != null; } diff --git a/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java b/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java index 48abb54cf7..0be14af3ac 100644 --- a/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java +++ b/ebean-test/src/main/java/io/ebean/test/config/provider/ProviderAutoConfig.java @@ -6,9 +6,11 @@ import io.ebean.config.DatabaseConfig; import io.ebean.config.EncryptKeyManager; -import java.lang.System.Logger.Level; import java.util.Properties; +import static java.lang.System.Logger.Level.DEBUG; +import static java.lang.System.Logger.Level.INFO; + /** * Auto configuration of User and Tenant providers and Encrypt key manager for testing purposes. */ @@ -44,12 +46,12 @@ public void run() { if (keyManager == null) { // Must be 16 Chars for Oracle function String keyVal = properties.getProperty("ebean.test.encryptKey", "simple0123456789"); - log.log(Level.DEBUG, "for testing - using FixedEncryptKeyManager() keyVal:{0}", keyVal); + log.log(DEBUG, "for testing - using FixedEncryptKeyManager() keyVal:{0}", keyVal); config.setEncryptKeyManager(new FixedEncryptKeyManager(keyVal)); } if (providerSetFlag > 0) { - log.log(Level.INFO, msg(providerSetFlag)); + log.log(INFO, msg(providerSetFlag)); } } diff --git a/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java b/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java index 9cab33032e..92df367318 100644 --- a/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java +++ b/platforms/h2/src/main/java/io/ebean/platform/h2/H2HistoryTrigger.java @@ -3,13 +3,14 @@ import io.avaje.applog.AppLog; import org.h2.api.Trigger; -import java.lang.System.Logger.Level; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; +import static java.lang.System.Logger.Level.DEBUG; + /** * H2 database trigger used to populate history tables to support the @History feature. */ @@ -72,7 +73,7 @@ public void init(Connection conn, String schemaName, String triggerName, String insertSql.append(");"); this.insertHistorySql = insertSql.toString(); - log.log(Level.DEBUG, "History table insert sql: {0}", insertHistorySql); + log.log(DEBUG, "History table insert sql: {0}", insertHistorySql); } @Override