3

I'm dealing with 2 WAR applications (let's call them app1.war and app2.war) deployed in a tomcat7 environment. Through the setenv.sh I'm extending the classpath to a shared folder located in /opt/configurations.

I'd like to structure my configurations this way: configurations/ ├── app1.properties ├── app2.properties ├── logback-app1.xml └── logback-app2.xml

How do I tell to each application to read different logback*.xml files from the shared classpath? In other words, how do I tell app1.war to read only logback-app1.xml and app2.war to read only logback-app2.xml.

ecostanzi
  • 240
  • 1
  • 8
  • 19

1 Answers1

0

There is an answer to this question here : http://vtanase.blogspot.com/2012/07/how-to-create-different-logback.html

The point is to use a different JNDI entry declared in each web.xml

<env-entry>
  <env-entry-name>logback/configuration-resource</env-entry-name>
  <env-entry-type>java.lang.String</env-entry-type>
  <env-entry-value>app1/logback.xml</env-entry-value>
</env-entry>

and add a property for logback to look JNDI :

JAVA_OPTS="$JAVA_OPTS -Dlogback.ContextSelector=JNDI"

If the problem was to separate the resulting logging file for each war, there is an other way to achieve this with one single logback.xml using SiftingAppender. Examples can be found :

Community
  • 1
  • 1
Stephane L
  • 2,879
  • 1
  • 34
  • 44
  • Is there a way to do this with annotations? – Pytry Jul 06 '17 at 22:07
  • I don't know a way to configure it with annotations, but if you want to get rid of the web.xml, you can try the java config, there is an exemple here : https://stackoverflow.com/questions/16910955/programmatically-configure-logback-appender . – Stephane L Jul 11 '17 at 08:46