首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

如何使用log4j2.properties文件打印Hibernate 5.4生成的参数和sql

log4j2.properties是log4j2日志框架的配置文件,用于配置日志的输出方式和级别。下面是使用log4j2.properties文件打印Hibernate 5.4生成的参数和sql的步骤:

  1. 创建log4j2.properties文件,并将其放置在项目的classpath下(通常是src/main/resources目录)。
  2. 在log4j2.properties文件中添加以下配置:
代码语言:txt
复制
# 设置根日志级别为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
  1. 在Hibernate的配置文件(通常是hibernate.cfg.xml)中添加以下配置,以启用log4j2日志框架:
代码语言:txt
复制
<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>
  1. 运行项目,Hibernate 5.4将会使用log4j2进行日志输出,包括生成的参数和sql。

注意:以上配置仅适用于Hibernate 5.4版本,其他版本的Hibernate可能需要稍作调整。另外,配置中的日志级别和输出方式可以根据实际需求进行调整。

推荐的腾讯云相关产品:腾讯云日志服务(CLS),它是一种全托管的日志管理服务,可帮助您实时采集、存储、检索和分析日志数据。您可以使用CLS来收集和分析Hibernate生成的参数和sql的日志数据。了解更多信息,请访问:腾讯云日志服务(CLS)

相关搜索:如何在使用hibernate 3和logback时打印准确的sql查询如何使用Swashbuckle在生成的Swagger文件中生成全局参数?使用具有多个参数的SSRS从SQL Server生成和下载报告如何使用Python 3的Tkinter打开和打印文件(在打印机中)?如何配置DOS和SQL Developer以使用要使用的TNSAMES文件?如何使用Doctrine2和Symfony2查看自动生成的SQL架构更新SQL查询?SQL Server数据库备份脚本:如何使用文件路径/位置的参数?如何在SQL Server中使用存储过程生成表的数据脚本文件?VBA Excel:如何使用用于打开、打印和关闭的文件号的变量如何使用JPQL、Spring Data Repositories和Hibernate参数化TimescaleDB `time_bucket`函数的Postgresql时间间隔如何使用cx_Oracle和Python执行存储在.sql文件中的PL/SQL代码如何合并两个文件,同时使用AWK在生成的空字段上打印给定值?如何在visual studio代码中使用命令生成文件夹和其中的文件?如何在vue组件上传递上传的文件和使用axios传递参数?如何使用随机值和Python中的random()方法生成两列21行的文件如何重载C++中的"delete“操作符,以打印使用它的文件的行和名称?如何使用图像数据生成器和来自dataframe的流(使用CSV文件)实现K折叠交叉验证在sql中使用带有传入参数的like关键字时,如何在使用sequelize和sql模板字符串时获得返回结果?如何使用sbt和Java 1.8生成能够在Java 1.7上运行的jar文件如何使用Android Studio中的DataOutputStream上传文件和传递其他参数到web服务器
相关搜索:
页面内容是否对你有帮助?
有帮助
没帮助

相关·内容

没有搜到相关的视频

领券