logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "A B (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (LOG4J2-747) Servlet Example of using different log4j2-{env:envValue}.xml
Date Sun, 10 Aug 2014 17:22:11 GMT

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

A B edited comment on LOG4J2-747 at 8/10/14 5:20 PM:
-----------------------------------------------------

I will try to answer for both the comments above

I also downloaded the 2.0.1 jars to test with for this

I could not get <param-value>/WEB-INF/config/log4j2.xml</param-value> to work.
  I am adding only the  log4jConfiguration context param

	<context-param>
		<param-name>log4jConfiguration</param-name>
		<param-value>/WEB-INF/config/log4j2.xml</param-value>
	</context-param>

I wasn't sure, reading from the documentation that when I want to use the non-default location
/ filename for a servlet 3.0 web-app, whether I need to define other context params as well.
 From the documentation it appeared that if I set isLog4jAutoInitializationDisabled=true,
then only I need to define the contextinitializer and filter.  Is my understanding correct
or wanting to define a non-default configuration file, in itself mandates defining the other
context params as well.

If I do need to define the other params, will you please let me know what I MUST define in
my web.xml to make this work?

For Standalone, I was able to use a config that was named differently from log4j2.xml or log4j2-test.xml.
 Using the environment variable in the system parameter for standalone - like thus - log4j.configurationFile=file:///Z:\\RAD85_WS\\ITWeb\\Log4jSamplesStandAlone\\log4j2config\\log4j2_${env:websphere_environment}.xml
- generates an error, maybe I need to pass the parameter in a different way for this?

I do not have access to other web containers, so haven't tested it against them.

Please let me know, if I am doing something wrong, or missing some required set-ups. 

Also, please let me know, how I could add formatting to my response so that they are legible.
 

Thanks,



was (Author: adbdkb):
I will try to answer for both the comments above

I also downloaded the 2.0.1 jars to test with for this

I could not get <param-value>/WEB-INF/config/log4j2.xml</param-value> to work.
  I am adding only the  log4jConfiguration context param

<code>
	<context-param>
		<param-name>log4jConfiguration</param-name>
		<param-value>/WEB-INF/config/log4j2.xml</param-value>
	</context-param>
<code>
I wasn't sure, reading from the documentation that when I want to use the non-default location
/ filename for a servlet 3.0 web-app, whether I need to define other context params as well.
 From the documentation it appeared that if I set isLog4jAutoInitializationDisabled=true,
then only I need to define the contextinitializer and filter.  Is my understanding correct
or wanting to define a non-default configuration file, in itself mandates defining the other
context params as well.

If I do need to define the other params, will you please let me know what I MUST define in
my web.xml to make this work?

For Standalone, I was able to use a config that was named differently from log4j2.xml or log4j2-test.xml.
 Using the environment variable in the system parameter for standalone - like thus - log4j.configurationFile=file:///Z:\\RAD85_WS\\ITWeb\\Log4jSamplesStandAlone\\log4j2config\\log4j2_${env:websphere_environment}.xml
- generates an error, maybe I need to pass the parameter in a different way for this?

I do not have access to other web containers, so haven't tested it against them.

Please let me know, if I am doing something wrong, or missing some required set-ups. 

Also, please let me know, how I could add formatting to my response so that they are legible.
 

Thanks,


> 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
>
>
> 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-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message