DispatchAction and Log4j

View: New views
4 Messages — Rating Filter:   Alert me  

DispatchAction and Log4j

by NiJK :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm trying to get Log4j working with my application.

It works fine in all my classes when I add the line
private static Log log = LogFactory.getLog(ClassName.class);

However, a DispatchAction already has a logger defined. When I add this line to a DispatchAction I am receiving two lines of output instead of just the one. If I remove the line, I get no output at all.

I am forwarding commons-logging to log4j using
org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory

How do I configure the logger for a struts action?

Thanks.

Re: DispatchAction and Log4j

by Paul Benedict-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Since you're using log4j, you can configure any logger you want using
additional configuration.

log4j.logger.org.apache.struts=DEBUG

Paul

On Wed, Nov 11, 2009 at 6:49 AM, NiJK <n_kitching@...> wrote:

>
> I'm trying to get Log4j working with my application.
>
> It works fine in all my classes when I add the line
> private static Log log = LogFactory.getLog(ClassName.class);
>
> However, a DispatchAction already has a logger defined. When I add this line
> to a DispatchAction I am receiving two lines of output instead of just the
> one. If I remove the line, I get no output at all.
>
> I am forwarding commons-logging to log4j using
> org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.Log4jFactory
>
> How do I configure the logger for a struts action?
>
> Thanks.
> --
> View this message in context: http://old.nabble.com/DispatchAction-and-Log4j-tp26300684p26300684.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...


Re: DispatchAction and Log4j

by NiJK :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Paul,

Thanks for your reply.

My DispatchActions are classes of type myproject.myactions, for example.

Shouldn't I be able to add the line
log4j.logger.myproject.myactions.myaction=DEBUG
and have the level defined for this class alone?


Re: DispatchAction and Log4j

by Paul Benedict-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Loggers need to be referenced by the name passed into their constructor.

For example:
package org.something;
class A {
  protected static final log = Logger.createLogger(A.class);
}

package com.something;
class B extends A { }

The name of the logger is "org.something.A" (the class reference is a
shorthand). So you'll have to configure it by that.

Paul


On Mon, Nov 16, 2009 at 3:55 AM, NiJK <n_kitching@...> wrote:

>
> Paul,
>
> Thanks for your reply.
>
> My DispatchActions are classes of type myproject.myactions, for example.
>
> Shouldn't I be able to add the line
> log4j.logger.myproject.myactions.myaction=DEBUG
> and have the level defined for this class alone?
>
>
> --
> View this message in context: http://old.nabble.com/DispatchAction-and-Log4j-tp26300684p26369293.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@...
> For additional commands, e-mail: user-help@...
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...