logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bender Heri" <HBen...@Ergonomics.ch>
Subject RE: [SPAM (Bayesain Analysis)] - RE: Programmatically change properties of an appender - Bayesian Filter detected spam
Date Wed, 16 Aug 2006 11:30:24 GMT
The problem is to find the appender instance. Remember that log4j holds the instantiated loggers
within a hierarchy based on the logger name where the '.' describes a new level of the hierarchy.
If you configure a logger i.e. com.foo.bar.MyPackage and assign an appender to it (=Logger
A), and then you retrieve by code a logger with name com.foo.bar.MyPackage.MyClass (=Logger
B), then the situation is as following:

Logger A was instatiated when configuring the logger framework and the appender is attached
to it. Logger B will only be instantiated at the moment when you call Logger.getLogger( "com.foo.bar.MyPackage.MyClass"
). But this logger has no appender attached. It searches the correct appender upwards in the
hierarchy.

The following helper method finds the correct appender of any arbitrary logger:


    /**
     * Finds the next appender with the given name within the hierarchie which is
     * defined by the given Logger, incl. RootLogger
     * <p>
     * @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;
        
    }

> -----Original Message-----
> From: Levy, Jeremy [mailto:Jeremy.Levy@morganstanley.com]
> Sent: Monday, July 24, 2006 3:33 PM
> To: Log4J Users List
> Subject: [SPAM (Bayesain Analysis)] - RE: Programmatically change
> properties of an appender - Bayesian Filter detected spam
> 
> 
> What I have done for the moment is set the values I want to replace as
> ${xxx.xxx} in my layout and change the corresponding System Property.
> However I would think there is a cleaner way to do this..
> 
> j
> 
> -----Original Message-----
> From: James Stauffer [mailto:stauffer.james@gmail.com] 
> Sent: Friday, July 21, 2006 3:55 PM
> To: Log4J Users List
> Subject: Re: Programmatically change properties of an appender
> 
> I am 90% sure the answer it yes but I don't know exactly which methods
> you need to call to get the appender.
> 
> On 7/21/06, Levy, Jeremy <Jeremy.Levy@morganstanley.com> wrote:
> > I would like to change the subject and the from address of a 
> > smtpappender programmatically that is initially configured via a 
> > properties file, is this possible?
> >
> > j
> >
> >
> >
> > --------------------------------------------------------
> >
> > Important Notice to Recipients:
> > It is important that you do not use e-mail to request, authorize or
> effect the purchase or sale of any security or commodity, to send fund
> transfer instructions, or to effect any other transactions. Any such
> request, orders, or instructions that you send will not be 
> accepted and
> will not be processed by Morgan Stanley.
> >
> >
> 
> 
> --
> James Stauffer
> Are you good? Take the test at http://www.livingwaters.com/good/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>  
>  
>  
> --------------------------------------------------------
> 
> Important Notice to Recipients:
> It is important that you do not use e-mail to request, 
> authorize or effect the purchase or sale of any security or 
> commodity, to send fund transfer instructions, or to effect 
> any other transactions. Any such request, orders, or 
> instructions that you send will not be accepted and will not 
> be processed by Morgan Stanley.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 

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


Mime
View raw message