[ 
https://issues.apache.org/jira/browse/LOG4J2-747?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14094372#comment-14094372
 ] 

A B commented on LOG4J2-747:
----------------------------

If I don't add the log4j-web jar file, then it does goes back to its default 
configuration and prints ERROR and FATAL messages, but not other ones.

I checked for the classpath - this is a minimalist project with just the jars I 
had shown you in the screen-shot, no other jars anywhere in the classpath.

I knew I didn't need the sources, Just have a habit of adding sources, if I 
want to debug.  I removed the web sources jar from the project and now it seems 
to work.  

So, it appears that when I add the sources for log4j-web, the web-fragment from 
that source is probably scanned and considered a different web-fragment with 
teh same name and that generates an error.

This maybe something you may want to look at - or outline a way where people 
should add the sources if they want to debug...

I also tried by changing the name of the log4j config file - changing it from 
log4j2.xml to log4j2_env.xml which exists and log4j2_env2.xml which doesn't 
exist ( env is part of the name, not environment variable )

So, the observation is - if I define the log4jConfiguration and point it to an 
existing config file, that is used. If log4jConfiguration is pointing to 
non-existent file, the default is used.

Other observation is, using the sources jar along with the web jar ( or would 
be the case for any jar containing the web-fragment, it would happen ) will 
give duplicate web fragment error

I will now try using the actual environment variable sometime today and report 
the outcome here.  

Thanks for the suggestions and help you are providing


> Servlet Example of using different log4j2-{env:envValue}.xml
> ------------------------------------------------------------
>
>                 Key: LOG4J2-747
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-747
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.0-beta9
>         Environment: Websphere 8.5 Windows 7 
>            Reporter: A B
>         Attachments: LOG4J2-747_Jira.war, LOG4J2747_Jira_Sample3.ear, log4j2 
> location.jpg, log4j2-webapp-error.txt
>
>
> Based on my previous post / question on the log4j2 user list - Defining 
> different log4j2.xml configurations based on environment - 
> http://apache-logging.6191.n7.nabble.com/Defining-different-log4j2-xml-configurations-based-on-environment-tp40639p40662.html
>  - I was attempting to create a  Servlet Example of using different 
> log4j2-\{env:envValue\}.xml.  
> Based on the answers in this thread "Defining different log4j2.xml 
> configurations based on environment", from log4j user list I tried to test 
> using a different config for different environments. This is what I have done.
> * I defined a Windows env variable {{websphere_environment}} and set its 
> value to "local"
> * I specify the config location as log4j2-\{env:envValue\}.xml. My web.xml 
> context-param looks like below - servlet version is 3.0.
> {code}
> <context-param>
>     <param-name>log4jConfigLocation</param-name>
>     <param-value>/WEB-INF/config/log4j2-${env:websphere_environment}.xml
>     </param-value>
> </context-param>
> {code}
> My relevant servlet method looks like below
> {code}
> protected void doGet(HttpServletRequest request, HttpServletResponse 
> response) throws
>     ServletException, IOException {
>     Logger logger = Logger.getLogger(ServletLog4j2Test.class.getName());
>     logger.fatal("Loaded:);
>     //    " + /WEB-INF/config/log4j2-${env:websphere_environment}.xml
> }
> {code}
> I do not have the lo4j2-local.xml defined in the WEB-INF/config ( it is 
> defined as log4j-local.xml, not log4j2-local.xml and was expecting to get an 
> error but it seems that the servlet is using a default configuration, because 
> when I run the servlet, I get
> {code}
> "07/24/14 07:14:07:564:FATAL:WebContainer : 0:        :     
> :com.test.log4j2.ServletLog4j2Test: Loaded:"
> {code}
> How should my web-app and config files be set-up so that I can use different 
> configs for different environments based on the environment?
>  



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org
For additional commands, e-mail: log4j-dev-h...@logging.apache.org

Reply via email to