log4j2.properties是log4j2日志框架的配置文件,用于配置日志的输出方式和级别。下面是使用log4j2.properties文件打印Hibernate 5.4生成的参数和sql的步骤:
# 设置根日志级别为DEBUG
rootLogger.level = debug
rootLogger.appenderRef.stdout.ref = Console
# 配置Console输出
appender.stdout.type = Console
appender.stdout.name = STDOUT
appender.stdout.layout.type = PatternLayout
appender.stdout.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
# 配置Hibernate的日志输出
logger.org.hibernate.type.descriptor.sql.BasicBinder.level = trace
logger.org.hibernate.SQL.level = trace
logger.org.hibernate.type.descriptor.sql.BasicExtractor.level = trace
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">true</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.jdbc.batch_size">50</property>
<property name="hibernate.order_inserts">true</property>
<property name="hibernate.order_updates">true</property>
<property name="hibernate.jdbc.batch_versioned_data">true</property>
<property name="hibernate.jdbc.fetch_size">100</property>
<property name="hibernate.jdbc.use_scrollable_resultset">true</property>
<property name="hibernate.jdbc.use_getGeneratedKeys">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.connection.release_mode">after_transaction</property>
<property name="hibernate.connection.autocommit">false</property>
<property name="hibernate.connection.provider_disables_autocommit">true</property>
<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.validate">true</property>
<property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
<property name="hibernate.c3p0.contextClassLoaderSource">library</property>
<property name="hibernate.c3p0.acquireRetryAttempts">1</property>
<property name="hibernate.c3p0.acquireRetryDelay">250</property>
<property name="hibernate.c3p0.breakAfterAcquireFailure">false</property>
<property name="hibernate.c3p0.maxIdleTime">1800</property>
<property name="hibernate.c3p0.maxIdleTimeExcessConnections">1800</property>
<property name="hibernate.c3p0.unreturnedConnectionTimeout">1800</property>
<property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces">true</property>
<property name="hibernate.c3p0.numHelperThreads">3</property>
<property name="hibernate.c3p0.maxAdministrativeTaskTime">1800</property>
<property name="hibernate.c3p0.idleConnectionTestPeriod">1800</property>
<property name="hibernate.c3p0.autoCommitOnClose">false</property>
<property name="hibernate.c3p0.forceIgnoreUnresolvedTransactions">false</property>
<property name="hibernate.c3p0.contextClassLoaderSource">library</property>
<property name="hibernate.c3p0.preferredTestQuery">SELECT 1</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.testConnectionOnCheckin">true</property>
<property name="hibernate.c3p0.acquireRetryAttempts">1</property>
<property name="hibernate.c3p0.acquireRetryDelay">250</property>
<property name="hibernate.c3p0.breakAfterAcquireFailure">false</property>
<property name="hibernate.c3p0.maxIdleTime">1800</property>
<property name="hibernate.c3p0.maxIdleTimeExcessConnections">1800</property>
<property name="hibernate.c3p0.unreturnedConnectionTimeout">1800</property>
<property name="hibernate.c3p0.debugUnreturnedConnectionStackTraces">true</property>
<property name="hibernate.c3p0.numHelperThreads">3</property>
<property name="hibernate.c3p0.maxAdministrativeTaskTime">1800</property>
<property name="hibernate.c3p0.idleConnectionTestPeriod">1800</property>
<property name="hibernate.c3p0.autoCommitOnClose">false</property>
<property name="hibernate.c3p0.forceIgnoreUnresolvedTransactions">false</property>
注意:以上配置仅适用于Hibernate 5.4版本,其他版本的Hibernate可能需要稍作调整。另外,配置中的日志级别和输出方式可以根据实际需求进行调整。
推荐的腾讯云相关产品:腾讯云日志服务(CLS),它是一种全托管的日志管理服务,可帮助您实时采集、存储、检索和分析日志数据。您可以使用CLS来收集和分析Hibernate生成的参数和sql的日志数据。了解更多信息,请访问:腾讯云日志服务(CLS)。
领取专属 10元无门槛券
手把手带您无忧上云