Я пытаюсь напечатать оператор sql в файле журнала, но он не работает.
Ниже приведен файл свойств приложения:
custom.datasource.jdbc-url=jdbc:mysql://127.0.0.1:3306/custom_service?useSSL=false
custom.datasource.username=root
custom.datasource.password=paytm@123
custom.datasource.driverClassName=com.mysql.jdbc.Driver
custom.hibernate.dialect=org.hibernate.dialect.MySQLDialect
custom.hibernate.hbm2ddl.auto=none
##show sql statement
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
Log4j root уровень установить в режим отладки. Что здесь не так?
Log4j Config, как показано ниже:
<?xml version="1.0" encoding="UTF-8"?>
<DynamicThresholdFilter key="x-debug-enabled" onMatch="ACCEPT" onMismatch="NEUTRAL">
<KeyValuePair key="true" value="DEBUG"/>
</DynamicThresholdFilter>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="[%level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} requestId: %X{requestId}, customerId: %X{customerId} - %msg%n"></PatternLayout>
</Console>
<File name="File" fileName="/var/log/custom-onboarding-service/custom-onboarding-service.log" ignoreExceptions="false">
<PatternLayout pattern="[%level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} requestId: %X{requestId}, customerId: %X{customerId} - %msg%n"></PatternLayout>
</File>
<File name="FileException" fileName="/var/log/custom-onboarding-service/custom-onboarding-service-error.log" ignoreExceptions="false">
<PatternLayout pattern="[%level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} requestId: %X{requestId}, customerId: %X{customerId} - %msg%n"></PatternLayout>
</File>
<RollingFile name="customOnboarding" fileName="/var/log/custom-onboarding-service/custom-onboarding-service-audit.log"
filePattern="/var/log/custom-onboarding-service/custom-onboarding-service-audit-%d{yyyy-MM-dd}-%i.log">
<PatternLayout>
<Pattern>%m%n</Pattern>
</PatternLayout>
<Policies>
<SizeBasedTriggeringPolicy size="250 MB"/>
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="debug">
<AppenderRef ref="FileException" level="ERROR"></AppenderRef>
</Root>
<Logger name="com.nv.custom" level="debug" additivity="false">
<AppenderRef ref="File" />
<AppenderRef ref="FileException" level="ERROR"></AppenderRef>
</Logger>
<Logger name="JSON_LOGGER" level="info" additivity="false">
<AppenderRef ref="customOnboarding" />
</Logger>
</Loggers>
Ниже приведен пользовательский файл конфигурации БД, используемый для настройки Конфигурации пружины JPA:
Пользовательский файл конфигурации БД:
@PersistenceContext(unitName = "custom")
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
@Qualifier("customDataSource") DataSource dataSource) {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
factoryBean.setPersistenceUnitName("custom");
factoryBean.setDataSource(dataSource);
factoryBean.setPackagesToScan("com.nv.custom.db.mktcustom.entities","com.nv.custom.onboarding.entity");
Properties jpaProperties = new Properties();
jpaProperties.put("hibernate.dialect", env.getRequiredProperty("custom.hibernate.dialect"));
jpaProperties.put("hibernate.hbm2ddl.auto", env.getRequiredProperty("custom.hibernate.hbm2ddl.auto"));
jpaProperties.put("spring.jpa.properties.hibernate.format_sql", env.getRequiredProperty("custom.hibernate.show_sql"));
jpaProperties.put("spring.jpa.properties.hibernate.show_sql", env.getRequiredProperty("custom.hibernate.format_sql"));
factoryBean.setJpaProperties(jpaProperties);
return factoryBean;
}