You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Thomas Dudziak <to...@gmail.com> on 2007/01/02 22:18:51 UTC

How to use Log4j in a mailet ?

Hi folks,

when I use Log4j in a mailet, then I get this error:

java.lang.NoSuchFieldError: level
        at org.apache.log4j.spi.RootLogger.setLevel(RootLogger.java:65)
        at org.apache.log4j.spi.RootLogger.<init>(RootLogger.java:44)
        at org.apache.log4j.LogManager.<clinit>(LogManager.java:78)
        at my.mailet.TestMailet.<clinit>(TestMailet.java:16)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:242)
        ...

Log4j is version 1.2.13 and it's jar is present. And AFAICT neither
James nor Phoenix does use log4j (another older log4j jar might
explain this error) ?

any idea ?
Tom

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


Re: How to use Log4j in a mailet ?

Posted by Thomas Dudziak <to...@gmail.com>.
On 1/2/07, Stefano Bagnara <ap...@bago.org> wrote:

> There should not be another log4j bundled with James.
> In 2.3.0 you can add your libraries to the
> <jamesfolder>/apps/james/SAR-INF/lib folder instead of placing them in
> the sar file (it should work).
>
> I see we have a log4j-core.jar in tools/lib. I don't know why it is
> there and what dependency need it. Maybe you can try to remove it.

It works in 2.2, so I'll stick to that for now (it's a pretty simple
mailet). I'll let you know when I have it working in 2.3.

cheers,
Tom

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


Re: How to use Log4j in a mailet ?

Posted by Stefano Bagnara <ap...@bago.org>.
Thomas Dudziak wrote:
> On 1/2/07, Stefano Bagnara <ap...@bago.org> wrote:
> 
>> In what folder did you placed the log4j library?
>>
>> Try both <jamesfolder>/lib OR <jamesfolder>/apps/james/lib
>>
>> A last try could be adding the log4j jar to the james.sar file (the sar
>> file is simply a jar/zip, renamed)
> 
> Since I have a custom mailet, I have a modified SAR file that contains
> log4j in SAR-INF/lib (together with the other jars of my mailet).
> And as can be seen from the stacktrace, the jar is found but something
> is wrong with the classloader. Or is there already a log4j jar
> somewhere in james/phoenix that I missed ?


There should not be another log4j bundled with James.
In 2.3.0 you can add your libraries to the 
<jamesfolder>/apps/james/SAR-INF/lib folder instead of placing them in 
the sar file (it should work).

I see we have a log4j-core.jar in tools/lib. I don't know why it is 
there and what dependency need it. Maybe you can try to remove it.

Stefano


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


Re: How to use Log4j in a mailet ?

Posted by Thomas Dudziak <to...@gmail.com>.
On 1/2/07, Stefano Bagnara <ap...@bago.org> wrote:

> In what folder did you placed the log4j library?
>
> Try both <jamesfolder>/lib OR <jamesfolder>/apps/james/lib
>
> A last try could be adding the log4j jar to the james.sar file (the sar
> file is simply a jar/zip, renamed)

Since I have a custom mailet, I have a modified SAR file that contains
log4j in SAR-INF/lib (together with the other jars of my mailet).
And as can be seen from the stacktrace, the jar is found but something
is wrong with the classloader. Or is there already a log4j jar
somewhere in james/phoenix that I missed ?

Tom

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


Re: How to use Log4j in a mailet ?

Posted by Stefano Bagnara <ap...@bago.org>.
Thomas Dudziak wrote:
> On 1/2/07, Stefano Bagnara <ap...@bago.org> wrote:
>> 1) You can make the whole phoenix to log over log4j and this will make
>> your "log" calls from the mailet to be logged by log4j too.
>> http://wiki.apache.org/james/log4j
> 
> Ah, yeah, that might be useful.
> 
>> 2) Are you using James 2.2.0 or James 2.3.0? The classloaders have
>> changed between the 2 versions.
> 
> It's 2.3. I'm currently checking whether it works in 2.2.


In what folder did you placed the log4j library?

Try both <jamesfolder>/lib OR <jamesfolder>/apps/james/lib

A last try could be adding the log4j jar to the james.sar file (the sar 
file is simply a jar/zip, renamed)

Stefano


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


Re: How to use Log4j in a mailet ?

Posted by Thomas Dudziak <to...@gmail.com>.
On 1/2/07, Stefano Bagnara <ap...@bago.org> wrote:
> 1) You can make the whole phoenix to log over log4j and this will make
> your "log" calls from the mailet to be logged by log4j too.
> http://wiki.apache.org/james/log4j

Ah, yeah, that might be useful.

> 2) Are you using James 2.2.0 or James 2.3.0? The classloaders have
> changed between the 2 versions.

It's 2.3. I'm currently checking whether it works in 2.2.

cheers,
Tom

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


Re: How to use Log4j in a mailet ?

Posted by Stefano Bagnara <ap...@bago.org>.
1) You can make the whole phoenix to log over log4j and this will make 
your "log" calls from the mailet to be logged by log4j too.
http://wiki.apache.org/james/log4j

2) Are you using James 2.2.0 or James 2.3.0? The classloaders have 
changed between the 2 versions.

Stefano

Thomas Dudziak wrote:
> Hi folks,
> 
> when I use Log4j in a mailet, then I get this error:
> 
> java.lang.NoSuchFieldError: level
>        at org.apache.log4j.spi.RootLogger.setLevel(RootLogger.java:65)
>        at org.apache.log4j.spi.RootLogger.<init>(RootLogger.java:44)
>        at org.apache.log4j.LogManager.<clinit>(LogManager.java:78)
>        at my.mailet.TestMailet.<clinit>(TestMailet.java:16)
>        at java.lang.Class.forName0(Native Method)
>        at java.lang.Class.forName(Class.java:242)
>        ...
> 
> Log4j is version 1.2.13 and it's jar is present. And AFAICT neither
> James nor Phoenix does use log4j (another older log4j jar might
> explain this error) ?
> 
> any idea ?
> Tom



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