1 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.output.AsyncLogTarget; 18 19 53 public final class AsyncLogTargetFactory 54 extends AbstractTargetFactory 55 implements LogTargetFactoryManageable 56 { 57 58 protected LogTargetFactoryManager m_logTargetFactoryManager; 59 60 63 public final LogTarget createTarget( final Configuration configuration ) 64 throws ConfigurationException 65 { 66 final int queuesize = configuration.getAttributeAsInteger( "queue-size", -1 ); 67 final Configuration config = configuration.getChildren()[0]; 68 final LogTargetFactory factory = m_logTargetFactoryManager.getLogTargetFactory( config.getName() ); 69 final LogTarget target = factory.createTarget( config ); 70 final AsyncLogTarget asyncTarget; 71 if( queuesize == -1 ) 72 { 73 asyncTarget = new AsyncLogTarget( target ); 74 } 75 else 76 { 77 asyncTarget = new AsyncLogTarget( target, queuesize ); 78 } 79 80 final String priority = configuration.getAttribute( "priority", null ); 81 final int thread_priority; 82 if( "MIN".equalsIgnoreCase( priority ) ) 83 { 84 thread_priority = Thread.MIN_PRIORITY; 85 } 86 else if( "NORM".equalsIgnoreCase( priority ) ) 87 { 88 thread_priority = Thread.NORM_PRIORITY; 89 } 90 else if( "NORM".equalsIgnoreCase( priority ) ) 91 { 92 thread_priority = Thread.NORM_PRIORITY; 93 } 94 else 95 { 96 thread_priority = configuration.getAttributeAsInteger( "priority", 1 ); 97 } 98 final Thread thread = new Thread ( asyncTarget ); 99 thread.setPriority( thread_priority ); 100 thread.setDaemon( true ); 101 thread.start(); 102 return asyncTarget; 103 } 104 105 108 public final void setLogTargetFactoryManager( LogTargetFactoryManager logTargetFactoryManager ) 109 { 110 m_logTargetFactoryManager = logTargetFactoryManager; 111 } 112 113 } 114 115 | Popular Tags |