Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I pass my logback.xml into my akka application as a system property?

I have an akka application which I wish to package as an uberjar. If I package my application, the logback.xml appears in the root of the jar, but when I start my application I get an error in the configuration log because "URL x is not of type file!" where x is a url which looks like

jar:file:/path/to/jar!logback.xml

(Error appears here https://github.com/qos-ch/logback/blob/master/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConfigurationWatchList.java#L90)

This is because the logback file is archived, and so cannot be accessed as a file, which is what logback is expecting. I'm fine with this because the logback config shouldn't feature in a jar because it can result in conflicts. What I want to do is package and run my application, passing in the logback.xml at runtime, e.g

java -Dlogback.configurationFile=/full/path/to/logback.xml -jar myapplication.jar

When run like this, the logging configuration falls back to the default and I end up with actor logs appearing in my console (It all works as expected when running through maven). Tell me what I'm missing :)

like image 434
Chironex Avatar asked Oct 31 '22 09:10

Chironex


1 Answers

Yes, it's not a good idea to package the logback.xml file into your fat jar. The intention it to have it be configured at runtime. If you are using sbt for assembling the jar, you can specify directories & files to not include by adding to unmanagedJars. For example:

unmanagedJars in Compile <++= baseDirectory map { dir => (dir ** "logback.xml").classpath }

Then you should be able to pass it in at runtime by including it after -cp (classpath) or -jar. For example:

java -jar -Dlogback.configurationFile=/full/path/to/logback.xml myapplication.jar

like image 97
Alex Ehrnschwender Avatar answered Nov 09 '22 10:11

Alex Ehrnschwender