I have several executable classes and I would like to automatically set the log filename to the name of the Java class being executed.
I know I could do this programmatically, probably using Reflection and MDC
, but isn't there an easier way to achieve this by configuring logback.xml
?
This seems a rather basic need to me, so I am surprised I could not find documentation about it.
If you're on a JVM that supports it you can use this property
<file>${sun.java.command}.log</file>
Otherwise you need to set a similar system property in all your main
methods that logback can use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With