Thank you, Heri, for that answer. It works. However it does have one catch, the 
method needs to know the logger name. What i was trying out was:
   
  for (each logger mentioned in the log4j.xml) {
       for (each appender of the logger) {
        //get the appender information
       }
  }
   
  The code that you mentioned does the second part of listing the information 
of all appenders given a logger name. Can i somehow enhance it to implement the 
requirement mentioned above?
   
  Thanks again.
  -Jaikiran
  

Bender Heri <[EMAIL PROTECTED]> wrote:
  /**
* Finds the next appender with the given name within the hierarchie which is
* defined by the given Logger, incl. RootLogger
*   
* @param aLog the logger whose appender should be found.
* @param aAppenderName the name of the desired appender
* @return an array with two entries: entry[0] is the Logger to which the found
* appender is attached, entry[1] is the found Appender
* @throws Exception if no appender could be found
*/
public static Object[] getNextAppenderInHierarchie( Logger aLog, String 
aAppenderName )
throws Exception
{
Logger log = aLog;
String name = aLog.getName();
Appender a = null;

while ( ( a = log.getAppender( aAppenderName ) ) == null )
{
int i = name.lastIndexOf( '.' );

if ( i == -1 )
{
// the entire hierarchy was checked. Try also the root logger:
log = Logger.getRootLogger();
a = log.getAppender( aAppenderName );

if ( a == null )
{
throw new Exception( new StringBuffer( "appender " )
.append( aAppenderName )
.append( " not found for logger " )
.append( aLog.getName() ).toString() );
} // if a == null

break;
} // if name.length() == 0

name = name.substring( 0, i );

log = Logger.getLogger( name );
} // while ( ( a = aLog.getAppender( "DB_APPENDER" ) ) == null )

Object[] result = new Object[2];
result[0] = log;
result[1] = a;

return result;

}

With this method you can only find the appender CONSOLE because you didn't 
attacht the appender FILE to any logger.

Heri


> -----Original Message-----
> From: jaikiran pai [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, July 04, 2006 12:03 PM
> To: log4j-user@logging.apache.org
> Subject: Get all appenders configured in log4j - Possible?
> 
> 
> Is there some way (API), through which i can get a collection 
> of appenders that have been mentioned(configured) through 
> log4j config files? Consider the following log4j.xml:
> 
> ----------------------------------------------------------------
> 
> 
> > xmlns:log4j="http://jakarta.apache.org/log4j/"; debug="false">
> 
> > class="org.jboss.logging.appender.RollingFileAppender">
> > class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
> 
> value="${jboss.server.home.dir}/log/server.log"/>
> 
> 
> [%X{TAPUSERNAME}] %-5p [%c] %m%n" name="ConversionPattern" />
> 
> 
> > class="org.apache.log4j.ConsoleAppender">
> > class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
> 

> 

> 
> > [Category] Message\n -->
> 
> [%X{TAPUSERNAME}] %-5p [%c{1}] %m%n" name="ConversionPattern" />
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ----------------------------------------------------------------
> 
> Can i get a collection containing the instances of appender 
> named "FILE" and "CONSOLE" in the above case?
> 
> regards,
> -Jaikiran
> 
> 
> 
> ---------------------------------
> Yahoo! India Answers: Share what you know. Learn something 
> new Click here
> Catch all the FIFA World Cup 2006 action on Yahoo! India Click here
> 

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




                                
---------------------------------
 Yahoo! India Answers: Share what you know. Learn something new Click here
Catch all the FIFA World Cup 2006 action on Yahoo! India Click here

Reply via email to