Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share logback.xml between projects

I have a couple projects and I'm wondering the best way to share logback configurations between them. The setup looks something like this:

Physical Machine 1
    Project 1
    Project 2
    Project 3

Physical Machine 2
    Project 1
    Project 4

To avoid duplication, I don't want to stick a logback.xml in each projects resources directory. Should I bundle the logback.xml as another project and make it a dependency for each of the projects? Or just place it somewhere on the hard drive and have each project read in the logback.xml on startup? Or something else?

Also for development, they are all in the same JVM, so sharing a logback-test.xml and not reading from disk would be nice.

like image 211
yellavon Avatar asked Nov 16 '25 05:11

yellavon


2 Answers

I generally bundle configuration files as a standalone project so that it can be used across multiple projects.

I think the principal argument relies on versionning and how easy it's going to be if it's a dependency. On the file system you'd have to keep several versions of the file in subdirectories and it could quickly become messy.

If you're using Maven, here's a link which could help you.

like image 65
Javier92 Avatar answered Nov 17 '25 19:11

Javier92


Here is the Logback Configuratrion Chapter in the online manual.

When Logback is starting up, it attempts to load a logback configuration file from the classpath.

A solution to your question is to store the shared logback.xml file in a directory that is in the classpath of each of the projects.

like image 44
DwB Avatar answered Nov 17 '25 20:11

DwB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!