Have you looked at http://logging.apache.org/log4j/2.x/manual/webapp.html? The
documentation there is missing one thing that will probably help you. You can
specify
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>file://etc/myApp/mylogging-${sys:region}.xml</param-value>
</context-param>
If you then set the region system property to "prod" you would use
mylogging-prod.xml.
Ralph
On Sep 11, 2013, at 4:21 AM, WebServices Development wrote:
> I had posted this on SO and was advised that it may be better to post this
> question on this list.
>
> I want to try and use logj2 in my web application. With log4j 1.x, we set-up
> different configurations files based on environment and use
> ServletContextListener to load the appropriate configuration using a call like
>
> DOMConfigurator.configureAndWatch(logConfigFile, delay);
>
> by passing the config file location.
>
> I was planning on doing the same for log4j2 config file but according to
> this<http://stackoverflow.com/questions/16716556/how-to-specify-log4j-2-x-config-location>
>
> (http://stackoverflow.com/questions/16716556/how-to-specify-log4j-2-x-config-location
> ) and
> this<http://stackoverflow.com/questions/16778986/log4j-only-can-view-error-level-on-my-java-enterprise-application-module-ejb-wi>
>
> (http://stackoverflow.com/questions/16778986/log4j-only-can-view-error-level-on-my-java-enterprise-application-module-ejb-wi
> ), it is not possible or advisable to use DOMConfigurator with log4j2.
>
> So, my question is: How can I use different configuration files based on
> environment with log4j2?
>
> I am not trying to have separate logfiles for each web application within an
> EAR, but a separate config file for each of the environments, so that, for
> example, I can have DEBUG in dev and UAT, but not in PROD or can have large
> file sizes in dev and uat, but not in prod. Like I mentioned in the question,
> what we do with version 1 is that we have, say, log4j-dev.xml, log4j-prod.xml
> etc. and have a servlet context listener and an env variable such that
> without making code changes, when I deploy the app to an env, it picks up
> correct config.
>
> Thank you
>
>
>
>
>
>
> -----------------------------------------
> This email transmission and any accompanying attachments may
> contain CSX privileged and confidential information intended only
> for the use of the intended addressee. Any dissemination,
> distribution, copying or action taken in reliance on the contents
> of this email by anyone other than the intended recipient is
> strictly prohibited. If you have received this email in error
> please immediately delete it and notify sender at the above CSX
> email address. Sender and CSX accept no liability for any damage
> caused directly or indirectly by receipt of this email.