Merge remote-tracking branch 'upstream/main' into wip/6.0_merge_7

This commit is contained in:
Andrea Boriero 2021-05-31 14:55:18 +02:00
commit 451568f322
49 changed files with 1019 additions and 739 deletions

View File

@ -59,7 +59,6 @@
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle> <bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
<bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle> <bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle>
<bundle>mvn:log4j/log4j/1.2.17</bundle>
<bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle> <bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle>
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle> <bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>

View File

@ -32,7 +32,6 @@
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle> <bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
<bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle> <bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle>
<bundle>mvn:log4j/log4j/1.2.17</bundle>
<bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle> <bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle>
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle> <bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>

View File

@ -40,7 +40,6 @@
<bundle>mvn:com.fasterxml/classmate/0.8.0</bundle> <bundle>mvn:com.fasterxml/classmate/0.8.0</bundle>
<bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle> <bundle>mvn:org.apache.logging.log4j/log4j-api/2.0</bundle>
<bundle>mvn:log4j/log4j/1.2.17</bundle>
<bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle> <bundle>mvn:org.jboss.logging/jboss-logging/3.2.1.Final</bundle>
<bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle> <bundle>mvn:org.javassist/javassist/3.18.1-GA</bundle>

View File

@ -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 <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=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.jdbc=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

View File

@ -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 <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.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.jdbc
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

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
### 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

66
etc/log4j2.properties Normal file
View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
### 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

View File

@ -91,7 +91,7 @@ dependencies {
testImplementation libraries.byteman_install testImplementation libraries.byteman_install
testImplementation libraries.byteman_bmunit testImplementation libraries.byteman_bmunit
testRuntimeOnly libraries.log4j testRuntimeOnly libraries.log4j2
testRuntimeOnly libraries.javassist testRuntimeOnly libraries.javassist
testRuntimeOnly libraries.byteBuddy testRuntimeOnly libraries.byteBuddy

View File

@ -9,9 +9,9 @@
// use. In that respect it serves a role similar to <dependencyManagement> in Maven // use. In that respect it serves a role similar to <dependencyManagement> in Maven
ext { ext {
junitVersion = '4.12' junitVersion = '4.13'
junitVintageVersion = '5.4.2' junitVintageVersion = '5.7.1'
junit5Version = '5.4.2' junit5Version = '5.7.1'
h2Version = '1.4.199' h2Version = '1.4.199'
bytemanVersion = '4.0.13' //Compatible with JDK16 bytemanVersion = '4.0.13' //Compatible with JDK16
@ -133,7 +133,7 @@ ext {
junit: "junit:junit:${junitVersion}", junit: "junit:junit:${junitVersion}",
junit5_vintage: "org.junit.vintage:junit-vintage-engine:${junitVintageVersion}", junit5_vintage: "org.junit.vintage:junit-vintage-engine:${junitVintageVersion}",
log4j: "log4j:log4j:1.2.17", log4j2: "org.apache.logging.log4j:log4j-core:2.14.1",
byteman: "org.jboss.byteman:byteman:${bytemanVersion}", byteman: "org.jboss.byteman:byteman:${bytemanVersion}",
byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}", byteman_install: "org.jboss.byteman:byteman-install:${bytemanVersion}",

View File

@ -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 <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.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.jdbc.BasicBinder=trace
log4j.logger.org.hibernate.type.descriptor.jdbc.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

View File

@ -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 <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
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.jdbc.BasicBinder
logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdb.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

View File

@ -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 <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.tool.hbm2ddl=debug
log4j.logger.org.hibernate.testing.cache=debug

View File

@ -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 <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.hbm2ddl.name=org.hibernate.tool.hbm2ddl
logger.hbm2ddl.level=debug
logger.testing-cache.name=org.hibernate.testing.cache
logger.testing-cache.level=debug

View File

@ -88,7 +88,6 @@ dependencies {
testImplementation libraries.mockito_inline testImplementation libraries.mockito_inline
testImplementation libraries.jodaTime testImplementation libraries.jodaTime
testImplementation libraries.assertj testImplementation libraries.assertj
testImplementation libraries.log4j
testImplementation libraries.cdi testImplementation libraries.cdi
testImplementation libraries.jboss_ejb_spec_jar testImplementation libraries.jboss_ejb_spec_jar
testImplementation libraries.jboss_annotation_spec_jar testImplementation libraries.jboss_annotation_spec_jar

View File

@ -202,6 +202,10 @@ public class QueryStatisticsImpl implements QueryStatistics {
planCacheHitCount.increment(); planCacheHitCount.increment();
} }
void incrementPlanCacheMissCount() {
planCacheMissCount.increment();
}
public String toString() { public String toString() {
return "QueryStatistics" return "QueryStatistics"
+ "[query=" + query + "[query=" + query

View File

@ -805,11 +805,20 @@ public class StatisticsImpl implements StatisticsImplementor, Service, Manageabl
} }
@Override @Override
public void queryPlanCacheHit(String hql) { public void queryPlanCacheHit(String query) {
queryPlanCacheHitCount.increment(); queryPlanCacheHitCount.increment();
if ( hql != null ) { if ( query != null ) {
getQueryStatistics( hql ).incrementPlanCacheHitCount(); getQueryStatistics( query ).incrementPlanCacheHitCount();
}
}
@Override
public void queryPlanCacheMiss(String query) {
queryPlanCacheMissCount.increment();
if ( query != null ) {
getQueryStatistics( query ).incrementPlanCacheMissCount();
} }
} }

View File

@ -251,9 +251,18 @@ public interface StatisticsImplementor extends Statistics, Service {
/** /**
* Callback indicating a get from the query plan cache resulted in a hit. * Callback indicating a get from the query plan cache resulted in a hit.
* *
* @param hql The query * @param query The query
*/ */
default void queryPlanCacheHit(String hql) { default void queryPlanCacheHit(String query) {
//For backward compatibility
}
/**
* Callback indicating a get from the query plan cache resulted in a miss.
*
* @param query The query
*/
default void queryPlanCacheMiss(String query) {
//For backward compatibility //For backward compatibility
} }

View File

@ -22,9 +22,6 @@ import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import javax.persistence.Table; 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.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
@ -34,6 +31,13 @@ import org.hibernate.testing.orm.junit.Setting;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.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") @TestForIssue(jiraKey = "HHH-13244")
@Jpa( @Jpa(
annotatedClasses = { annotatedClasses = {
@ -75,11 +79,13 @@ public class JpaProxyComplianceWithDebugTest {
@Test @Test
@TestForIssue(jiraKey = "HHH-13244") @TestForIssue(jiraKey = "HHH-13244")
public void testJpaComplianceProxyWithDebug(EntityManagerFactoryScope scope) { public void testJpaComplianceProxyWithDebug(EntityManagerFactoryScope scope) {
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. //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 //These are simply the narrowest log settings that trigger the bug
Logger entityLogger = LogManager.getLogger("org.hibernate.internal.util.EntityPrinter"); LoggerConfig entityLogger = configuration.getLoggerConfig( "org.hibernate.internal.util.EntityPrinter");
Logger listenerLogger = LogManager.getLogger("org.hibernate.event.internal.AbstractFlushingEventListener"); LoggerConfig listenerLogger = configuration.getLoggerConfig("org.hibernate.event.internal.AbstractFlushingEventListener");
Level oldEntityLogLevel = entityLogger.getLevel(); Level oldEntityLogLevel = entityLogger.getLevel();
Level oldListenerLogLevel = listenerLogger.getLevel(); Level oldListenerLogLevel = listenerLogger.getLevel();

View File

@ -27,8 +27,12 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.LoggerConfig;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
@ -46,9 +50,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
@DomainModel(annotatedClasses = { TestEntity.class, AggregateEntity.class }) @DomainModel(annotatedClasses = { TestEntity.class, AggregateEntity.class })
@SessionFactory(generateStatistics = true) @SessionFactory(generateStatistics = true)
public class QueryResultCacheTests { public class QueryResultCacheTests {
private final Logger resultsLogger = Logger.getLogger( ResultsLogger.LOGGER_NAME ); private final LoggerContext context = (LoggerContext) LogManager.getContext( false );
private final Logger execLogger = Logger.getLogger( SqlExecLogger.LOGGER_NAME ); private final Configuration configuration = context.getConfiguration();
private final Logger cacheLogger = Logger.getLogger( SecondLevelCacheLogger.LOGGER_NAME ); private final LoggerConfig resultsLoggerConfig = configuration.getLoggerConfig( ResultsLogger.LOGGER_NAME );
private final LoggerConfig execLoggerConfig = configuration.getLoggerConfig( SqlExecLogger.LOGGER_NAME );
private final LoggerConfig cacheLoggerConfig = configuration.getLoggerConfig( SecondLevelCacheLogger.LOGGER_NAME );
Logger resultsLogger = LogManager.getLogger( ResultsLogger.LOGGER_NAME );
private Level originalResultsLevel; private Level originalResultsLevel;
private Level originalExecLevel; private Level originalExecLevel;
@ -56,21 +64,21 @@ public class QueryResultCacheTests {
@BeforeAll @BeforeAll
public void setUpLogger() { public void setUpLogger() {
originalResultsLevel = resultsLogger.getLevel(); originalResultsLevel = resultsLoggerConfig.getLevel();
resultsLogger.setLevel( Level.TRACE ); resultsLoggerConfig.setLevel( Level.TRACE );
originalExecLevel = execLogger.getLevel(); originalExecLevel = execLoggerConfig.getLevel();
execLogger.setLevel( Level.TRACE ); execLoggerConfig.setLevel( Level.TRACE );
originalCacheLevel = cacheLogger.getLevel(); originalCacheLevel = cacheLoggerConfig.getLevel();
cacheLogger.setLevel( Level.TRACE ); cacheLoggerConfig.setLevel( Level.TRACE );
} }
@AfterAll @AfterAll
public void resetLogger() { public void resetLogger() {
resultsLogger.setLevel( originalResultsLevel ); resultsLoggerConfig.setLevel( originalResultsLevel );
execLogger.setLevel( originalExecLevel ); execLoggerConfig.setLevel( originalExecLevel );
cacheLogger.setLevel( originalCacheLevel ); cacheLoggerConfig.setLevel( originalCacheLevel );
} }
@Test @Test

View File

@ -24,7 +24,7 @@ import org.hibernate.tool.schema.internal.SchemaCreatorImpl;
import org.hibernate.testing.TestForIssue; import org.hibernate.testing.TestForIssue;
import org.junit.Test; 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.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;

View File

@ -12,6 +12,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.LockModeType; import javax.persistence.LockModeType;
import javax.persistence.NamedQuery; import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Tuple; import javax.persistence.Tuple;
import javax.persistence.TypedQuery; import javax.persistence.TypedQuery;
@ -146,7 +147,7 @@ public class QueryPlanCacheStatisticsTest {
assertEquals( 5, employees.size() ); assertEquals( 5, employees.size() );
//The miss count is still 1, as no we got the query plan from the cache //The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() ); assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases. //And the cache hit count increases.
assertEquals( 1, statistics.getQueryPlanCacheHitCount() ); assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
@ -160,7 +161,55 @@ public class QueryPlanCacheStatisticsTest {
assertEquals( 5, employees.size() ); assertEquals( 5, employees.size() );
//The miss count is still 1, as no we got the query plan from the cache //The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases.
assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
} );
}
@Test
@TestForIssue( jiraKey = "HHH-14632" )
public void testCreateNativeQueryHitCount(SessionFactoryScope scope) {
statistics.clear();
scope.inTransaction( entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//First time, we get a cache miss, so the query is compiled
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//The hit count should be 0 as we don't need to go to the cache after we already compiled the query
assertEquals( 0, statistics.getQueryPlanCacheHitCount() );
} );
scope.inTransaction( entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases.
assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
} );
scope.inTransaction( entityManager -> {
List<Employee> employees = entityManager.createNativeQuery(
"select * from employee e", Employee.class )
.getResultList();
assertEquals( 5, employees.size() );
//The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() ); assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases. //And the cache hit count increases.
assertEquals( 2, statistics.getQueryPlanCacheHitCount() ); assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
@ -225,7 +274,7 @@ public class QueryPlanCacheStatisticsTest {
assertEquals( 5, employees.size() ); assertEquals( 5, employees.size() );
//The miss count is still 1, as no we got the query plan from the cache //The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() ); assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases. //And the cache hit count increases.
assertEquals( 1, statistics.getQueryPlanCacheHitCount() ); assertEquals( 1, statistics.getQueryPlanCacheHitCount() );
@ -239,7 +288,7 @@ public class QueryPlanCacheStatisticsTest {
assertEquals( 5, employees.size() ); assertEquals( 5, employees.size() );
//The miss count is still 1, as no we got the query plan from the cache //The miss count is still 1, as now we got the query plan from the cache
assertEquals( 1, statistics.getQueryPlanCacheMissCount() ); assertEquals( 1, statistics.getQueryPlanCacheMissCount() );
//And the cache hit count increases. //And the cache hit count increases.
assertEquals( 2, statistics.getQueryPlanCacheHitCount() ); assertEquals( 2, statistics.getQueryPlanCacheHitCount() );
@ -283,6 +332,7 @@ public class QueryPlanCacheStatisticsTest {
} }
@Entity(name = "Employee") @Entity(name = "Employee")
@Table(name = "employee")
@NamedQuery( @NamedQuery(
name = "find_employee_by_name", name = "find_employee_by_name",
query = "select e from Employee e where e.name = :name" query = "select e from Employee e where e.name = :name"

View File

@ -154,8 +154,10 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase {
newTx = s.beginTransaction(); newTx = s.beginTransaction();
// please enable // please enable
// log4j.logger.org.hibernate.cache.StandardQueryCache=DEBUG // logger.standard-query-cache.name=org.hibernate.cache.StandardQueryCache
// log4j.logger.org.hibernate.cache.UpdateTimestampsCache=DEBUG // 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 // to see that isUpToDate is called where not appropriated
Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() );
@ -254,8 +256,10 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase {
newTx = s.beginTransaction(); newTx = s.beginTransaction();
// please enable // please enable
// log4j.logger.org.hibernate.cache.StandardQueryCache=DEBUG // logger.standard-query-cache.name=org.hibernate.cache.StandardQueryCache
// log4j.logger.org.hibernate.cache.UpdateTimestampsCache=DEBUG // 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 // to see that isUpToDate is called where not appropriated
Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() );
@ -303,8 +307,10 @@ public class ImmutableNaturalKeyLookupTest extends BaseCoreFunctionalTestCase {
newTx = s.beginTransaction(); newTx = s.beginTransaction();
// please enable // please enable
// log4j.logger.org.hibernate.cache.StandardQueryCache=DEBUG // logger.standard-query-cache.name=org.hibernate.cache.StandardQueryCache
// log4j.logger.org.hibernate.cache.UpdateTimestampsCache=DEBUG // 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 // to see that isUpToDate is called where not appropriated
Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() ); Assert.assertTrue( s.getSessionFactory().getStatistics().isStatisticsEnabled() );

View File

@ -1,75 +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.appender.stdout2=org.apache.log4j.ConsoleAppender
log4j.appender.stdout2.Target=System.out
log4j.appender.stdout2.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout2.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{5}:(%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
# SQL Logging - HHH-6833
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.orm=info, stdout2
log4j.additivity.org.hibernate.orm=false
log4j.logger.org.hibernate.orm.sql.results=debug
#log4j.logger.org.hibernate.orm.graph=debug
log4j.logger.org.hibernate.orm.query.sqm=debug
log4j.logger.org.hibernate.orm.query.hql=trace
log4j.logger.org.hibernate.sql.results.graph.DomainResultGraphPrinter=debug
#log4j.logger.org.hibernate.orm.mapping.natural_id=debug
log4j.logger.org.hibernate.tool.hbm2ddl=trace
#log4j.logger.org.hibernate.testing.cache=debug
#log4j.logger.org.hibernate.orm.sql.results.loading.collection=trace
log4j.logger.org.hibernate.orm.jdbc.bind=trace
log4j.logger.org.hibernate.orm.jdbc.extract=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

View File

@ -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 <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
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.jdbc.BasicBinder
logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.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

View File

@ -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

View File

@ -1,32 +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
log4j.logger.org.hibernate.tool.hbm2ddl=debug
log4j.logger.org.hibernate.type.descriptor.jdbc.BasicBinder=trace
log4j.logger.org.hibernate.type.descriptor.jdbc.BasicExtractor=trace
log4j.logger.org.hibernate.envers.jaxb=debug
log4j.logger.org.hibernate.query=debug
log4j.logger.org.hibernate.orm.query=debug
log4j.logger.org.hibernate.sql.ast=debug
log4j.logger.org.hibernate.orm.sql.ast=debug
log4j.logger.org.hibernate.sql.exec=debug
log4j.logger.org.hibernate.orm.sql.exec=debug

View File

@ -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 <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
logger.hbm2ddl.name=org.hibernate.tool.hbm2ddl
logger.hbm2ddl.level=debug
logger.type-basic-binder.name=org.hibernate.type.descriptor.jdbc.BasicBinder
logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.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

View File

@ -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 <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.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.jdbc.BasicBinder=trace
log4j.logger.org.hibernate.type.descriptor.jdbc.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

View File

@ -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 <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
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.jdbc.BasicBinder
logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.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

View File

@ -5,19 +5,19 @@
# See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. # See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
# #
# Root logger option # Direct log messages to console
log4j.rootLogger=DEBUG, 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 # Direct log messages to a log file
log4j.appender.file=org.apache.log4j.FileAppender appender.file.type=File
log4j.appender.file.File=target/test.log appender.file.name=file
log4j.appender.file.layout=org.apache.log4j.PatternLayout appender.file.fileName=target/test.log
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n appender.file.layout.type=PatternLayout
log4j.appender.file.Threshold=DEBUG appender.file.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p [%c] (%t) - %m%n
# Direct log messages to console # Root logger option
log4j.appender.console=org.apache.log4j.ConsoleAppender rootLogger.level=debug
log4j.appender.console.Target=System.out rootLogger.appenderRef.file.ref=file
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

View File

@ -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

View File

@ -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

View File

@ -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 <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.stat=trace
log4j.logger.org.hibernate.tool.hbm2ddl=trace
log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type.descriptor.jdbc.BasicBinder=trace
log4j.logger.org.hibernate.type.descriptor.jdbc.BasicExtractor=trace

View File

@ -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 <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.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.jdbc.BasicBinder
logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.BasicExtractor
logger.type-basic-extractor.level=trace

View File

@ -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 <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.tool.hbm2ddl=debug
log4j.logger.org.hibernate.testing.cache=debug

View File

@ -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 <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.hbm2ddl.name=org.hibernate.tool.hbm2ddl
logger.hbm2ddl.level=debug
logger.testing-cache.name=org.hibernate.testing.cache
logger.testing-cache.level=debug

View File

@ -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 <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.SQL=DEBUG
log4j.logger.org.hibernate.spatial=debug

View File

@ -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 <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.sql.name=org.hibernate.SQL
logger.sql.level=DEBUG
logger.spatial.name=org.hibernate.spatial
logger.spatial.level=debug

View File

@ -35,6 +35,8 @@ dependencies {
api 'javax.money:money-api:1.0.1' api 'javax.money:money-api:1.0.1'
api 'org.javamoney:moneta:1.1' api 'org.javamoney:moneta:1.1'
api libraries.log4j2
jakartaeeTransformJars 'biz.aQute.bnd:biz.aQute.bnd.transform:5.1.1', jakartaeeTransformJars 'biz.aQute.bnd:biz.aQute.bnd.transform:5.1.1',
'commons-cli:commons-cli:1.4', 'commons-cli:commons-cli:1.4',
'org.slf4j:slf4j-simple:1.7.30', 'org.slf4j:slf4j-simple:1.7.30',

View File

@ -32,7 +32,7 @@ dependencies {
api 'javax.money:money-api:1.0.1' api 'javax.money:money-api:1.0.1'
api 'org.javamoney:moneta:1.1' api 'org.javamoney:moneta:1.1'
compileOnly libraries.log4j api libraries.log4j2
} }
tasks.test.include '**/*' tasks.test.include '**/*'

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 <a href="mailto:sanne@hibernate.org">Sanne Grinovero</a> (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<LogListener> enabledListeners = new LinkedList<LogListener>();
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;
}
}

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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 <a href="mailto:sanne@hibernate.org">Sanne Grinovero</a> (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<LogListener> 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;
}
}

View File

@ -25,7 +25,7 @@ public final class LogInspectionHelper {
private LogInspectionHelper() { private LogInspectionHelper() {
} }
private static Log4DelegatingLogger convertType(Object loggerReference) { private static Log4J2DelegatingLogger convertType(Object loggerReference) {
if ( loggerReference instanceof DelegatingBasicLogger) { if ( loggerReference instanceof DelegatingBasicLogger) {
//Most loggers generated via the annotation processor are of this type //Most loggers generated via the annotation processor are of this type
DelegatingBasicLogger wrapper = (DelegatingBasicLogger) loggerReference; DelegatingBasicLogger wrapper = (DelegatingBasicLogger) loggerReference;
@ -37,11 +37,11 @@ public final class LogInspectionHelper {
} }
} }
if ( ! ( loggerReference instanceof Log4DelegatingLogger ) ) { if ( ! ( loggerReference instanceof Log4J2DelegatingLogger ) ) {
throw new AssertionFailure( "Unexpected log type: JBoss Logger didn't register the custom TestableLoggerProvider as logger provider" ); throw new AssertionFailure( "Unexpected log type: JBoss Logger didn't register the custom TestableLoggerProvider as logger provider" );
} }
return (Log4DelegatingLogger) loggerReference; return (Log4J2DelegatingLogger) loggerReference;
} }
public static void registerListener(LogListener listener, BasicLogger log) { public static void registerListener(LogListener listener, BasicLogger log) {
@ -52,7 +52,7 @@ public final class LogInspectionHelper {
convertType( log ).clearAllListeners(); convertType( log ).clearAllListeners();
} }
private static Log4DelegatingLogger convertType(BasicLogger log) { private static Log4J2DelegatingLogger convertType(BasicLogger log) {
if ( log instanceof DelegatingBasicLogger) { if ( log instanceof DelegatingBasicLogger) {
//Most loggers generated via the annotation processor are of this type //Most loggers generated via the annotation processor are of this type
DelegatingBasicLogger wrapper = (DelegatingBasicLogger) log; DelegatingBasicLogger wrapper = (DelegatingBasicLogger) log;
@ -63,13 +63,13 @@ public final class LogInspectionHelper {
throw new RuntimeException( cause ); 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" ); 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 field = DelegatingBasicLogger.class.getDeclaredField( "log" );
field.setAccessible( true ); field.setAccessible( true );
Object object = field.get( wrapper ); Object object = field.get( wrapper );

View File

@ -6,14 +6,15 @@
*/ */
package org.hibernate.testing.logger; package org.hibernate.testing.logger;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.apache.log4j.MDC;
import org.apache.log4j.NDC;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.apache.logging.log4j.ThreadContext;
/** /**
* A {@code LoggerProvider} for JBoss Logger. * A {@code LoggerProvider} for JBoss Logger.
* See also META-INF/services/org.jboss.logging.LoggerProvider * 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 { 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 //We LEAK Logger instances: good only for testing as we know the set of categories is limited in practice
private static final ConcurrentMap<String,Logger> reuseLoggerInstances = new ConcurrentHashMap<String,Logger>(); private static final ConcurrentMap<String,Logger> reuseLoggerInstances = new ConcurrentHashMap<>();
// Maintainer note: // Maintainer note:
// Except the next method, which is adjusted to return our own Log4DelegatingLogger // Except the next method, which is adjusted to return our own Log4DelegatingLogger
// this class is a verbatim copy of org.jboss.logging.Log4jLoggerProvider // this class is a verbatim copy of org.jboss.logging.Log4jLoggerProvider
// (which is a final class) // (which is a final class)
@Override
public Logger getLogger(final String name) { public Logger getLogger(final String name) {
Logger logger = reuseLoggerInstances.get( name ); Logger logger = reuseLoggerInstances.get( name );
if ( logger == null ) { if ( logger == null ) {
logger = new Log4DelegatingLogger( "".equals( name ) ? "ROOT" : name ); logger = new Log4J2DelegatingLogger( "".equals( name ) ? "ROOT" : name );
Logger previous = reuseLoggerInstances.putIfAbsent( name, logger ); Logger previous = reuseLoggerInstances.putIfAbsent( name, logger );
if ( previous != null ) { if ( previous != null ) {
return previous; return previous;
@ -44,57 +46,67 @@ public class TestableLoggerProvider implements org.jboss.logging.LoggerProvider
@Override @Override
public void clearMdc() { public void clearMdc() {
MDC.clear(); ThreadContext.clearMap();
} }
public Object getMdc(String key) { @Override
return MDC.get( key ); public Object putMdc(String key, Object value) {
}
@SuppressWarnings("unchecked")
public Map<String, Object> getMdcMap() {
return MDC.getContext();
}
public Object putMdc(String key, Object val) {
try { try {
return MDC.get( key ); return ThreadContext.get( key );
} }
finally { 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) { public void removeMdc(String key) {
MDC.remove( key ); ThreadContext.remove( key );
} }
@Override
public Map<String, Object> getMdcMap() {
return new HashMap<>( ThreadContext.getImmutableContext() );
}
@Override
public void clearNdc() { public void clearNdc() {
NDC.remove(); ThreadContext.clearStack();
} }
@Override
public String getNdc() { public String getNdc() {
return NDC.get(); return ThreadContext.peek();
} }
@Override
public int getNdcDepth() { public int getNdcDepth() {
return NDC.getDepth(); return ThreadContext.getDepth();
}
public String peekNdc() {
return NDC.peek();
} }
@Override
public String popNdc() { public String popNdc() {
return NDC.pop(); return ThreadContext.pop();
} }
@Override
public String peekNdc() {
return ThreadContext.peek();
}
@Override
public void pushNdc(String message) { public void pushNdc(String message) {
NDC.push( message ); ThreadContext.push( message );
} }
@Override
public void setNdcMaxDepth(int maxDepth) { public void setNdcMaxDepth(int maxDepth) {
NDC.setMaxDepth( maxDepth ); ThreadContext.trim( maxDepth );
} }
} }

View File

@ -30,7 +30,7 @@ public class LogDelegationTest {
@Test @Test
public void testLogDelegationIsActivated() { public void testLogDelegationIsActivated() {
assertThat( LOG, instanceOf( Log4DelegatingLogger.class ) ); assertThat( LOG, instanceOf( Log4J2DelegatingLogger.class ) );
} }
@Test @Test

View File

@ -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 <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.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.jdbc.BasicBinder=trace
log4j.logger.org.hibernate.type.descriptor.jdbc.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

View File

@ -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 <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
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.jdbc.BasicBinder
logger.type-basic-binder.level=trace
logger.type-basic-extractor.name=org.hibernate.type.descriptor.jdbc.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

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
### 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

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
#
### 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