Mark,

Thanks, You are absolutely right.

 

So the Steps would be:

1. Declare an instance of Logger 

final static Logger logger =
Logger.getLogger(BasicConfiguratorExample2.class); 

General Case: <Logger> <instance Name of Logger> = <
Logger>.getLogger(<class Name to be Logged>.class);

 

2. Declare an Appender

ConsoleAppender a0 = new ConsoleAppender(new SimpleLayout());

 

General Case: <Appender> <instance Name of Appender> = new < Appender >(new
<layout()>);

 

3. Declare a Logger                   

Logger root = Logger.getRootLogger();

 

General Case: <Logger> <instance Name of Logger> = < Logger>.getLogger();

 

4. to call the activateOptions method on the consoleAppender before you are
able to use it

a0.activateOptions();

 

General Case: <Appender Instance>. activateOptions();

 

5. attach the Appender to the logger 

                                      root.addAppender(a0);

General Case: <Logger Instance>.addAppender(Appender Instance);

 

6. Start Using log4j.

logger.info ("Entering Application");

 

General Case: <Logger>.<Log Level>("text related to the log you want to
display");

 

The question is, is step 4 necessary? 

This is what Ceki says:

 

Appender instances must be activated before use

 

For all appenders except trivial ones, the activateOptions() method must be
called before an appender can be used. This is true for both log4j versions
1.2 as well 1.3.

However, in log4j 1.3, this contract is enforced by run-time checks. Thus,
if you forget to call activateOptions() method, AppenderSkeleton will refuse
to invoke the append() method of its derived classes.

Users who programmatically instantiate appenders, even appenders maintained
outside the log4j project, need to call the activateOptions() method after
they instantiate and set its options. This will ensures run-time
compatibility for log4j 1.2 as well as 1.3.

I am thinking that this discussion can be a good candidate for Journal
Logging Programming User Guide.

 

Thanks,

 

-Kamal.

 

-----Original Message-----
From: DeSantis, MJ Mark @ IS [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, February 15, 2006 9:05 AM
To: 'Log4J Users List'
Subject: RE: log4j:WARN No appenders could be found for logger 

 

I think you may have to call the activateOptions method on the

consoleAppender before you are able to use it. So:

 

ConsoleAppender a0 = new ConsoleAppender(new SimpleLayout());

a0.activateOptions();

root.addAppender(a0);

 

 

May do the trick

 

 

Mark

 

-----Original Message-----

From: Kamal Ahmed [mailto:[EMAIL PROTECTED] 

Sent: Tuesday, February 14, 2006 6:36 PM

To: Log4J Users List

Subject: log4j:WARN No appenders could be found for logger 

 

 

How do we resolve:

 

 

 

How do we resolve:

 

log4j:WARN No appenders could be found for logger

(com.webmethods.sc.logging.test.unit.WmLoggerFilterTest).

 

log4j:WARN Please initialize the log4j system properly.

 

 

 

Step 1: Declare an Appender, e.g.

 

ConsoleAppender a0 = new ConsoleAppender(new SimpleLayout());

 

 

 

Step2: Declare a Logger e.g.                   

 

Logger root = Logger.getRootLogger();

 

 

 

Step3: attach the Appender to the logger e.g.

 

                                      root.addAppender(a0);

 

 

 

                   

 

1.      Is this correct?

 

2.      Is this the only way?

 

Thanks,

 

-Kamal.

 

 

---------------------------------------------------------------------

To unsubscribe, e-mail: [EMAIL PROTECTED]

For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to