how do I suppress a inherited projects logback.xml file (2 logback.xml in a single project)?
As far as I'm concerned, you should never package a logging config file (logback.xml, log4j.properties, or what have you) inside a JAR file. The whole point of even having a logging config file is to make it easy for the end-user to adjust logging levels by editing the file. Burying it in an archive defeats the purpose of that, because to change the logging level your user has to expand the archive, edit the file, and then re-package the archive.
Here's my preferred layout for a deployed application. It's a little bit more work to set up, but IMO is worth the trouble because it gives you the flexibility and ease of configuration that an uberjar doesn't.
my-app/
bin/
run-app.sh
config/
logback.xml
lib/
my-lib.jar
my-app.jar
Your run-app.sh
script would look something like:
BIN=`dirname "$0"`
BASE=$BIN/..
java -cp "$BASE/config:$BASE/lib/*" my-app.main
This has the advantage that, by putting the config directory at the front of the classpath, any logging config file found there should take precedence over anything that might be found in one of the JARs (e.g. included by a third-party library that you have no control over).
In case the base is a library it should not come with a logback.xml. Why is a library concerned about logging? In case it is an application, you should probably extract the common part into a library – base-common – and a small application – base-app. Then base-common does not contain any logback configuration. base-app and derive both depend on base-common. They can specify their logback configuration without conflict.
I wanted to answer my own question because I was specifically asking in the context of Clojure (although I completely failed to mention that in originating question, genius).
I fixed the problem by doing as Alex (accepted answer) suggest, and putting my logback.xml in its own special directory dev-config
. I then use clojure's project.clj
file to specify that dev-config
should only be loaded when the development profile is run, as follows:
;; project.clj
(defproject com.samedhi/base.app "0.0.1-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]]
:profiles {:dev {:source-paths ["dev", "dev-config"]}}
:min-lein-version "2.0.0"
:source-paths ["app/src" "app/templates"]
:resource-paths ["config"]
:target-path "out/"
:compiler-options {:externs ["app/externs/base.js"]}
:aliases {"dumbrepl" ["trampoline" "run" "-m" "clojure.main/main"]})
The only important point is that :profiles => :dev => :source-paths has had "dev-config" added to its vector. This directory is picked up when I am doing local development, but is not part of created jar files, and as such does not show up in other projects that import this project. So, the logging shows up when doing development on this project, but does not show up when this project is used by other projects. Excellent.