1 8 package org.apache.avalon.excalibur.logger.factory; 9 10 import javax.servlet.ServletContext ; 11 import org.apache.avalon.framework.configuration.Configuration; 12 import org.apache.avalon.framework.configuration.ConfigurationException; 13 import org.apache.avalon.framework.context.ContextException; 14 import org.apache.log.LogTarget; 15 import org.apache.log.format.ExtendedPatternFormatter; 16 import org.apache.log.format.Formatter; 17 import org.apache.log.format.PatternFormatter; 18 import org.apache.log.format.RawFormatter; 19 import org.apache.log.output.ServletOutputLogTarget; 20 21 51 public final class ServletTargetFactory 52 extends AbstractTargetFactory 53 { 54 55 58 public final LogTarget createTarget( final Configuration configuration ) 59 throws ConfigurationException 60 { 61 final String contextkey = 62 m_configuration.getAttribute( "context-key", "servlet-context" ); 63 final ServletContext sctx; 64 65 final Configuration conf_format = configuration.getChild( "format" ); 66 final Formatter formatter = getFormatter( conf_format ); 67 68 try 69 { 70 sctx = (ServletContext ) m_context.get( contextkey ); 71 } 72 catch( final ContextException ce ) 73 { 74 throw new ConfigurationException( "Cannot find ServletContext object in " + 75 "application context", ce ); 76 } 77 78 return new ServletOutputLogTarget( sctx ); 79 } 80 81 protected Formatter getFormatter( final Configuration conf ) 82 { 83 Formatter formatter = null; 84 85 if ( null != conf ) 86 { 87 final FormatterFactory formatterFactory = new FormatterFactory(); 88 formatter = formatterFactory.createFormatter( conf ); 89 } 90 91 return formatter; 92 } 93 } 94 | Popular Tags |