Reputation: 1339
We are developing a simple Java console application as a school project. In the beginning, I decided to use Flyway for database migrations as it looked like the easiest solution. I'm happy with the migrations per se but would like to suppress Flyway's console logging.
After googling this quite extensively, I cannot figure out how to get rid of the logging without messing with changing standard output. Should I do that or is there a better way to clean up our output? To me, this sounds like a problem that should have a simple switch somewhere that I just can't find...
Thank you!
EDIT: Here is the project in question: ohtu-ts (UI is in Finnish, but code in English)
Upvotes: 1
Views: 1673
Reputation: 4726
Use log4j to store logs in files
Classes to import
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Maven dependences
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
log4j properties file in
src/main/resources/log4j.properties
The file log4j.properties
log4j.rootLogger=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=logs/file_name_to_logs.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.file.MaxFileSize=5MB
Upvotes: 0
Reputation: 448
Flyway is designed to look for a compatible logging library on the classpath. If none are found, it falls back to its default logging behavior, which is what you're seeing here.
This isn't documented well because Flyway is typically used from a client, like the CLI, Maven, etc. The clients have their own mechanisms for handling logs. However you're taking a very manual approach.
Use SLF4J:
C:\jars
)java -cp C:\jars\* -jar ohtu-ts-all.jar
Flyway will pick up SLF4J and use it for logging. The NOP binding is a special implementation of SLF4J which suppresses all logs.
Looking at your code, you're pulling in Flyway Core as a dependency. Use the Gradle plugin instead. That way you can avoid such insane manual setup.
Upvotes: 1