gavlyukovskiy/spring-boot-data-source-decorator

unable to follow readme.

Closed this issue · 1 comments

If I create repository like:
public interface ContactRepository extends CrudRepository<JpaContact, UUID>

and call save on it, only selects are logged. Selects are related to entityManager.merge, which are fired regardless of JpaContact being annotated by @SelectBeforeUpdate(false) ), inserts inserts data into DB, but are not logged.

Ok, but I don't want selects, which shouldn't be invoked anyways. So I will do:


@Repository
@Transactional
public class ContactRepository {

    @PersistenceContext
    private EntityManager entityManager;

public void persist(JpaContact contact) {
        entityManager.persist(contact);
    }
}

and then selects aren't correctly invoked, but only tx commit is logged by p6spy.

settings:

spring.jpa.database=POSTGRESQL
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=validate

#log4j.logger.org.hibernate=TRACE
#log4j.logger.org.hibernate.type=TRACE
#log4j.logger.org.hibernate.SQL=TRACE
#logging.level.org.hibernate=TRACE
#logging.level.org.hibernate.type=TRACE
#logging.level.org.hibernate.SQL=TRACE

spring.datasource.url = jdbc:postgresql://localhost:5432/postgres
spring.datasource.driver-class-name = org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=postgres

#---------
#hibernate.jdbc.batch_size=5
#hibernate.order_inserts=true
#hibernate.order_updates=true
#hibernate.jdbc.batch_versioned_data=true
#spring.jpa.hibernate.jdbc.batch_size=5
#spring.jpa.hibernate.order_inserts=true
#spring.jpa.hibernate.order_updates=true
#spring.jpa.hibernate.jdbc.batch_versioned_data=true
spring.jpa.properties.hibernate.jdbc.batch_size=5
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true


#-------------
# Register RuntimeListenerSupportFactory if JdbcEventListener beans were found
decorator.datasource.p6spy.enable-runtime-listeners=true
# Register P6LogFactory to log JDBC events
decorator.datasource.p6spy.enable-logging=true
# Use com.p6spy.engine.spy.appender.MultiLineFormat instead of com.p6spy.engine.spy.appender.SingleLineFormat
decorator.datasource.p6spy.multiline=true
# Use logging for default listeners [slf4j, sysout, file]
decorator.datasource.p6spy.logging=file
# Log file to use (only with logging=file)
decorator.datasource.p6spy.log-file=/tmp/spy.log
# Custom log format, if specified com.p6spy.engine.spy.appender.CustomLineFormat will be used with this log format
#decorator.datasource.p6spy.log-format=

decorator.datasource.datasource-proxy.query.enable-logging=true
decorator.datasource.datasource-proxy.query.log-level=warn
# Logger name to log all queries, default depends on chosen logging, e.g. net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener
decorator.datasource.datasource-proxy.query.logger-name=p6spy

also selects does not log into console, but only into the file, spy.properties is ignored altogether ... I'm really confused what should be configured, where and how.

Hi, as far as I know you can't have output in file and console at the same time. But you can define custom JdbcEventListener or SimpleJdbcEventListener as a bean and log queries you want.

Regarding spy.properties they are merged with the properties you have defined in application.properties, so if you defined some logging properties there, e.g. appender, then value from decorator.datasource.p6spy.logging will not be taken.

BTW properties decorator.datasource.datasource-proxy.* don't affect p6spy and applicable only if you're running with datasource-proxy.