How to create Spring Boot logs in standalone project deployed on windows?

247 Views Asked by At

I am using following to execute spring and creating logs

java -jar AhMachine-0.0.1-SNAPSHOT.jar > c:\log.txt

but this creates a single log for lifetime.

Is there any way to split this log via commandline or spring boot?

2

There are 2 best solutions below

2
On BEST ANSWER

java -jar AhMachine-0.0.1-SNAPSHOT.jar > c:\log.txt will pipe the console output to a file

java -jar -Dlogging-file=c:\log.txt AhMachine-0.0.1-SNAPSHOT.jar will output the internal configurated file appenders to a file

java -jar -Dlogging-file=c:\log.txt -Dlogging.file.max-size=4KB AhMachine-0.0.1-SNAPSHOT.jar will output the internal configurated file appenders to a file will create log.txt files of max 4KB in size, a .gz file is created of the older files

For more complex configuration I would advise using a config-file like spring-logback.xml, you can easily specify the location of that file via the CLI -Dlogging.config=c:/log/config/spring-logback.xml

0
On

Not via command line, this can all be done inside the jar via rolling file appender:

https://www.baeldung.com/java-logging-rolling-file-appenders

If you cannot access the Jar no matter what see this comment:

https://stackoverflow.com/a/53395247/3942132

I haven't tested it but there should be a rotatelogs.exe process for windows as well.