You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by "billokara@gmail.com" <bi...@gmail.com> on 2017/09/27 21:04:24 UTC

issues with log4j-web.jar deployed location

Hi,

should log4j-web.jar be packaged in individual web app WEB-INF/lib or can it be deployed in tomcat/lib (to be shared by several web apps)?

Tested with log4j2 v2.6 and latest v2.9.1, and noticed that it seems to work either way when a webapp is first deployed. BUT if having a log4j2.xml configured like:

<Configuration monitorInterval="10" status="warn" verbose="true">
    <Appenders>
        <File name="APP_LOGFILE" fileName="logs/${web:contextPath}.log"/>
    </Appenders>


when the webapp, say, MyApp is loaded, it will correctly use the web:contextPath lookup and create a MyApp.log file. But after modifying the log4j2.xml log level, the configuration will get reloaded as expected, BUT then instead of logging to the original MyApp.log file, it will create a 
${web:contextPath}.log 
file and logging to that new file.

That problem only happens if the log4j2-web.jar file is put in tomcat/lib, instead of packaged in MyApp/WEB-INF/lib

So just want to confirm if log4j-web.jar should always be packaged in WEB-INF/lib?


thanks!
Bill



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: issues with log4j-web.jar deployed location

Posted by Ralph Goers <ra...@dslextreme.com>.
Yes, that is exactly what you want to do.

Ralph

> On Sep 27, 2017, at 3:12 PM, billokara@gmail.com wrote:
> 
> thanks a lot for the prompt reply and explanation! 
> 
> the reason for using the log4j-web is to have each webapp logs to it's own log file, thus the ${web:contextPath}.log. But packaging the log4j-web in the webapp/lib would make sense.
> 
> -Bill
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: issues with log4j-web.jar deployed location

Posted by "billokara@gmail.com" <bi...@gmail.com>.
thanks a lot for the prompt reply and explanation! 

the reason for using the log4j-web is to have each webapp logs to it's own log file, thus the ${web:contextPath}.log. But packaging the log4j-web in the webapp/lib would make sense.

-Bill

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: issues with log4j-web.jar deployed location

Posted by Ralph Goers <ra...@dslextreme.com>.
Matt, remember you can install log4j in tomcat’s lib directory to have tomcat use log4j and then each web app can also have its own log4j configuration. If the ClassLoaderContextSelector is working correctly this should work just fine.

Ralph

> On Sep 27, 2017, at 2:58 PM, Matt Sicker <bo...@gmail.com> wrote:
> 
> log4j-web.jar is for use inside a war file (so yes, WEB-INF/lib). If you
> install log4j globally in Tomcat's lib directory, you don't need to use
> log4j-web as the logging is managed server-wide. The web jar is mainly to
> hook up logging into the servlet container lifecycle itself which doesn't
> really apply to global usage (the JVM lifecycle is more relevant there
> which is the normal use case).
> 
> On 27 September 2017 at 16:04, billokara@gmail.com <bi...@gmail.com>
> wrote:
> 
>> Hi,
>> 
>> should log4j-web.jar be packaged in individual web app WEB-INF/lib or can
>> it be deployed in tomcat/lib (to be shared by several web apps)?
>> 
>> Tested with log4j2 v2.6 and latest v2.9.1, and noticed that it seems to
>> work either way when a webapp is first deployed. BUT if having a log4j2.xml
>> configured like:
>> 
>> <Configuration monitorInterval="10" status="warn" verbose="true">
>>    <Appenders>
>>        <File name="APP_LOGFILE" fileName="logs/${web:contextPath}.log"/>
>>    </Appenders>
>> 
>> 
>> when the webapp, say, MyApp is loaded, it will correctly use the
>> web:contextPath lookup and create a MyApp.log file. But after modifying the
>> log4j2.xml log level, the configuration will get reloaded as expected, BUT
>> then instead of logging to the original MyApp.log file, it will create a
>> ${web:contextPath}.log
>> file and logging to that new file.
>> 
>> That problem only happens if the log4j2-web.jar file is put in tomcat/lib,
>> instead of packaged in MyApp/WEB-INF/lib
>> 
>> So just want to confirm if log4j-web.jar should always be packaged in
>> WEB-INF/lib?
>> 
>> 
>> thanks!
>> Bill
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>> For additional commands, e-mail: log4j-user-help@logging.apache.org
>> 
>> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Re: issues with log4j-web.jar deployed location

Posted by Matt Sicker <bo...@gmail.com>.
log4j-web.jar is for use inside a war file (so yes, WEB-INF/lib). If you
install log4j globally in Tomcat's lib directory, you don't need to use
log4j-web as the logging is managed server-wide. The web jar is mainly to
hook up logging into the servlet container lifecycle itself which doesn't
really apply to global usage (the JVM lifecycle is more relevant there
which is the normal use case).

On 27 September 2017 at 16:04, billokara@gmail.com <bi...@gmail.com>
wrote:

> Hi,
>
> should log4j-web.jar be packaged in individual web app WEB-INF/lib or can
> it be deployed in tomcat/lib (to be shared by several web apps)?
>
> Tested with log4j2 v2.6 and latest v2.9.1, and noticed that it seems to
> work either way when a webapp is first deployed. BUT if having a log4j2.xml
> configured like:
>
> <Configuration monitorInterval="10" status="warn" verbose="true">
>     <Appenders>
>         <File name="APP_LOGFILE" fileName="logs/${web:contextPath}.log"/>
>     </Appenders>
>
>
> when the webapp, say, MyApp is loaded, it will correctly use the
> web:contextPath lookup and create a MyApp.log file. But after modifying the
> log4j2.xml log level, the configuration will get reloaded as expected, BUT
> then instead of logging to the original MyApp.log file, it will create a
> ${web:contextPath}.log
> file and logging to that new file.
>
> That problem only happens if the log4j2-web.jar file is put in tomcat/lib,
> instead of packaged in MyApp/WEB-INF/lib
>
> So just want to confirm if log4j-web.jar should always be packaged in
> WEB-INF/lib?
>
>
> thanks!
> Bill
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>


-- 
Matt Sicker <bo...@gmail.com>