One: First look at a diagram
Commons-logging and SLF4J are log interfaces for use by users, without providing implementations! The Log4j,slf4j-nop in the back is their realization.
II: The Slf4j-api-1.5.8.jar of Hibernate framework
Hibernate defaults to the Slf4j-nop.jar log implementation method.
But we can replace the implementation of log4j. But not simply add Log4j-1.2.17.jar on the line. A converter is also required in the middle slf4j-log4j12-1.5.8.jar
Then add log4j.properties to the SRC directory
# # # Direct log messages to stdout # # #log4j. appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.target=system.outlog4j.appender.stdout.layout= Org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%d{absolute}%5p%c{1}:%L-%m%n### Set log levels-for more verbose logging "info" to ' Debug ' # # #log4j. Rootlogger=warn, Stdout#log4j.logger.org.hiber nate=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 Driv Ermanagerconnectionprovider # # # #log4j. logger.org.hibernate.connection.drivermanagerconnectionprovider=trace
Log output:
22:12:18,627 INFO schemaupdate:155-running HBM2DDL schema update
22:12:18,629 INFO schemaupdate:167-fetching Database metadata
22:12:18,630 INFO schemaupdate:179-updating Schema
22:12:18,647 INFO tablemetadata:65-table Found:hibernate.teacher
22:12:18,647 INFO tablemetadata:66-columns: [ID, title, name]
22:12:18,647 INFO tablemetadata:68-foreign keys: []
22:12:18,647 INFO tablemetadata:69-indexes: [Primary]
22:12:18,648 INFO Schemaupdate:217-schema Update complete
Hibernate:insert into Teacher (name, title, id) VALUES (?,?,?)
Hibernate learning: SLF4J log Frame