Search code examples
javaspring-bootp6spy

Specify user's home directory in a .properties file


I am trying to integrate p6spy (3.x.x) in my project, and in spy.properties file, I wanted to specify

logfile=${user.home}/logs/spy-%d{yyyyMMdd}.log

or at least

logfile=${user.home}/logs/spy.log 

So far, I couldn't manage to do either, and the execution is failing with FileNotFoundException

java.io.FileNotFoundException: ${user.home}/logs/spy.log (No such file or directory) 

Mine is a Spring Boot project with collaborators running different operating systems. By default, it is creating the spy.log file in project root, which is not good.

Is it possible to specify relative paths like the way I want in .properties files? If yes, how?

Thanks a lot!


Solution

  • P6spy does not support placeholders. That's why ${user.home} is not recognized, you can try p6spy-spring-boot-starter from my library https://github.com/gavlyukovskiy/spring-boot-data-source-decorator that integrates p6spy into spring boot allowing you to use application.properties/yml where placeholders are supported instead of spy.properties.

    You should put this into your application properties: decorator.datasource.p6spy.logging=file decorator.datasource.p6spy.log-file=${user.home}/logs/spy.log

    But if you want to have rotating of the logs it's better to use slf4j and add custom appender to your logging library to capture only p6spy logs.