logback.xml being picked up twice in project (how do I surpess the inheritted projects logback.xml)?

5,246 views
Skip to first unread message

Stephen Cagle

unread,
Aug 15, 2013, 6:51:04 PM8/15/13
to clo...@googlegroups.com
I have project 'base' that has a logback.xml file and project 'derive' that also has a logback.xml file. Project 'derive' has a dependency on 'base'. When I "lein trampoline repl" on project 'derive', I get the following warning.

....
15:34:30,066 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
15:34:30,066 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
15:34:30,066 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/home/stephen/Work/com.samedhi/derive/client/config/logback.xml]
15:34:30,067 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs multiple times on the classpath.
15:34:30,067 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [jar:file:/home/stephen/.m2/repository/com/samedhi/base.app/0.0.1-SNAPSHOT/base.app-0.0.1-SNAPSHOT.jar!/logback.xml]
15:34:30,067 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml] occurs at [file:/home/stephen/Work/com.samedhi/derive/client/config/logback.xml]
15:34:30,129 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
....

So, the problem appears to be that I have two logback.xml's in my classpath. What am I supposed to do to "surpress" the logback.xml from project 'base'?

Jason Bennett

unread,
Aug 15, 2013, 7:38:01 PM8/15/13
to clo...@googlegroups.com
You shouldn't include the logback.xml in the generated jar file.

Only the ultimately generated artifact should have a logback.xml file, best loaded from the file system (possibly through -D). It doesn't matter what settings base has for logging, derive should set all logging parameters.

jason

Stephen Cagle

unread,
Aug 15, 2013, 8:06:37 PM8/15/13
to clo...@googlegroups.com
I don't know what -D is, other than a one eyed laughing face. :D

Is there some sort of standard for this? Do people simply write a script that checks out the code and remove files that they don't want in the generated jar? Is there something I can put in my project.clj that specifies what I don't want included in a generated jar? How do people generally go about it. 

Not that it is a big deal, mind you. It just seems a bit busy to have to write a special script that 1) checks out my code from github 2)removes the files I don't want in the jar 3) builds the jar 4) does whatever else I am forgetting. Seems like there might be something simpler that I don't know about.

Jason Bennett

unread,
Aug 15, 2013, 8:16:24 PM8/15/13
to clo...@googlegroups.com
The trick is, don't build the original jar with the logback config file. No dependent of that jar wants to be told how to do logging. You should keep your logback.xml in the /config directory, not in /resources.

As far as -D, that's to pass environment parameters to the JVM. See http://logback.qos.ch/manual/configuration.html#configFileProperty for how to configure the logback.xml location that way.

To recap: don't include logback.xml in any jars, anywhere (except for test versions, which logback supports). Have it living in production on the file system, and point to that file on startup. That way, you can have environment-specific logging configured in that environment.

jason



--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/jeVTo0aWWb4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jason Bennett, jas...@acm.org
E pur si muove!
Get Firefox! - http://getfirefox.com

Stephen Cagle

unread,
Aug 15, 2013, 8:31:58 PM8/15/13
to clo...@googlegroups.com, jas...@acm.org
Sorry if I am being dense, just want to make sure I understand what you are saying...

So, I was including logback.xml in my git source control. I take it you would say that is a bad idea? I thought it made sense as I then have it as part of the project, but I suppose it could get in the way in situations like this. Do you gitignore your logback.xml and just have a custom logback.xml specified with "logback.configurationFile" for different aspects (development, testing, production)?

Laurent PETIT

unread,
Aug 16, 2013, 2:39:19 AM8/16/13
to clo...@googlegroups.com, jas...@acm.org
2013/8/16 Stephen Cagle <sam...@gmail.com>:
> Sorry if I am being dense, just want to make sure I understand what you are
> saying...
>
> So, I was including logback.xml in my git source control. I take it you
> would say that is a bad idea? I thought it made sense as I then have it as
> part of the project, but I suppose it could get in the way in situations
> like this. Do you gitignore your logback.xml and just have a custom
> logback.xml specified with "logback.configurationFile" for different aspects
> (development, testing, production)?

A simple configuration idea (supposing you are using leiningen for
projects base and derive, and that you own both projects so you can
make changes to both).

base plays the role of a "library". A library should not impose
logging settings on the final products that will use it. But you still
need a logging file to test the library ! Just put a logback-test.xml
file in your dev-resources directory. It's fine to have it in git,
then, since it won't be part of the final jar now, it's all that
matters.

You do this for each "library" in your application.

For the final product, the one you deliver, you can just have 2
configurations, one for test, one while developing:

- place a file logback-test.xml in dev-resources. When it is present,
it will be picked first, meaning it will be picked first in your local
machine.
- place the production file logback.xml in resources.

This is a simple settings. It doesn't handle the case where you want
different logback.xml files for test, staging and prod servers, for
instance. YMMV.
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Stephen Cagle

unread,
Aug 17, 2013, 3:41:06 PM8/17/13
to clo...@googlegroups.com, jas...@acm.org
Thanks Laurent, I did as you suggest and things seem to be fine now. I ended up using :profiles => :dev  => :source-paths in my project.clj to include the 'dev-resources' directory. Seems to be in use when I lein repl, but is not included when I build a jar. Probably there are other problems with that, but it seems to work well enough for me.
Reply all
Reply to author
Forward
0 new messages