diff --git a/documentation/src/main/asciidoc/quickstart/tutorials/osgi/managed-jpa/features.xml b/documentation/src/main/asciidoc/quickstart/tutorials/osgi/managed-jpa/features.xml index c712d512f4..1df06fe5b9 100644 --- a/documentation/src/main/asciidoc/quickstart/tutorials/osgi/managed-jpa/features.xml +++ b/documentation/src/main/asciidoc/quickstart/tutorials/osgi/managed-jpa/features.xml @@ -59,7 +59,6 @@ mvn:com.fasterxml/classmate/0.8.0 mvn:org.apache.logging.log4j/log4j-api/2.0 - mvn:log4j/log4j/1.2.17 mvn:org.jboss.logging/jboss-logging/3.2.1.Final mvn:org.javassist/javassist/3.18.1-GA diff --git a/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-jpa/features.xml b/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-jpa/features.xml index 3252004918..f3f240a282 100644 --- a/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-jpa/features.xml +++ b/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-jpa/features.xml @@ -32,7 +32,6 @@ mvn:com.fasterxml/classmate/0.8.0 mvn:org.apache.logging.log4j/log4j-api/2.0 - mvn:log4j/log4j/1.2.17 mvn:org.jboss.logging/jboss-logging/3.2.1.Final mvn:org.javassist/javassist/3.18.1-GA diff --git a/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-native/features.xml b/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-native/features.xml index 3adcef2c30..cd4d665d40 100644 --- a/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-native/features.xml +++ b/documentation/src/main/asciidoc/quickstart/tutorials/osgi/unmanaged-native/features.xml @@ -40,7 +40,6 @@ mvn:com.fasterxml/classmate/0.8.0 mvn:org.apache.logging.log4j/log4j-api/2.0 - mvn:log4j/log4j/1.2.17 mvn:org.jboss.logging/jboss-logging/3.2.1.Final mvn:org.javassist/javassist/3.18.1-GA diff --git a/documentation/src/test/resources/log4j.properties b/documentation/src/test/resources/log4j.properties deleted file mode 100644 index 49358a1a2d..0000000000 --- a/documentation/src/test/resources/log4j.properties +++ /dev/null @@ -1,56 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate=info -#log4j.logger.org.hibernate=warn - -log4j.logger.org.hibernate.ejb=info -log4j.logger.org.hibernate.ejb.packaging=info -log4j.logger.org.hibernate.reflection=info - -#log4j.logger.org.hibernate.engine.Cascades=warn -#log4j.logger.org.hibernate.hql=warn - -### log just the SQL -log4j.logger.org.hibernate.SQL=debug - -### log JDBC bind parameters ### -log4j.logger.org.hibernate.type=trace -log4j.logger.org.hibernate.type.descriptor.sql=trace -log4j.logger.org.hibernate.id.enhanced.TableGenerator=trace -log4j.logger.org.hibernate.id.IdentifierGeneratorHelper=trace -log4j.logger.org.hibernate.persister.entity.AbstractEntityPersister=trace -log4j.logger.org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl=trace - -### log schema export/update ### -log4j.logger.org.hibernate.tool.hbm2ddl=info - -### log HQL parse trees -#log4j.logger.org.hibernate.hql=warn - -### log cache activity ### -#log4j.logger.org.hibernate.cache=warn - -### log JDBC resource acquisition -#log4j.logger.org.hibernate.jdbc=warn - -### enable the following line if you want to track down connection ### -### leakages when using DriverManagerConnectionProvider ### -#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace - -### When entity copy merge functionality is enabled using: -### hibernate.event.merge.entity_copy_observer=log, the following will -### provide information about merged entity copies. -#log4j.logger.org.hibernate.event.internal.EntityCopyAllowedLoggedObserver=warn - -log4j.logger.org.hibernate.userguide=debug diff --git a/documentation/src/test/resources/log4j2.properties b/documentation/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..bcca35fbe7 --- /dev/null +++ b/documentation/src/test/resources/log4j2.properties @@ -0,0 +1,75 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.hibernate.name=org.hibernate +logger.hibernate.level=info +#logger.hibernate.level=warn + +logger.ejb.name=org.hibernate.ejb +logger.ejb.level=info +logger.ejb-packaging.name=org.hibernate.ejb.packaging +logger.ejb-packaging.level=info +logger.reflection.name=org.hibernate.reflection +logger.reflection.level=info + +logger.cascades.name=org.hibernate.engine.Cascades +#logger.cascades.level=warn + +### log just the SQL +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug + +### log JDBC bind parameters ### +logger.hibernate-type.name=org.hibernate.type +logger.hibernate-type.level=trace +logger.type-sql.name=org.hibernate.type.descriptor.sql +logger.type-sql.level=trace +logger.table-generator.name=org.hibernate.id.enhanced.TableGenerator +logger.table-generator.level=trace +logger.identifier-generator-helper.name=org.hibernate.id.IdentifierGeneratorHelper +logger.identifier-generator-helper.level=trace +logger.abstract-entity-persister.name=org.hibernate.persister.entity.AbstractEntityPersister +logger.abstract-entity-persister.level=trace +logger.entity-reference-initializer-impl.name=org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl +logger.entity-reference-initializer-impl.level=trace + +### log schema export/update ### +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=info + +### log HQL parse trees +logger.hql.name=org.hibernate.hql +#logger.hql.level=warn + +### log cache activity ### +logger.cache.name=org.hibernate.cache +#logger.cache.level=warn + +### log JDBC resource acquisition +logger.hibernate-jdbc.name=org.hibernate.jdbc +#logger.hibernate-jdbc.level=warn + +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +logger.driver-manager-connection-provider.name=org.hibernate.connection.DriverManagerConnectionProvider +#logger.driver-manager-connection-provider.level=trace + +### When entity copy merge functionality is enabled using: +### hibernate.event.merge.entity_copy_observer=log, the following will +### provide information about merged entity copies. +logger.entity-copy-allowed-logged-observer.name=org.hibernate.event.internal.EntityCopyAllowedLoggedObserver +#logger.entity-copy-allowed-logged-observer.level=warn + +logger.userguide.name=org.hibernate.userguide +logger.userguide.level=debug diff --git a/etc/log4j.properties b/etc/log4j.properties deleted file mode 100644 index d0b320610a..0000000000 --- a/etc/log4j.properties +++ /dev/null @@ -1,54 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# - -### direct log messages to stdout ### -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -### direct messages to file hibernate.log ### -#log4j.appender.file=org.apache.log4j.FileAppender -#log4j.appender.file.File=hibernate.log -#log4j.appender.file.layout=org.apache.log4j.PatternLayout -#log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -### set log levels - for more verbose logging change 'info' to 'debug' ### - -log4j.rootLogger=warn, stdout - -#log4j.logger.org.hibernate=info -log4j.logger.org.hibernate=debug - -### log HQL query parser activity -#log4j.logger.org.hibernate.hql.ast.AST=debug - -### log just the SQL -#log4j.logger.org.hibernate.SQL=debug - -### log JDBC bind parameters ### -log4j.logger.org.hibernate.type=info -#log4j.logger.org.hibernate.type=debug - -### log schema export/update ### -log4j.logger.org.hibernate.tool.hbm2ddl=debug - -### log HQL parse trees -#log4j.logger.org.hibernate.hql=debug - -### log cache activity ### -#log4j.logger.org.hibernate.cache=debug - -### log transaction activity -#log4j.logger.org.hibernate.transaction=debug - -### log JDBC resource acquisition -#log4j.logger.org.hibernate.jdbc=debug - -### enable the following line if you want to track down connection ### -### leakages when using DriverManagerConnectionProvider ### -#log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace diff --git a/etc/log4j2.properties b/etc/log4j2.properties new file mode 100644 index 0000000000..e12215cd72 --- /dev/null +++ b/etc/log4j2.properties @@ -0,0 +1,66 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# + +### direct log messages to stdout ### +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +### direct messages to file hibernate.log ### +#appender.file.type=File +#appender.file.name=file +#appender.file.fileName=hibernate.log +#appender.file.layout.type=PatternLayout +#appender.file.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +### set log levels - for more verbose logging change 'info' to 'debug' ### + +rootLogger.level=warn +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.hibernate.name=org.hibernate +#logger.hibernate.level=info +logger.hibernate.level=debug + +### log HQL query parser activity +logger.hql-ast.name=org.hibernate.hql.ast.AST +#logger.hql-ast.level=debug + +### log just the SQL +logger.sql.name=org.hibernate.SQL +#logger.sql.level=debug + +### log JDBC bind parameters ### +logger.hibernate-type.name=org.hibernate.type +logger.hibernate-type.level=info +#logger.hibernate-type.level=debug + +### log schema export/update ### +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=debug + +### log HQL parse trees +logger.hql.name=org.hibernate.hql +#logger.hql.level=debug + +### log cache activity ### +logger.cache.name=org.hibernate.cache +#logger.cache.level=debug + +### log transaction activity +logger.hibernate-transaction.name=org.hibernate.transaction +#logger.hibernate-transaction.level=debug + +### log JDBC resource acquisition +logger.hibernate-jdbc.name=org.hibernate.jdbc +#logger.hibernate-jdbc.level=debug + +### enable the following line if you want to track down connection ### +### leakages when using DriverManagerConnectionProvider ### +logger.driver-manager-connection-provider.name=org.hibernate.connection.DriverManagerConnectionProvider +#logger.driver-manager-connection-provider.level=trace diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index 85d5330adf..582c5078d8 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -71,7 +71,7 @@ dependencies { testCompile( libraries.byteman_install ) testCompile( libraries.byteman_bmunit ) - testRuntime( libraries.log4j ) + testRuntime( libraries.log4j2 ) testRuntime( libraries.javassist ) testRuntime( libraries.byteBuddy ) diff --git a/gradle/libraries.gradle b/gradle/libraries.gradle index a2240e9d9a..a317e76e8a 100644 --- a/gradle/libraries.gradle +++ b/gradle/libraries.gradle @@ -120,7 +120,7 @@ ext { // ~~~~~~~~~~~~~~~~~~~~~~~~~~ testing - log4j: "log4j:log4j:1.2.17", + log4j2: "org.apache.logging.log4j:log4j-core:2.14.1", junit: "junit:junit:${junitVersion}", byteman: "org.jboss.byteman:byteman:${bytemanVersion}", byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}", diff --git a/hibernate-agroal/src/test/resources/log4j.properties b/hibernate-agroal/src/test/resources/log4j.properties deleted file mode 100644 index eb96581a28..0000000000 --- a/hibernate-agroal/src/test/resources/log4j.properties +++ /dev/null @@ -1,60 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n -#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n - -#log4j.appender.stdout-mdc=org.apache.log4j.ConsoleAppender -#log4j.appender.stdout-mdc.Target=System.out -#log4j.appender.stdout-mdc.layout=org.apache.log4j.PatternLayout -#log4j.appender.stdout-mdc.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n - -log4j.appender.unclosedSessionFactoryFile=org.apache.log4j.FileAppender -log4j.appender.unclosedSessionFactoryFile.append=true -log4j.appender.unclosedSessionFactoryFile.file=target/tmp/log/UnclosedSessionFactoryWarnings.log -log4j.appender.unclosedSessionFactoryFile.layout=org.apache.log4j.PatternLayout -log4j.appender.unclosedSessionFactoryFile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -#log4j.logger.org.hibernate.loader.plan=trace, stdout-mdc -#log4j.additivity.org.hibernate.loader.plan=false -#log4j.logger.org.hibernate.persister.walking=trace, stdout-mdc -#log4j.additivity.org.hibernate.persister.walking=false - -log4j.logger.org.hibernate.tool.hbm2ddl=trace -log4j.logger.org.hibernate.testing.cache=debug - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug - -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace - -log4j.logger.org.hibernate.hql.internal.ast=debug - -log4j.logger.org.hibernate.sql.ordering.antlr=debug - -log4j.logger.org.hibernate.loader.plan2.build.internal.LoadPlanImpl=debug -log4j.logger.org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter=debug -log4j.logger.org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails=debug - -log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=info - -log4j.logger.org.hibernate.boot.model.source.internal.hbm.ModelBinder=debug -log4j.logger.org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry=debug - - -### When entity copy merge functionality is enabled using: -### hibernate.event.merge.entity_copy_observer=log, the following will -### provide information about merged entity copies. -### log4j.logger.org.hibernate.event.internal.EntityCopyAllowedLoggedObserver=debug - -log4j.logger.org.hibernate.testing.junit4.TestClassMetadata=info, unclosedSessionFactoryFile -log4j.logger.org.hibernate.boot.model.process.internal.ScanningCoordinator=debug diff --git a/hibernate-agroal/src/test/resources/log4j2.properties b/hibernate-agroal/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..c9a2a7cad7 --- /dev/null +++ b/hibernate-agroal/src/test/resources/log4j2.properties @@ -0,0 +1,83 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n + +appender.stdout-mdc.type=Console +appender.stdout-mdc.name=stdout-mdc +appender.stdout-mdc.layout.type=PatternLayout +appender.stdout-mdc.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n + +appender.unclosedSessionFactoryFile.type=File +appender.unclosedSessionFactoryFile.name=unclosedSessionFactoryFile +appender.unclosedSessionFactoryFile.append=true +appender.unclosedSessionFactoryFile.fileName=target/tmp/log/UnclosedSessionFactoryWarnings.log +appender.unclosedSessionFactoryFile.layout.type=PatternLayout +appender.unclosedSessionFactoryFile.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.loader-plan.name=org.hibernate.loader.plan +#logger.loader-plan.level=trace +#logger.loader-plan.appenderRef.stdout-mdc.ref=stdout-mdc +#logger.loader-plan.additivity=false +logger.persister-walking.name=org.hibernate.persister.walking +#logger.persister-walking.level=trace +#logger.persister-walking.appenderRef.stdout-mdc.ref=stdout-mdc +#logger.persister-walking.additivity=false + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=trace +logger.testing-cache.name=org.hibernate.testing.cache +logger.testing-cache.level=debug + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug + +logger.type-basic-binder.name=org.hibernate.type.descriptor.sql.BasicBinder +logger.type-basic-binder.level=trace +logger.type-basic-extractor.name=org.hibernate.type.descriptor.sql.BasicExtractor +logger.type-basic-extractor.level=trace + +logger.hql-internal-ast.name=org.hibernate.hql.internal.ast +logger.hql-internal-ast.level=debug + +logger.sql-ordering-antlr.name=org.hibernate.sql.ordering.antlr +logger.sql-ordering-antlr.level=debug + +logger.load-plan-impl.name=org.hibernate.loader.plan2.build.internal.LoadPlanImpl +logger.load-plan-impl.level=debug +logger.load-plan-tree-printer.name=org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter +logger.load-plan-tree-printer.level=debug +logger.entity-load-query-details.name=org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails +logger.entity-load-query-details.level=debug + +logger.statistical-logging-session-event-listener.name=org.hibernate.engine.internal.StatisticalLoggingSessionEventListener +logger.statistical-logging-session-event-listener.level=info + +logger.model-binder.name=org.hibernate.boot.model.source.internal.hbm.ModelBinder +logger.model-binder.level=debug +logger.java-type-descriptor-registry.name=org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry +logger.java-type-descriptor-registry.level=debug + + +logger.merged-entity-copies.name=org.hibernate.event.internal.EntityCopyAllowedLoggedObserver +### When entity copy merge functionality is enabled using: +### hibernate.event.merge.entity_copy_observer=log, the following will +### provide information about merged entity copies. +#logger.merged-entity-copies.level=debug + +logger.test-class-metadata.name=org.hibernate.testing.junit4.TestClassMetadata +logger.test-class-metadata.level=info +logger.test-class-metadata.appenderRef.unclosedSessionFactoryFile.ref=unclosedSessionFactoryFile +logger.scanning-coordinator.name=org.hibernate.boot.model.process.internal.ScanningCoordinator +logger.scanning-coordinator.level=debug diff --git a/hibernate-c3p0/src/test/resources/log4j.properties b/hibernate-c3p0/src/test/resources/log4j.properties deleted file mode 100644 index 86c5d9be55..0000000000 --- a/hibernate-c3p0/src/test/resources/log4j.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.tool.hbm2ddl=debug -log4j.logger.org.hibernate.testing.cache=debug diff --git a/hibernate-c3p0/src/test/resources/log4j2.properties b/hibernate-c3p0/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..d4da0b21a5 --- /dev/null +++ b/hibernate-c3p0/src/test/resources/log4j2.properties @@ -0,0 +1,19 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=debug +logger.testing-cache.name=org.hibernate.testing.cache +logger.testing-cache.level=debug diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java index a619e6a9e1..d4d04b23e9 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/JpaProxyComplianceWithDebug.java @@ -25,14 +25,17 @@ import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; import javax.persistence.Table; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; import org.hibernate.cfg.AvailableSettings; import org.hibernate.testing.TestForIssue; import org.junit.Before; import org.junit.Test; +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.LoggerConfig; + @TestForIssue(jiraKey = "HHH-13244") public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTestCase { @@ -82,17 +85,19 @@ public class JpaProxyComplianceWithDebug extends BaseEntityManagerFunctionalTest @Test @TestForIssue(jiraKey = "HHH-13244") public void testJpaComplianceProxyWithDebug() { + LoggerContext context = (LoggerContext) LogManager.getContext( false ); + Configuration configuration = context.getConfiguration(); //This could be replaced with setting the root logger level, or the "org.hibernate" logger to debug. //These are simply the narrowest log settings that trigger the bug - Logger entityLogger = LogManager.getLogger("org.hibernate.internal.util.EntityPrinter"); - Logger listenerLogger = LogManager.getLogger("org.hibernate.event.internal.AbstractFlushingEventListener"); + LoggerConfig entityLogger = configuration.getLoggerConfig( "org.hibernate.internal.util.EntityPrinter"); + LoggerConfig listenerLogger = configuration.getLoggerConfig("org.hibernate.event.internal.AbstractFlushingEventListener"); Level oldEntityLogLevel = entityLogger.getLevel(); Level oldListenerLogLevel = listenerLogger.getLevel(); - entityLogger.setLevel((Level) Level.DEBUG); - listenerLogger.setLevel((Level) Level.DEBUG); + entityLogger.setLevel(Level.DEBUG); + listenerLogger.setLevel(Level.DEBUG); try { doInJPA(this::entityManagerFactory, entityManager -> { entityManager.find(MvnoBillingAgreement.class, 1); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/ImmutableNaturalKeyLookupTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/ImmutableNaturalKeyLookupTest.java index 58ea046c3e..1ce438654c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/ImmutableNaturalKeyLookupTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/naturalid/ImmutableNaturalKeyLookupTest.java @@ -132,8 +132,10 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase { newTx = s.beginTransaction(); // please enable - // log4j.logger.org.hibernate.cache.StandardQueryCache=DEBUG - // log4j.logger.org.hibernate.cache.UpdateTimestampsCache=DEBUG + // logger.standard-query-cache.name=org.hibernate.cache.StandardQueryCache + // logger.standard-query-cache.level=debug + // logger.update-timestamps-cache.name=org.hibernate.cache.UpdateTimestampsCache + // logger.update-timestamps-cache.level=debug // to see that isUpToDate is called where not appropriated Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); @@ -228,8 +230,10 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase { newTx = s.beginTransaction(); // please enable - // log4j.logger.org.hibernate.cache.StandardQueryCache=DEBUG - // log4j.logger.org.hibernate.cache.UpdateTimestampsCache=DEBUG + // logger.standard-query-cache.name=org.hibernate.cache.StandardQueryCache + // logger.standard-query-cache.level=debug + // logger.update-timestamps-cache.name=org.hibernate.cache.UpdateTimestampsCache + // logger.update-timestamps-cache.level=debug // to see that isUpToDate is called where not appropriated Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); @@ -274,8 +278,10 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase { newTx = s.beginTransaction(); // please enable - // log4j.logger.org.hibernate.cache.StandardQueryCache=DEBUG - // log4j.logger.org.hibernate.cache.UpdateTimestampsCache=DEBUG + // logger.standard-query-cache.name=org.hibernate.cache.StandardQueryCache + // logger.standard-query-cache.level=debug + // logger.update-timestamps-cache.name=org.hibernate.cache.UpdateTimestampsCache + // logger.update-timestamps-cache.level=debug // to see that isUpToDate is called where not appropriated Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java b/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java index faab782487..522c679837 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/joinedsubclassbatch/JoinedSubclassBatchingTest.java @@ -32,10 +32,6 @@ import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; - import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; /** diff --git a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ImplicitCompositeKeyJoinTest.java b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ImplicitCompositeKeyJoinTest.java index 4f59647beb..1771db5726 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ImplicitCompositeKeyJoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/schemaupdate/ImplicitCompositeKeyJoinTest.java @@ -24,7 +24,7 @@ import org.hibernate.tool.schema.internal.SchemaCreatorImpl; import org.hibernate.testing.TestForIssue; import org.junit.Test; -import org.apache.log4j.Logger; +import org.jboss.logging.Logger; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; diff --git a/hibernate-core/src/test/resources/log4j.properties b/hibernate-core/src/test/resources/log4j.properties deleted file mode 100644 index 498bbeddd6..0000000000 --- a/hibernate-core/src/test/resources/log4j.properties +++ /dev/null @@ -1,62 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.appender.unclosedSessionFactoryFile=org.apache.log4j.FileAppender -log4j.appender.unclosedSessionFactoryFile.append=true -log4j.appender.unclosedSessionFactoryFile.file=target/tmp/log/UnclosedSessionFactoryWarnings.log -log4j.appender.unclosedSessionFactoryFile.layout=org.apache.log4j.PatternLayout -log4j.appender.unclosedSessionFactoryFile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.orm.graph=debug - -#log4j.logger.org.hibernate.orm.tooling.schema.script=trace -#log4j.logger.org.hibernate.orm.tooling.schema.script.graph=trace - - -log4j.logger.org.hibernate.tool.hbm2ddl=trace -log4j.logger.org.hibernate.testing.cache=debug - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug - -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace - -log4j.logger.org.hibernate.hql.internal.ast=debug - -log4j.logger.org.hibernate.sql.ordering.antlr=debug - -log4j.logger.org.hibernate.loader.plan2.build.internal.LoadPlanImpl=debug -log4j.logger.org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter=debug -log4j.logger.org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails=debug - -log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=info - -log4j.logger.org.hibernate.boot.model.source.internal.hbm.ModelBinder=debug -log4j.logger.org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry=debug - -#log4j.logger.org.hibernate.action.internal.EntityAction=debug -#log4j.logger.org.hibernate.engine.internal.Cascade=trace - - -### When entity copy merge functionality is enabled using: -### hibernate.event.merge.entity_copy_observer=log, the following will -### provide information about merged entity copies. -### log4j.logger.org.hibernate.event.internal.EntityCopyAllowedLoggedObserver=debug - -log4j.logger.org.hibernate.testing.junit4.TestClassMetadata=info, unclosedSessionFactoryFile -log4j.logger.org.hibernate.boot.model.process.internal.ScanningCoordinator=debug -log4j.logger.org.hibernate.collection.internal.AbstractPersistentCollection=debug - -log4j.logger.org.hibernate.cache trace -log4j.logger.org.hibernate.stat trace \ No newline at end of file diff --git a/hibernate-core/src/test/resources/log4j2.properties b/hibernate-core/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..f21f8c8748 --- /dev/null +++ b/hibernate-core/src/test/resources/log4j2.properties @@ -0,0 +1,89 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +appender.unclosedSessionFactoryFile.type=File +appender.unclosedSessionFactoryFile.name=unclosedSessionFactoryFile +appender.unclosedSessionFactoryFile.append=true +appender.unclosedSessionFactoryFile.fileName=target/tmp/log/UnclosedSessionFactoryWarnings.log +appender.unclosedSessionFactoryFile.layout.type=PatternLayout +appender.unclosedSessionFactoryFile.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.graph.name=org.hibernate.orm.graph +logger.graph.level=debug + +logger.tooling-schema-script.name=org.hibernate.orm.tooling.schema.script +#logger.tooling-schema-script.level=trace +logger.tooling-schema-script-graph.name=org.hibernate.orm.tooling.schema.script.graph +#logger.tooling-schema-script-graph.level=trace + + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=trace +logger.testing-cache.name=org.hibernate.testing.cache +logger.testing-cache.level=debug + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug + +logger.type-basic-binder.name=org.hibernate.type.descriptor.sql.BasicBinder +logger.type-basic-binder.level=trace +logger.type-basic-extractor.name=org.hibernate.type.descriptor.sql.BasicExtractor +logger.type-basic-extractor.level=trace + +logger.hql-internal-ast.name=org.hibernate.hql.internal.ast +logger.hql-internal-ast.level=debug + +logger.sql-ordering-antlr.name=org.hibernate.sql.ordering.antlr +logger.sql-ordering-antlr.level=debug + +logger.load-plan-impl.name=org.hibernate.loader.plan2.build.internal.LoadPlanImpl +logger.load-plan-impl.level=debug +logger.load-plan-tree-printer.name=org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter +logger.load-plan-tree-printer.level=debug +logger.entity-load-query-details.name=org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails +logger.entity-load-query-details.level=debug + +logger.statistical-logging-session-event-listener.name=org.hibernate.engine.internal.StatisticalLoggingSessionEventListener +logger.statistical-logging-session-event-listener.level=info + +logger.model-binder.name=org.hibernate.boot.model.source.internal.hbm.ModelBinder +logger.model-binder.level=debug +logger.java-type-descriptor-registry.name=org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry +logger.java-type-descriptor-registry.level=debug + +logger.entity-action.name=org.hibernate.action.internal.EntityAction +#logger.entity-action.level=debug +logger.cascade.name=org.hibernate.engine.internal.Cascade +#logger.cascade.level=trace + + +logger.merged-entity-copies.name=org.hibernate.event.internal.EntityCopyAllowedLoggedObserver +### When entity copy merge functionality is enabled using: +### hibernate.event.merge.entity_copy_observer=log, the following will +### provide information about merged entity copies. +#logger.merged-entity-copies.level=debug + +logger.test-class-metadata.name=org.hibernate.testing.junit4.TestClassMetadata +logger.test-class-metadata.level=info +logger.test-class-metadata.appenderRef.unclosedSessionFactoryFile.ref=unclosedSessionFactoryFile +logger.scanning-coordinator.name=org.hibernate.boot.model.process.internal.ScanningCoordinator +logger.scanning-coordinator.level=debug +logger.abstract-persistent-collection.name=org.hibernate.collection.internal.AbstractPersistentCollection +logger.abstract-persistent-collection.level=debug + +logger.cache.name=org.hibernate.cache +logger.cache.level=trace +logger.stat.name=org.hibernate.stat +logger.stat.level=trace \ No newline at end of file diff --git a/hibernate-ehcache/src/test/resources/log4j.properties b/hibernate-ehcache/src/test/resources/log4j.properties deleted file mode 100644 index cc2eb6d040..0000000000 --- a/hibernate-ehcache/src/test/resources/log4j.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later -# See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.test=info - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug \ No newline at end of file diff --git a/hibernate-ehcache/src/test/resources/log4j2.properties b/hibernate-ehcache/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..636a2e63b8 --- /dev/null +++ b/hibernate-ehcache/src/test/resources/log4j2.properties @@ -0,0 +1,20 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later +# See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.test.name=org.hibernate.test +logger.test.level=info + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug \ No newline at end of file diff --git a/hibernate-envers/src/test/resources/log4j.properties b/hibernate-envers/src/test/resources/log4j.properties deleted file mode 100644 index e516e460d1..0000000000 --- a/hibernate-envers/src/test/resources/log4j.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.test=info - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug -log4j.logger.org.hibernate.tool.hbm2ddl=debug - -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace - -log4j.logger.org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl=trace \ No newline at end of file diff --git a/hibernate-envers/src/test/resources/log4j2.properties b/hibernate-envers/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..77dcbca11f --- /dev/null +++ b/hibernate-envers/src/test/resources/log4j2.properties @@ -0,0 +1,30 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.test.name=org.hibernate.test +logger.test.level=info + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=debug + +logger.type-basic-binder.name=org.hibernate.type.descriptor.sql.BasicBinder +logger.type-basic-binder.level=trace +logger.type-basic-extractor.name=org.hibernate.type.descriptor.sql.BasicExtractor +logger.type-basic-extractor.level=trace + +logger.additional-jaxb-mapping-producer-impl.name=org.hibernate.envers.boot.internal.AdditionalJaxbMappingProducerImpl +logger.additional-jaxb-mapping-producer-impl.level=trace \ No newline at end of file diff --git a/hibernate-hikaricp/src/test/resources/log4j.properties b/hibernate-hikaricp/src/test/resources/log4j.properties deleted file mode 100644 index eb96581a28..0000000000 --- a/hibernate-hikaricp/src/test/resources/log4j.properties +++ /dev/null @@ -1,60 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n -#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n - -#log4j.appender.stdout-mdc=org.apache.log4j.ConsoleAppender -#log4j.appender.stdout-mdc.Target=System.out -#log4j.appender.stdout-mdc.layout=org.apache.log4j.PatternLayout -#log4j.appender.stdout-mdc.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n - -log4j.appender.unclosedSessionFactoryFile=org.apache.log4j.FileAppender -log4j.appender.unclosedSessionFactoryFile.append=true -log4j.appender.unclosedSessionFactoryFile.file=target/tmp/log/UnclosedSessionFactoryWarnings.log -log4j.appender.unclosedSessionFactoryFile.layout=org.apache.log4j.PatternLayout -log4j.appender.unclosedSessionFactoryFile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -#log4j.logger.org.hibernate.loader.plan=trace, stdout-mdc -#log4j.additivity.org.hibernate.loader.plan=false -#log4j.logger.org.hibernate.persister.walking=trace, stdout-mdc -#log4j.additivity.org.hibernate.persister.walking=false - -log4j.logger.org.hibernate.tool.hbm2ddl=trace -log4j.logger.org.hibernate.testing.cache=debug - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug - -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace - -log4j.logger.org.hibernate.hql.internal.ast=debug - -log4j.logger.org.hibernate.sql.ordering.antlr=debug - -log4j.logger.org.hibernate.loader.plan2.build.internal.LoadPlanImpl=debug -log4j.logger.org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter=debug -log4j.logger.org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails=debug - -log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=info - -log4j.logger.org.hibernate.boot.model.source.internal.hbm.ModelBinder=debug -log4j.logger.org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry=debug - - -### When entity copy merge functionality is enabled using: -### hibernate.event.merge.entity_copy_observer=log, the following will -### provide information about merged entity copies. -### log4j.logger.org.hibernate.event.internal.EntityCopyAllowedLoggedObserver=debug - -log4j.logger.org.hibernate.testing.junit4.TestClassMetadata=info, unclosedSessionFactoryFile -log4j.logger.org.hibernate.boot.model.process.internal.ScanningCoordinator=debug diff --git a/hibernate-hikaricp/src/test/resources/log4j2.properties b/hibernate-hikaricp/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..1563522cc7 --- /dev/null +++ b/hibernate-hikaricp/src/test/resources/log4j2.properties @@ -0,0 +1,83 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n + +appender.stdout-mdc.type=Console +appender.stdout-mdc.name=stdout-mdc +appender.stdout-mdc.layout.type=PatternLayout +appender.stdout-mdc.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n + +appender.unclosedSessionFactoryFile.type=File +appender.unclosedSessionFactoryFile.name=unclosedSessionFactoryFile +appender.unclosedSessionFactoryFile.append=true +appender.unclosedSessionFactoryFile.fileName=target/tmp/log/UnclosedSessionFactoryWarnings.log +appender.unclosedSessionFactoryFile.layout.type=PatternLayout +appender.unclosedSessionFactoryFile.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.loader-plan.name=org.hibernate.loader.plan +#logger.loader-plan.level=trace +#logger.loader-plan.appenderRef.stdout-mdc.ref=stdout-mdc +#logger.loader-plan.additivity=false +logger.persister-walking.name=org.hibernate.persister.walking +#logger.persister-walking.level=trace +#logger.persister-walking.appenderRef.stdout-mdc.ref=stdout-mdc +#logger.persister-walking.additivity=false + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=trace +logger.testing-cache.name=org.hibernate.testing.cache +logger.testing-cache.level=debug + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug + +logger.type-basic-binder.name=org.hibernate.type.descriptor.sql.BasicBinder +logger.type-basic-binder.level=trace +logger.type-basic-extractor.name=org.hibernate.type.descriptor.sql.BasicExtractor +logger.type-basic-extractor.level=trace + +logger.hql-internal-ast.name=org.hibernate.hql.internal.ast +logger.hql-internal-ast.level=debug + +logger.sql-ordering-antlr.name=org.hibernate.sql.ordering.antlr +logger.sql-ordering-antlr.level=debug + +logger.load-plan-impl.name=org.hibernate.loader.plan2.build.internal.LoadPlanImpl +logger.load-plan-impl.level=debug +logger.load-plan-tree-printer.name=org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter +logger.load-plan-tree-printer.level=debug +logger.entity-load-query-details.name=org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails +logger.entity-load-query-details.level=debug + +logger.statistical-logging-session-event-listener.name=org.hibernate.engine.internal.StatisticalLoggingSessionEventListener +logger.statistical-logging-session-event-listener.level=info + +logger.model-binder.name=org.hibernate.boot.model.source.internal.hbm.ModelBinder +logger.model-binder.level=debug +logger.java-type-descriptor-registry.name=org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry +logger.java-type-descriptor-registry.level=debug + + +logger.merged-entity-copies.name=org.hibernate.event.internal.EntityCopyAllowedLoggedObserver +### When entity copy merge functionality is enabled using: +### hibernate.event.merge.entity_copy_observer=log, the following will +### provide information about merged entity copies. +#logger.merged-entity-copies.level=debug + +logger.test-class-metadata.name=org.hibernate.testing.junit4.TestClassMetadata +logger.test-class-metadata.level=info +logger.test-class-metadata.appenderRef.unclosedSessionFactoryFile.ref=unclosedSessionFactoryFile +logger.scanning-coordinator.name=org.hibernate.boot.model.process.internal.ScanningCoordinator +logger.scanning-coordinator.level=debug diff --git a/hibernate-integrationtest-java-modules/src/test/resources/logging.properties b/hibernate-integrationtest-java-modules/src/test/resources/logging.properties index f96639aaf0..545fb493ca 100644 --- a/hibernate-integrationtest-java-modules/src/test/resources/logging.properties +++ b/hibernate-integrationtest-java-modules/src/test/resources/logging.properties @@ -5,19 +5,19 @@ # See the lgpl.txt file in the root directory or . # -# Root logger option -log4j.rootLogger=DEBUG, file - -# Direct log messages to a log file -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=target/test.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n -log4j.appender.file.Threshold=DEBUG - # Direct log messages to console -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.Target=System.out -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n -log4j.appender.console.Threshold=WARN \ No newline at end of file +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n + +# Direct log messages to a log file +appender.file.type=File +appender.file.name=file +appender.file.fileName=target/test.log +appender.file.layout.type=PatternLayout +appender.file.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n + +# Root logger option +rootLogger.level=debug +rootLogger.appenderRef.file.ref=file diff --git a/hibernate-jcache/src/test/resources/log4j.properties b/hibernate-jcache/src/test/resources/log4j.properties deleted file mode 100644 index f29002cc37..0000000000 --- a/hibernate-jcache/src/test/resources/log4j.properties +++ /dev/null @@ -1,17 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.test=info - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug \ No newline at end of file diff --git a/hibernate-jcache/src/test/resources/log4j2.properties b/hibernate-jcache/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..a348845e89 --- /dev/null +++ b/hibernate-jcache/src/test/resources/log4j2.properties @@ -0,0 +1,20 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.test.name=org.hibernate.test +logger.test.level=info + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug \ No newline at end of file diff --git a/hibernate-micrometer/src/test/resources/log4j.properties b/hibernate-micrometer/src/test/resources/log4j.properties deleted file mode 100644 index 4567cb1105..0000000000 --- a/hibernate-micrometer/src/test/resources/log4j.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.stat=trace - -log4j.logger.org.hibernate.tool.hbm2ddl=trace -log4j.logger.org.hibernate.SQL=debug -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace \ No newline at end of file diff --git a/hibernate-micrometer/src/test/resources/log4j2.properties b/hibernate-micrometer/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..15a8605c8b --- /dev/null +++ b/hibernate-micrometer/src/test/resources/log4j2.properties @@ -0,0 +1,25 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.stat.name=org.hibernate.stat +logger.stat.level=trace + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=trace +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug +logger.type-basic-binder.name=org.hibernate.type.descriptor.sql.BasicBinder +logger.type-basic-binder.level=trace +logger.type-basic-extractor.name=org.hibernate.type.descriptor.sql.BasicExtractor +logger.type-basic-extractor.level=trace \ No newline at end of file diff --git a/hibernate-osgi/src/test/resources/logging.properties b/hibernate-osgi/src/test/resources/logging.properties index f96639aaf0..545fb493ca 100644 --- a/hibernate-osgi/src/test/resources/logging.properties +++ b/hibernate-osgi/src/test/resources/logging.properties @@ -5,19 +5,19 @@ # See the lgpl.txt file in the root directory or . # -# Root logger option -log4j.rootLogger=DEBUG, file - -# Direct log messages to a log file -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=target/test.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n -log4j.appender.file.Threshold=DEBUG - # Direct log messages to console -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.Target=System.out -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n -log4j.appender.console.Threshold=WARN \ No newline at end of file +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n + +# Direct log messages to a log file +appender.file.type=File +appender.file.name=file +appender.file.fileName=target/test.log +appender.file.layout.type=PatternLayout +appender.file.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n + +# Root logger option +rootLogger.level=debug +rootLogger.appenderRef.file.ref=file diff --git a/hibernate-proxool/src/test/resources/log4j.properties b/hibernate-proxool/src/test/resources/log4j.properties deleted file mode 100644 index 86c5d9be55..0000000000 --- a/hibernate-proxool/src/test/resources/log4j.properties +++ /dev/null @@ -1,16 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - - -log4j.rootLogger=info, stdout - -log4j.logger.org.hibernate.tool.hbm2ddl=debug -log4j.logger.org.hibernate.testing.cache=debug diff --git a/hibernate-proxool/src/test/resources/log4j2.properties b/hibernate-proxool/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..d4da0b21a5 --- /dev/null +++ b/hibernate-proxool/src/test/resources/log4j2.properties @@ -0,0 +1,19 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=debug +logger.testing-cache.name=org.hibernate.testing.cache +logger.testing-cache.level=debug diff --git a/hibernate-spatial/src/test/resources/log4j.properties b/hibernate-spatial/src/test/resources/log4j.properties deleted file mode 100644 index 5156e0d55e..0000000000 --- a/hibernate-spatial/src/test/resources/log4j.properties +++ /dev/null @@ -1,13 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n -log4j.rootLogger=info, stdout -log4j.logger.org.hibernate.SQL=DEBUG -log4j.logger.org.hibernate.spatial=debug diff --git a/hibernate-spatial/src/test/resources/log4j2.properties b/hibernate-spatial/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..6b2e5ea0a1 --- /dev/null +++ b/hibernate-spatial/src/test/resources/log4j2.properties @@ -0,0 +1,16 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT +logger.sql.name=org.hibernate.SQL +logger.sql.level=DEBUG +logger.spatial.name=org.hibernate.spatial +logger.spatial.level=debug diff --git a/hibernate-testing-jakarta/hibernate-testing-jakarta.gradle b/hibernate-testing-jakarta/hibernate-testing-jakarta.gradle index 716f96c9b0..e734d0acbd 100644 --- a/hibernate-testing-jakarta/hibernate-testing-jakarta.gradle +++ b/hibernate-testing-jakarta/hibernate-testing-jakarta.gradle @@ -21,7 +21,7 @@ dependencies { compile( libraries.byteman_install ) compile( libraries.byteman_bmunit ) compile( libraries.xapool ) - compile( libraries.log4j ) + compile( libraries.log4j2 ) compile( libraries.jboss_tx_spi_jakarta ) { transitive=false; } diff --git a/hibernate-testing/hibernate-testing.gradle b/hibernate-testing/hibernate-testing.gradle index abd8e3a5de..0f39d04069 100644 --- a/hibernate-testing/hibernate-testing.gradle +++ b/hibernate-testing/hibernate-testing.gradle @@ -18,7 +18,7 @@ dependencies { compile( libraries.byteman_install ) compile( libraries.byteman_bmunit ) compile( libraries.xapool ) - compile( libraries.log4j ) + compile( libraries.log4j2 ) compile( libraries.jboss_tx_spi ) { transitive=false; } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/logger/Log4DelegatingLogger.java b/hibernate-testing/src/main/java/org/hibernate/testing/logger/Log4DelegatingLogger.java deleted file mode 100644 index b6f14dd597..0000000000 --- a/hibernate-testing/src/main/java/org/hibernate/testing/logger/Log4DelegatingLogger.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.testing.logger; - -import java.text.MessageFormat; -import java.util.LinkedList; -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.jboss.logging.Logger; - -/** - * A {@code Logger} implementation which delegates to Log4J but makes it possible - * to test for events being logged (not logged). - * - * @author Sanne Grinovero (C) 2015 Red Hat Inc. - */ -public final class Log4DelegatingLogger extends Logger { - - private final org.apache.log4j.Logger logger; - - // Synchronize access on the field - private final List enabledListeners = new LinkedList(); - private final AtomicBoolean interceptEnabled = new AtomicBoolean( false ); - - Log4DelegatingLogger(final String name) { - super( name ); - logger = org.apache.log4j.Logger.getLogger( name ); - } - - void registerListener(LogListener newListener) { - synchronized ( enabledListeners ) { - if ( newListener != null ) { - enabledListeners.add( newListener ); - interceptEnabled.set( true ); - } - } - } - - void clearAllListeners() { - synchronized ( enabledListeners ) { - enabledListeners.clear(); - interceptEnabled.set( false ); - } - } - - public boolean isEnabled(final Level level) { - final org.apache.log4j.Level l = translate( level ); - return logger.isEnabledFor( l ) && l.isGreaterOrEqual( logger.getEffectiveLevel() ); - } - - protected void doLog(final Level level, final String loggerClassName, final Object message, final Object[] parameters, final Throwable thrown) { - final org.apache.log4j.Level translatedLevel = translate( level ); - if ( interceptEnabled.get() ) { - intercept( level, parameters == null || parameters.length == 0 ? String.valueOf( message ) : MessageFormat.format( String.valueOf( message ), parameters ), thrown ); - } - if ( !logger.isEnabledFor( translatedLevel ) ) { - return; - } - try { - logger.log( - loggerClassName, - translatedLevel, - parameters == null || parameters.length == 0 - ? String.valueOf( message ) - : MessageFormat.format(String.valueOf( message ), parameters ), - thrown - ); - } - catch (Throwable ignored) { - } - } - - private void intercept(Level level, String renderedMessage, Throwable thrown) { - synchronized ( enabledListeners ) { - for ( LogListener listener : enabledListeners ) { - listener.loggedEvent( level, renderedMessage, thrown ); - } - } - } - - protected void doLogf(final Level level, final String loggerClassName, final String format, final Object[] parameters, final Throwable thrown) { - final org.apache.log4j.Level translatedLevel = translate( level ); - if ( interceptEnabled.get() ) { - intercept( level, parameters == null ? format : String.format( format, parameters ), thrown ); - } - if ( !logger.isEnabledFor( translatedLevel ) ) { - return; - } - try { - logger.log( - loggerClassName, - translatedLevel, - parameters == null ? format : String.format( format, parameters ), - thrown - ); - } - catch (Throwable ignored) { - } - } - - private static org.apache.log4j.Level translate(final Level level) { - if ( level == null ) { - return org.apache.log4j.Level.ALL; - } - - switch ( level ) { - case FATAL: - return org.apache.log4j.Level.FATAL; - case ERROR: - return org.apache.log4j.Level.ERROR; - case WARN: - return org.apache.log4j.Level.WARN; - case INFO: - return org.apache.log4j.Level.INFO; - case DEBUG: - return org.apache.log4j.Level.DEBUG; - case TRACE: - return org.apache.log4j.Level.TRACE; - } - - return org.apache.log4j.Level.ALL; - } - -} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/logger/Log4J2DelegatingLogger.java b/hibernate-testing/src/main/java/org/hibernate/testing/logger/Log4J2DelegatingLogger.java new file mode 100644 index 0000000000..7341e5d3a2 --- /dev/null +++ b/hibernate-testing/src/main/java/org/hibernate/testing/logger/Log4J2DelegatingLogger.java @@ -0,0 +1,160 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.testing.logger; + +import java.text.MessageFormat; +import java.util.LinkedList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.jboss.logging.Logger; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.LoggingException; +import org.apache.logging.log4j.message.MessageFormatMessageFactory; +import org.apache.logging.log4j.message.StringFormattedMessage; +import org.apache.logging.log4j.spi.AbstractLogger; + +/** + * A {@code Logger} implementation which delegates to Log4J2 but makes it possible + * to test for events being logged (not logged). + * + * @author Sanne Grinovero (C) 2015 Red Hat Inc. + */ +public final class Log4J2DelegatingLogger extends Logger { + + private final AbstractLogger logger; + private final MessageFormatMessageFactory messageFactory; + + // Synchronize access on the field + private final List enabledListeners = new LinkedList<>(); + private final AtomicBoolean interceptEnabled = new AtomicBoolean( false ); + + Log4J2DelegatingLogger(final String name) { + super( name ); + org.apache.logging.log4j.Logger logger = LogManager.getLogger( name ); + if ( !( logger instanceof AbstractLogger ) ) { + throw new LoggingException( "The logger for [" + name + "] does not extend AbstractLogger. Actual logger: " + logger + .getClass() + .getName() ); + } + this.logger = (AbstractLogger) logger; + this.messageFactory = new MessageFormatMessageFactory(); + } + + void registerListener(LogListener newListener) { + synchronized (enabledListeners) { + if ( newListener != null ) { + enabledListeners.add( newListener ); + interceptEnabled.set( true ); + } + } + } + + void clearAllListeners() { + synchronized (enabledListeners) { + enabledListeners.clear(); + interceptEnabled.set( false ); + } + } + + @Override + public boolean isEnabled(final Level level) { + return this.logger.isEnabled( translate( level ) ); + } + + @Override + protected void doLog( + final Level level, + final String loggerClassName, + final Object message, + final Object[] parameters, + final Throwable thrown) { + final org.apache.logging.log4j.Level translatedLevel = translate( level ); + if ( interceptEnabled.get() ) { + intercept( + level, + parameters == null || parameters.length == 0 ? + String.valueOf( message ) : + MessageFormat.format( String.valueOf( message ), parameters ), + thrown + ); + } + if ( !this.logger.isEnabled( translatedLevel ) ) { + return; + } + try { + this.logger.logMessage( loggerClassName, translatedLevel, null, + ( parameters == null || parameters.length == 0 ) ? + this.messageFactory.newMessage( message ) : + this.messageFactory.newMessage( String.valueOf( message ), parameters ), + thrown + ); + } + catch (Throwable ignored) { + } + } + + private void intercept(Level level, String renderedMessage, Throwable thrown) { + synchronized (enabledListeners) { + for ( LogListener listener : enabledListeners ) { + listener.loggedEvent( level, renderedMessage, thrown ); + } + } + } + + @Override + protected void doLogf( + final Level level, + final String loggerClassName, + final String format, + final Object[] parameters, + final Throwable thrown) { + final org.apache.logging.log4j.Level translatedLevel = translate( level ); + if ( interceptEnabled.get() ) { + intercept( level, parameters == null ? format : String.format( format, parameters ), thrown ); + } + if ( !logger.isEnabled( translatedLevel ) ) { + return; + } + try { + this.logger.logMessage( + loggerClassName, + translatedLevel, + null, + new StringFormattedMessage( format, parameters ), + thrown + ); + } + catch (Throwable ignored) { + } + } + + private static org.apache.logging.log4j.Level translate(final Level level) { + if ( level == null ) { + return org.apache.logging.log4j.Level.ALL; + } + + switch ( level ) { + case FATAL: + return org.apache.logging.log4j.Level.FATAL; + case ERROR: + return org.apache.logging.log4j.Level.ERROR; + case WARN: + return org.apache.logging.log4j.Level.WARN; + case INFO: + return org.apache.logging.log4j.Level.INFO; + case DEBUG: + return org.apache.logging.log4j.Level.DEBUG; + case TRACE: + return org.apache.logging.log4j.Level.TRACE; + } + + return org.apache.logging.log4j.Level.ALL; + } + +} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java b/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java index b189410a39..a81e78bbf9 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/logger/LogInspectionHelper.java @@ -32,7 +32,7 @@ final class LogInspectionHelper { convertType( log ).clearAllListeners(); } - private static Log4DelegatingLogger convertType(BasicLogger log) { + private static Log4J2DelegatingLogger convertType(BasicLogger log) { if ( log instanceof DelegatingBasicLogger) { //Most loggers generated via the annotation processor are of this type DelegatingBasicLogger wrapper = (DelegatingBasicLogger) log; @@ -43,13 +43,13 @@ final class LogInspectionHelper { throw new RuntimeException( cause ); } } - if ( ! ( log instanceof Log4DelegatingLogger ) ) { + if ( ! ( log instanceof Log4J2DelegatingLogger ) ) { throw new AssertionFailure( "Unexpected log type: JBoss Logger didn't register the custom TestableLoggerProvider as logger provider" ); } - return (Log4DelegatingLogger) log; + return (Log4J2DelegatingLogger) log; } - private static Log4DelegatingLogger extractFromWrapper(DelegatingBasicLogger wrapper) throws Exception { + private static Log4J2DelegatingLogger extractFromWrapper(DelegatingBasicLogger wrapper) throws Exception { Field field = DelegatingBasicLogger.class.getDeclaredField( "log" ); field.setAccessible( true ); Object object = field.get( wrapper ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/logger/TestableLoggerProvider.java b/hibernate-testing/src/main/java/org/hibernate/testing/logger/TestableLoggerProvider.java index 50979d8d48..5f0fa3ca5d 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/logger/TestableLoggerProvider.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/logger/TestableLoggerProvider.java @@ -6,14 +6,15 @@ */ package org.hibernate.testing.logger; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.apache.log4j.MDC; -import org.apache.log4j.NDC; import org.jboss.logging.Logger; +import org.apache.logging.log4j.ThreadContext; + /** * A {@code LoggerProvider} for JBoss Logger. * See also META-INF/services/org.jboss.logging.LoggerProvider @@ -23,17 +24,18 @@ import org.jboss.logging.Logger; public class TestableLoggerProvider implements org.jboss.logging.LoggerProvider { //We LEAK Logger instances: good only for testing as we know the set of categories is limited in practice - private static final ConcurrentMap reuseLoggerInstances = new ConcurrentHashMap(); + private static final ConcurrentMap reuseLoggerInstances = new ConcurrentHashMap<>(); // Maintainer note: // Except the next method, which is adjusted to return our own Log4DelegatingLogger // this class is a verbatim copy of org.jboss.logging.Log4jLoggerProvider // (which is a final class) + @Override public Logger getLogger(final String name) { Logger logger = reuseLoggerInstances.get( name ); if ( logger == null ) { - logger = new Log4DelegatingLogger( "".equals( name ) ? "ROOT" : name ); + logger = new Log4J2DelegatingLogger( "".equals( name ) ? "ROOT" : name ); Logger previous = reuseLoggerInstances.putIfAbsent( name, logger ); if ( previous != null ) { return previous; @@ -44,57 +46,67 @@ public class TestableLoggerProvider implements org.jboss.logging.LoggerProvider @Override public void clearMdc() { - MDC.clear(); + ThreadContext.clearMap(); } - public Object getMdc(String key) { - return MDC.get( key ); - } - - @SuppressWarnings("unchecked") - public Map getMdcMap() { - return MDC.getContext(); - } - - public Object putMdc(String key, Object val) { + @Override + public Object putMdc(String key, Object value) { try { - return MDC.get( key ); + return ThreadContext.get( key ); } finally { - MDC.put( key, val ); + ThreadContext.put( key, String.valueOf( value ) ); } } + @Override + public Object getMdc(String key) { + return ThreadContext.get( key ); + } + + @Override public void removeMdc(String key) { - MDC.remove( key ); + ThreadContext.remove( key ); } + @Override + public Map getMdcMap() { + return new HashMap<>( ThreadContext.getImmutableContext() ); + } + + @Override public void clearNdc() { - NDC.remove(); + ThreadContext.clearStack(); } + @Override public String getNdc() { - return NDC.get(); + return ThreadContext.peek(); } + @Override public int getNdcDepth() { - return NDC.getDepth(); - } - - public String peekNdc() { - return NDC.peek(); + return ThreadContext.getDepth(); } + @Override public String popNdc() { - return NDC.pop(); + return ThreadContext.pop(); } + @Override + public String peekNdc() { + return ThreadContext.peek(); + } + + @Override public void pushNdc(String message) { - NDC.push( message ); + ThreadContext.push( message ); } + @Override public void setNdcMaxDepth(int maxDepth) { - NDC.setMaxDepth( maxDepth ); + ThreadContext.trim( maxDepth ); } } diff --git a/hibernate-testing/src/test/java/org/hibernate/testing/logger/LogDelegationTest.java b/hibernate-testing/src/test/java/org/hibernate/testing/logger/LogDelegationTest.java index 9509646e66..34d9e9c9ee 100644 --- a/hibernate-testing/src/test/java/org/hibernate/testing/logger/LogDelegationTest.java +++ b/hibernate-testing/src/test/java/org/hibernate/testing/logger/LogDelegationTest.java @@ -30,7 +30,7 @@ public class LogDelegationTest { @Test public void testLogDelegationIsActivated() { - assertThat( LOG, instanceOf( Log4DelegatingLogger.class ) ); + assertThat( LOG, instanceOf( Log4J2DelegatingLogger.class ) ); } @Test diff --git a/hibernate-vibur/src/test/resources/log4j.properties b/hibernate-vibur/src/test/resources/log4j.properties deleted file mode 100644 index eb96581a28..0000000000 --- a/hibernate-vibur/src/test/resources/log4j.properties +++ /dev/null @@ -1,60 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n -#log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n - -#log4j.appender.stdout-mdc=org.apache.log4j.ConsoleAppender -#log4j.appender.stdout-mdc.Target=System.out -#log4j.appender.stdout-mdc.layout=org.apache.log4j.PatternLayout -#log4j.appender.stdout-mdc.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n - -log4j.appender.unclosedSessionFactoryFile=org.apache.log4j.FileAppender -log4j.appender.unclosedSessionFactoryFile.append=true -log4j.appender.unclosedSessionFactoryFile.file=target/tmp/log/UnclosedSessionFactoryWarnings.log -log4j.appender.unclosedSessionFactoryFile.layout=org.apache.log4j.PatternLayout -log4j.appender.unclosedSessionFactoryFile.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -log4j.rootLogger=info, stdout - -#log4j.logger.org.hibernate.loader.plan=trace, stdout-mdc -#log4j.additivity.org.hibernate.loader.plan=false -#log4j.logger.org.hibernate.persister.walking=trace, stdout-mdc -#log4j.additivity.org.hibernate.persister.walking=false - -log4j.logger.org.hibernate.tool.hbm2ddl=trace -log4j.logger.org.hibernate.testing.cache=debug - -# SQL Logging - HHH-6833 -log4j.logger.org.hibernate.SQL=debug - -log4j.logger.org.hibernate.type.descriptor.sql.BasicBinder=trace -log4j.logger.org.hibernate.type.descriptor.sql.BasicExtractor=trace - -log4j.logger.org.hibernate.hql.internal.ast=debug - -log4j.logger.org.hibernate.sql.ordering.antlr=debug - -log4j.logger.org.hibernate.loader.plan2.build.internal.LoadPlanImpl=debug -log4j.logger.org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter=debug -log4j.logger.org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails=debug - -log4j.logger.org.hibernate.engine.internal.StatisticalLoggingSessionEventListener=info - -log4j.logger.org.hibernate.boot.model.source.internal.hbm.ModelBinder=debug -log4j.logger.org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry=debug - - -### When entity copy merge functionality is enabled using: -### hibernate.event.merge.entity_copy_observer=log, the following will -### provide information about merged entity copies. -### log4j.logger.org.hibernate.event.internal.EntityCopyAllowedLoggedObserver=debug - -log4j.logger.org.hibernate.testing.junit4.TestClassMetadata=info, unclosedSessionFactoryFile -log4j.logger.org.hibernate.boot.model.process.internal.ScanningCoordinator=debug diff --git a/hibernate-vibur/src/test/resources/log4j2.properties b/hibernate-vibur/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..1563522cc7 --- /dev/null +++ b/hibernate-vibur/src/test/resources/log4j2.properties @@ -0,0 +1,83 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (hibernateLoadPlanWalkPath->%X{hibernateLoadPlanWalkPath}) - %m%n + +appender.stdout-mdc.type=Console +appender.stdout-mdc.name=stdout-mdc +appender.stdout-mdc.layout.type=PatternLayout +appender.stdout-mdc.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L (walk path -> %X{hibernateLoadPlanWalkPath}) - %m%n + +appender.unclosedSessionFactoryFile.type=File +appender.unclosedSessionFactoryFile.name=unclosedSessionFactoryFile +appender.unclosedSessionFactoryFile.append=true +appender.unclosedSessionFactoryFile.fileName=target/tmp/log/UnclosedSessionFactoryWarnings.log +appender.unclosedSessionFactoryFile.layout.type=PatternLayout +appender.unclosedSessionFactoryFile.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +rootLogger.level=info +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.loader-plan.name=org.hibernate.loader.plan +#logger.loader-plan.level=trace +#logger.loader-plan.appenderRef.stdout-mdc.ref=stdout-mdc +#logger.loader-plan.additivity=false +logger.persister-walking.name=org.hibernate.persister.walking +#logger.persister-walking.level=trace +#logger.persister-walking.appenderRef.stdout-mdc.ref=stdout-mdc +#logger.persister-walking.additivity=false + +logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl +logger.hbm2ddl.level=trace +logger.testing-cache.name=org.hibernate.testing.cache +logger.testing-cache.level=debug + +# SQL Logging - HHH-6833 +logger.sql.name=org.hibernate.SQL +logger.sql.level=debug + +logger.type-basic-binder.name=org.hibernate.type.descriptor.sql.BasicBinder +logger.type-basic-binder.level=trace +logger.type-basic-extractor.name=org.hibernate.type.descriptor.sql.BasicExtractor +logger.type-basic-extractor.level=trace + +logger.hql-internal-ast.name=org.hibernate.hql.internal.ast +logger.hql-internal-ast.level=debug + +logger.sql-ordering-antlr.name=org.hibernate.sql.ordering.antlr +logger.sql-ordering-antlr.level=debug + +logger.load-plan-impl.name=org.hibernate.loader.plan2.build.internal.LoadPlanImpl +logger.load-plan-impl.level=debug +logger.load-plan-tree-printer.name=org.hibernate.loader.plan2.build.spi.LoadPlanTreePrinter +logger.load-plan-tree-printer.level=debug +logger.entity-load-query-details.name=org.hibernate.loader.plan2.exec.spi.EntityLoadQueryDetails +logger.entity-load-query-details.level=debug + +logger.statistical-logging-session-event-listener.name=org.hibernate.engine.internal.StatisticalLoggingSessionEventListener +logger.statistical-logging-session-event-listener.level=info + +logger.model-binder.name=org.hibernate.boot.model.source.internal.hbm.ModelBinder +logger.model-binder.level=debug +logger.java-type-descriptor-registry.name=org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry +logger.java-type-descriptor-registry.level=debug + + +logger.merged-entity-copies.name=org.hibernate.event.internal.EntityCopyAllowedLoggedObserver +### When entity copy merge functionality is enabled using: +### hibernate.event.merge.entity_copy_observer=log, the following will +### provide information about merged entity copies. +#logger.merged-entity-copies.level=debug + +logger.test-class-metadata.name=org.hibernate.testing.junit4.TestClassMetadata +logger.test-class-metadata.level=info +logger.test-class-metadata.appenderRef.unclosedSessionFactoryFile.ref=unclosedSessionFactoryFile +logger.scanning-coordinator.name=org.hibernate.boot.model.process.internal.ScanningCoordinator +logger.scanning-coordinator.level=debug diff --git a/tooling/metamodel-generator/src/test/resources/log4j.properties b/tooling/metamodel-generator/src/test/resources/log4j.properties deleted file mode 100644 index 319af3375c..0000000000 --- a/tooling/metamodel-generator/src/test/resources/log4j.properties +++ /dev/null @@ -1,31 +0,0 @@ -# -# Hibernate, Relational Persistence for Idiomatic Java -# -# License: GNU Lesser General Public License (LGPL), version 2.1 or later. -# See the lgpl.txt file in the root directory or . -# - -### direct log messages to stdout ### -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -### direct messages to file hibernate.log ### -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=hibernate.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n - -### direct messages to socket - chainsaw ### -log4j.appender.socket=org.apache.log4j.net.SocketAppender -log4j.appender.socket.remoteHost=localhost -log4j.appender.socket.port=4560 -log4j.appender.socket.locationInfo=true - - -### set log levels - for more verbose logging change 'info' to 'debug' ### -log4j.rootLogger=warn, stdout - -#log4j.logger.org.hibernate.jpamodelgen.test.util.CompilationTest=trace - diff --git a/tooling/metamodel-generator/src/test/resources/log4j2.properties b/tooling/metamodel-generator/src/test/resources/log4j2.properties new file mode 100644 index 0000000000..096dfc1d71 --- /dev/null +++ b/tooling/metamodel-generator/src/test/resources/log4j2.properties @@ -0,0 +1,28 @@ +# +# Hibernate, Relational Persistence for Idiomatic Java +# +# License: GNU Lesser General Public License (LGPL), version 2.1 or later. +# See the lgpl.txt file in the root directory or . +# + +### direct log messages to stdout ### +appender.stdout.type=Console +appender.stdout.name=STDOUT +appender.stdout.layout.type=PatternLayout +appender.stdout.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + +### direct messages to file hibernate.log ### +appender.file.type=File +appender.file.name=file +appender.file.fileName=hibernate.log +appender.file.layout.type=PatternLayout +appender.file.layout.pattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n + + +### set log levels - for more verbose logging change 'info' to 'debug' ### +rootLogger.level=warn +rootLogger.appenderRef.stdout.ref=STDOUT + +logger.compilation-test.name=org.hibernate.jpamodelgen.test.util.CompilationTest +#logger.compilation-test.level=trace +