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 Sigmond Hola <si...@gmail.com> on 2017/05/19 09:12:33 UTC

How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

We have a web project want to use log4j 2 for logging.

But after I add

   - log4j-api-2.x.jar
   - log4j-core-2.x.jar

to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not work.

I finally found out that there is a jar named activemq-all.jar under
WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.

Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
logging while both log4j and log4j 2 classes are in the classpath?

Thanks.

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Remko Popma <re...@gmail.com>.
Instead of activemq-all, use only the parts from activemq that you need (
https://mvnrepository.com/artifact/org.apache.activemq).

On Fri, May 19, 2017 at 6:12 PM, Sigmond Hola <si...@gmail.com> wrote:

> We have a web project want to use log4j 2 for logging.
>
> But after I add
>
>    - log4j-api-2.x.jar
>    - log4j-core-2.x.jar
>
> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not work.
>
> I finally found out that there is a jar named activemq-all.jar under
> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
>
> Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
> logging while both log4j and log4j 2 classes are in the classpath?
>
> Thanks.
>

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Sigmond Hola <si...@gmail.com>.
Hi Matt,

I think I have to replace activemq-all.jar with several nessesry jars,
because there are log4j v1 implementation in it, I found out it will try to
load log4j.properties(or xml) even after I add log4j2 binding for log4j v1:
log4j-1.2-api-2.x.jar in the classpath.

Bests.

On Thu, May 25, 2017 at 10:13 PM, Matt Sicker <bo...@gmail.com> wrote:

> I think that would depend on the servlet container you're using. I don't
> think there's a standard way to rearrange lib/ entries in a WAR file, so
> I'm assuming it'd be an extension. Another option might be to rename the
> activemq-all.jar file to something like z-activemq-all.jar so it comes last
> alphabetically? It's really implementation-dependent here. If you modify
> your build scripts, you could also unpack the activemq jar, remove log4j
> 1.x classes, then repackage them.
>
> On 25 May 2017 at 02:35, Sigmond Hola <si...@gmail.com> wrote:
>
> > Hi matt & Gary,
> >
> > How can I do this, then?
> >
> > Thanks.
> >
> >
> > On Mon, May 22, 2017 at 11:22 PM, Matt Sicker <bo...@gmail.com> wrote:
> >
> > > The best workaround in your scenario definitely sounds like rearranging
> > the
> > > classpath with log4j2 first.
> > >
> > > On 19 May 2017 at 21:33, Sigmond Hola <si...@gmail.com> wrote:
> > >
> > > > I dont like dependency on uber jar, also.
> > > > It's a old project that dont even using any build tools like maven.
> > > > I think I should refactoring it step by step, include replace the
> > > activemq
> > > > uber jar with several necessary jars.
> > > >
> > > > Thank u all for ur response.
> > > >
> > > > Best regards.
> > > >
> > > > On Sat, May 20, 2017 at 1:54 AM, Ralph Goers <
> > ralph.goers@dslextreme.com
> > > >
> > > > wrote:
> > > >
> > > > > Yuck.
> > > > >
> > > > > Ralph
> > > > >
> > > > > > On May 19, 2017, at 9:10 AM, Gary Gregory <
> garydgregory@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > You can also put all the Log4j 2 jars FIRST on the classpath.
> > > > > >
> > > > > > Gary
> > > > > >
> > > > > > On May 19, 2017 8:42 AM, "Ralph Goers" <
> ralph.goers@dslextreme.com
> > >
> > > > > wrote:
> > > > > >
> > > > > >> To be frank, uber jars like this that include other people’s
> stuff
> > > > are a
> > > > > >> terrible idea for exactly this reason. See
> > > > http://activemq.apache.org/
> > > > > >> initial-configuration.html <http://activemq.apache.org/
> > > > > >> initial-configuration.html>. It itemizes all the jars that are
> > > rolled
> > > > > >> into the uber jar.  You need to just use the individual
> > dependencies
> > > > you
> > > > > >> need.
> > > > > >>
> > > > > >> Ralph
> > > > > >>
> > > > > >>> On May 19, 2017, at 2:12 AM, Sigmond Hola <
> sigmund.god@gmail.com
> > >
> > > > > wrote:
> > > > > >>>
> > > > > >>> We have a web project want to use log4j 2 for logging.
> > > > > >>>
> > > > > >>> But after I add
> > > > > >>>
> > > > > >>>  - log4j-api-2.x.jar
> > > > > >>>  - log4j-core-2.x.jar
> > > > > >>>
> > > > > >>> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2
> > not
> > > > > work.
> > > > > >>>
> > > > > >>> I finally found out that there is a jar named activemq-all.jar
> > > under
> > > > > >>> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside
> > it.
> > > > > >>>
> > > > > >>> Since I cannot delete activemq-all.jar, so how can I use log4j
> 2
> > > for
> > > > > >>> logging while both log4j and log4j 2 classes are in the
> > classpath?
> > > > > >>>
> > > > > >>> Thanks.
> > > > > >>
> > > > > >>
> > > > >
> > > > >
> > > > >
> > > > > ------------------------------------------------------------
> > ---------
> > > > > 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>
> > >
> >
>
>
>
> --
> Matt Sicker <bo...@gmail.com>
>

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Matt Sicker <bo...@gmail.com>.
I think that would depend on the servlet container you're using. I don't
think there's a standard way to rearrange lib/ entries in a WAR file, so
I'm assuming it'd be an extension. Another option might be to rename the
activemq-all.jar file to something like z-activemq-all.jar so it comes last
alphabetically? It's really implementation-dependent here. If you modify
your build scripts, you could also unpack the activemq jar, remove log4j
1.x classes, then repackage them.

On 25 May 2017 at 02:35, Sigmond Hola <si...@gmail.com> wrote:

> Hi matt & Gary,
>
> How can I do this, then?
>
> Thanks.
>
>
> On Mon, May 22, 2017 at 11:22 PM, Matt Sicker <bo...@gmail.com> wrote:
>
> > The best workaround in your scenario definitely sounds like rearranging
> the
> > classpath with log4j2 first.
> >
> > On 19 May 2017 at 21:33, Sigmond Hola <si...@gmail.com> wrote:
> >
> > > I dont like dependency on uber jar, also.
> > > It's a old project that dont even using any build tools like maven.
> > > I think I should refactoring it step by step, include replace the
> > activemq
> > > uber jar with several necessary jars.
> > >
> > > Thank u all for ur response.
> > >
> > > Best regards.
> > >
> > > On Sat, May 20, 2017 at 1:54 AM, Ralph Goers <
> ralph.goers@dslextreme.com
> > >
> > > wrote:
> > >
> > > > Yuck.
> > > >
> > > > Ralph
> > > >
> > > > > On May 19, 2017, at 9:10 AM, Gary Gregory <ga...@gmail.com>
> > > > wrote:
> > > > >
> > > > > You can also put all the Log4j 2 jars FIRST on the classpath.
> > > > >
> > > > > Gary
> > > > >
> > > > > On May 19, 2017 8:42 AM, "Ralph Goers" <ralph.goers@dslextreme.com
> >
> > > > wrote:
> > > > >
> > > > >> To be frank, uber jars like this that include other people’s stuff
> > > are a
> > > > >> terrible idea for exactly this reason. See
> > > http://activemq.apache.org/
> > > > >> initial-configuration.html <http://activemq.apache.org/
> > > > >> initial-configuration.html>. It itemizes all the jars that are
> > rolled
> > > > >> into the uber jar.  You need to just use the individual
> dependencies
> > > you
> > > > >> need.
> > > > >>
> > > > >> Ralph
> > > > >>
> > > > >>> On May 19, 2017, at 2:12 AM, Sigmond Hola <sigmund.god@gmail.com
> >
> > > > wrote:
> > > > >>>
> > > > >>> We have a web project want to use log4j 2 for logging.
> > > > >>>
> > > > >>> But after I add
> > > > >>>
> > > > >>>  - log4j-api-2.x.jar
> > > > >>>  - log4j-core-2.x.jar
> > > > >>>
> > > > >>> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2
> not
> > > > work.
> > > > >>>
> > > > >>> I finally found out that there is a jar named activemq-all.jar
> > under
> > > > >>> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside
> it.
> > > > >>>
> > > > >>> Since I cannot delete activemq-all.jar, so how can I use log4j 2
> > for
> > > > >>> logging while both log4j and log4j 2 classes are in the
> classpath?
> > > > >>>
> > > > >>> Thanks.
> > > > >>
> > > > >>
> > > >
> > > >
> > > >
> > > > ------------------------------------------------------------
> ---------
> > > > 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>
> >
>



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

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Sigmond Hola <si...@gmail.com>.
Hi matt & Gary,

How can I do this, then?

Thanks.


On Mon, May 22, 2017 at 11:22 PM, Matt Sicker <bo...@gmail.com> wrote:

> The best workaround in your scenario definitely sounds like rearranging the
> classpath with log4j2 first.
>
> On 19 May 2017 at 21:33, Sigmond Hola <si...@gmail.com> wrote:
>
> > I dont like dependency on uber jar, also.
> > It's a old project that dont even using any build tools like maven.
> > I think I should refactoring it step by step, include replace the
> activemq
> > uber jar with several necessary jars.
> >
> > Thank u all for ur response.
> >
> > Best regards.
> >
> > On Sat, May 20, 2017 at 1:54 AM, Ralph Goers <ralph.goers@dslextreme.com
> >
> > wrote:
> >
> > > Yuck.
> > >
> > > Ralph
> > >
> > > > On May 19, 2017, at 9:10 AM, Gary Gregory <ga...@gmail.com>
> > > wrote:
> > > >
> > > > You can also put all the Log4j 2 jars FIRST on the classpath.
> > > >
> > > > Gary
> > > >
> > > > On May 19, 2017 8:42 AM, "Ralph Goers" <ra...@dslextreme.com>
> > > wrote:
> > > >
> > > >> To be frank, uber jars like this that include other people’s stuff
> > are a
> > > >> terrible idea for exactly this reason. See
> > http://activemq.apache.org/
> > > >> initial-configuration.html <http://activemq.apache.org/
> > > >> initial-configuration.html>. It itemizes all the jars that are
> rolled
> > > >> into the uber jar.  You need to just use the individual dependencies
> > you
> > > >> need.
> > > >>
> > > >> Ralph
> > > >>
> > > >>> On May 19, 2017, at 2:12 AM, Sigmond Hola <si...@gmail.com>
> > > wrote:
> > > >>>
> > > >>> We have a web project want to use log4j 2 for logging.
> > > >>>
> > > >>> But after I add
> > > >>>
> > > >>>  - log4j-api-2.x.jar
> > > >>>  - log4j-core-2.x.jar
> > > >>>
> > > >>> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not
> > > work.
> > > >>>
> > > >>> I finally found out that there is a jar named activemq-all.jar
> under
> > > >>> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
> > > >>>
> > > >>> Since I cannot delete activemq-all.jar, so how can I use log4j 2
> for
> > > >>> logging while both log4j and log4j 2 classes are in the classpath?
> > > >>>
> > > >>> Thanks.
> > > >>
> > > >>
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > 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>
>

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Matt Sicker <bo...@gmail.com>.
The best workaround in your scenario definitely sounds like rearranging the
classpath with log4j2 first.

On 19 May 2017 at 21:33, Sigmond Hola <si...@gmail.com> wrote:

> I dont like dependency on uber jar, also.
> It's a old project that dont even using any build tools like maven.
> I think I should refactoring it step by step, include replace the activemq
> uber jar with several necessary jars.
>
> Thank u all for ur response.
>
> Best regards.
>
> On Sat, May 20, 2017 at 1:54 AM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
> > Yuck.
> >
> > Ralph
> >
> > > On May 19, 2017, at 9:10 AM, Gary Gregory <ga...@gmail.com>
> > wrote:
> > >
> > > You can also put all the Log4j 2 jars FIRST on the classpath.
> > >
> > > Gary
> > >
> > > On May 19, 2017 8:42 AM, "Ralph Goers" <ra...@dslextreme.com>
> > wrote:
> > >
> > >> To be frank, uber jars like this that include other people’s stuff
> are a
> > >> terrible idea for exactly this reason. See
> http://activemq.apache.org/
> > >> initial-configuration.html <http://activemq.apache.org/
> > >> initial-configuration.html>. It itemizes all the jars that are rolled
> > >> into the uber jar.  You need to just use the individual dependencies
> you
> > >> need.
> > >>
> > >> Ralph
> > >>
> > >>> On May 19, 2017, at 2:12 AM, Sigmond Hola <si...@gmail.com>
> > wrote:
> > >>>
> > >>> We have a web project want to use log4j 2 for logging.
> > >>>
> > >>> But after I add
> > >>>
> > >>>  - log4j-api-2.x.jar
> > >>>  - log4j-core-2.x.jar
> > >>>
> > >>> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not
> > work.
> > >>>
> > >>> I finally found out that there is a jar named activemq-all.jar under
> > >>> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
> > >>>
> > >>> Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
> > >>> logging while both log4j and log4j 2 classes are in the classpath?
> > >>>
> > >>> Thanks.
> > >>
> > >>
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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>

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Sigmond Hola <si...@gmail.com>.
I dont like dependency on uber jar, also.
It's a old project that dont even using any build tools like maven.
I think I should refactoring it step by step, include replace the activemq
uber jar with several necessary jars.

Thank u all for ur response.

Best regards.

On Sat, May 20, 2017 at 1:54 AM, Ralph Goers <ra...@dslextreme.com>
wrote:

> Yuck.
>
> Ralph
>
> > On May 19, 2017, at 9:10 AM, Gary Gregory <ga...@gmail.com>
> wrote:
> >
> > You can also put all the Log4j 2 jars FIRST on the classpath.
> >
> > Gary
> >
> > On May 19, 2017 8:42 AM, "Ralph Goers" <ra...@dslextreme.com>
> wrote:
> >
> >> To be frank, uber jars like this that include other people’s stuff are a
> >> terrible idea for exactly this reason. See http://activemq.apache.org/
> >> initial-configuration.html <http://activemq.apache.org/
> >> initial-configuration.html>. It itemizes all the jars that are rolled
> >> into the uber jar.  You need to just use the individual dependencies you
> >> need.
> >>
> >> Ralph
> >>
> >>> On May 19, 2017, at 2:12 AM, Sigmond Hola <si...@gmail.com>
> wrote:
> >>>
> >>> We have a web project want to use log4j 2 for logging.
> >>>
> >>> But after I add
> >>>
> >>>  - log4j-api-2.x.jar
> >>>  - log4j-core-2.x.jar
> >>>
> >>> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not
> work.
> >>>
> >>> I finally found out that there is a jar named activemq-all.jar under
> >>> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
> >>>
> >>> Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
> >>> logging while both log4j and log4j 2 classes are in the classpath?
> >>>
> >>> Thanks.
> >>
> >>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Ralph Goers <ra...@dslextreme.com>.
Yuck.

Ralph

> On May 19, 2017, at 9:10 AM, Gary Gregory <ga...@gmail.com> wrote:
> 
> You can also put all the Log4j 2 jars FIRST on the classpath.
> 
> Gary
> 
> On May 19, 2017 8:42 AM, "Ralph Goers" <ra...@dslextreme.com> wrote:
> 
>> To be frank, uber jars like this that include other people’s stuff are a
>> terrible idea for exactly this reason. See http://activemq.apache.org/
>> initial-configuration.html <http://activemq.apache.org/
>> initial-configuration.html>. It itemizes all the jars that are rolled
>> into the uber jar.  You need to just use the individual dependencies you
>> need.
>> 
>> Ralph
>> 
>>> On May 19, 2017, at 2:12 AM, Sigmond Hola <si...@gmail.com> wrote:
>>> 
>>> We have a web project want to use log4j 2 for logging.
>>> 
>>> But after I add
>>> 
>>>  - log4j-api-2.x.jar
>>>  - log4j-core-2.x.jar
>>> 
>>> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not work.
>>> 
>>> I finally found out that there is a jar named activemq-all.jar under
>>> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
>>> 
>>> Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
>>> logging while both log4j and log4j 2 classes are in the classpath?
>>> 
>>> Thanks.
>> 
>> 



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


Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Gary Gregory <ga...@gmail.com>.
You can also put all the Log4j 2 jars FIRST on the classpath.

Gary

On May 19, 2017 8:42 AM, "Ralph Goers" <ra...@dslextreme.com> wrote:

> To be frank, uber jars like this that include other people’s stuff are a
> terrible idea for exactly this reason. See http://activemq.apache.org/
> initial-configuration.html <http://activemq.apache.org/
> initial-configuration.html>. It itemizes all the jars that are rolled
> into the uber jar.  You need to just use the individual dependencies you
> need.
>
> Ralph
>
> > On May 19, 2017, at 2:12 AM, Sigmond Hola <si...@gmail.com> wrote:
> >
> > We have a web project want to use log4j 2 for logging.
> >
> > But after I add
> >
> >   - log4j-api-2.x.jar
> >   - log4j-core-2.x.jar
> >
> > to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not work.
> >
> > I finally found out that there is a jar named activemq-all.jar under
> > WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
> >
> > Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
> > logging while both log4j and log4j 2 classes are in the classpath?
> >
> > Thanks.
>
>

Re: How can I use log4j 2 if there are both log4j and log4j 2 jars included in classpath?

Posted by Ralph Goers <ra...@dslextreme.com>.
To be frank, uber jars like this that include other people’s stuff are a terrible idea for exactly this reason. See http://activemq.apache.org/initial-configuration.html <http://activemq.apache.org/initial-configuration.html>. It itemizes all the jars that are rolled into the uber jar.  You need to just use the individual dependencies you need.

Ralph

> On May 19, 2017, at 2:12 AM, Sigmond Hola <si...@gmail.com> wrote:
> 
> We have a web project want to use log4j 2 for logging.
> 
> But after I add
> 
>   - log4j-api-2.x.jar
>   - log4j-core-2.x.jar
> 
> to WEB-INF/lib, and add log4j2.xml to WEB-INF/classes, log4j 2 not work.
> 
> I finally found out that there is a jar named activemq-all.jar under
> WEB-INF/lib, and it have classes of log4j (v1) and slf4j inside it.
> 
> Since I cannot delete activemq-all.jar, so how can I use log4j 2 for
> logging while both log4j and log4j 2 classes are in the classpath?
> 
> Thanks.