KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > logger > factory > PriorityFilterTargetFactory


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.logger.factory;
9
10 import org.apache.avalon.excalibur.logger.LogTargetFactory;
11 import org.apache.avalon.excalibur.logger.LogTargetFactoryManageable;
12 import org.apache.avalon.excalibur.logger.LogTargetFactoryManager;
13 import org.apache.avalon.framework.configuration.Configuration;
14 import org.apache.avalon.framework.configuration.ConfigurationException;
15 import org.apache.avalon.framework.context.ContextException;
16 import org.apache.log.LogTarget;
17 import org.apache.log.Priority;
18 import org.apache.log.filter.PriorityFilter;
19
20 /**
21  * PriorityFilterTargetFactory class.
22  *
23  * This factory creates LogTargets with a wrapped PriorityFilter around it:
24  *
25  * <pre>
26  *
27  * &lt;priority-filter id="target-id" log-level="ERROR"&gt;
28  * &lt;any-target-definition/&gt;
29  * ...
30  * &lt;any-target-definition/&gt;
31  * &lt;/priority-filter&gt;
32  *
33  * </pre>
34  * <p>
35  * This factory creates a PriorityFilter object with a logging Priority set
36  * to the value of the log-level attribute (which defaults to INFO if absent).
37  * The LogTarget to filter is described in child elements of the configuration (in
38  * the sample above named as &lt;any-target-definition/&gt;).
39  * </p>
40  *
41  * @author <a HREF="mailto:giacomo@apache,org">Giacomo Pati</a>
42  * @version CVS $Revision: 1.3 $ $Date: 2001/12/11 09:53:30 $
43  * @since 4.0
44  */

45 public final class PriorityFilterTargetFactory
46     extends AbstractTargetFactory
47     implements LogTargetFactoryManageable
48 {
49     /** The LogTargetFactoryManager */
50     protected LogTargetFactoryManager m_logTargetFactoryManager;
51
52     /**
53      * create a LogTarget based on a Configuration
54      */

55     public final LogTarget createTarget( final Configuration configuration )
56         throws ConfigurationException
57     {
58         final String JavaDoc loglevel = configuration.getAttribute( "log-level", "INFO" );
59         getLogger().debug( "loglevel is " + loglevel );
60         final PriorityFilter filter = new PriorityFilter( Priority.getPriorityForName( loglevel ) );
61
62         final Configuration [] configs = configuration.getChildren();
63         for( int i = 0; i < configs.length; i++ )
64         {
65             final LogTargetFactory factory = m_logTargetFactoryManager.getLogTargetFactory( configs[i].getName() );
66             getLogger().debug( "creating target " + configs[i].getName() + ": " + configs[i].toString() );
67             final LogTarget logtarget = factory.createTarget( configs[i] );
68             filter.addTarget( logtarget );
69         }
70         return filter;
71     }
72
73     /**
74      * get the LogTargetFactoryManager
75      */

76     public final void setLogTargetFactoryManager( LogTargetFactoryManager logTargetFactoryManager )
77     {
78         m_logTargetFactoryManager = logTargetFactoryManager;
79     }
80
81 }
82
83
Popular Tags