avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/logger/factory DatagramTargetFactory.java
Date Fri, 14 Dec 2001 21:35:29 GMT
donaldp     01/12/14 13:35:29

  Added:       src/java/org/apache/avalon/excalibur/logger/factory
                        DatagramTargetFactory.java
  Log:
  Add a factory for datagram log targets.
  
  Submitted By: Ghorpade, Rajendra <RGhorpade@onebridge.de>
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-excalibur/src/java/org/apache/avalon/excalibur/logger/factory/DatagramTargetFactory.java
  
  Index: DatagramTargetFactory.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.logger.factory;
  
  import java.io.IOException;
  import java.net.DatagramPacket;
  import java.net.DatagramSocket;
  import java.net.InetAddress;
  import java.net.UnknownHostException;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.log.LogEvent;
  import org.apache.log.LogTarget;
  import org.apache.log.format.ExtendedPatternFormatter;
  import org.apache.log.format.Formatter;
  import org.apache.log.format.PatternFormatter;
  import org.apache.log.format.RawFormatter;
  import org.apache.log.format.SyslogFormatter;
  import org.apache.log.output.net.DatagramOutputTarget;
  
  public class DatagramTargetFactory
      extends AbstractTargetFactory
  {
      private static final String FORMAT =
          "%7.7{priority} %5.5{time}   [%8.8{category}] (%{context}): %{message}\\n%{throwable}";
  
      public LogTarget createTarget( final Configuration conf )
          throws ConfigurationException
      {
          final Formatter formatter = getFormatter( conf.getChild( "format", false ) );
  
          final Configuration configChild = conf.getChild( "address", false );
          if ( null == configChild )
          {
              throw new ConfigurationException( "target address not specified in the config"
);
          }
  
          InetAddress address;
          try
          {
              address = InetAddress.getByName( configChild.getAttribute( "hostname" ) );
          }
          catch ( final UnknownHostException uhe )
          {
              throw new ConfigurationException( "Host specified in datagram target adress
is unknown!", uhe );
          }
  
          final int port = configChild.getAttributeAsInteger( "port" );
          try
          {
              return new DatagramOutputTarget( address, port, formatter );
          }
          catch ( final IOException ioe )
          {
              throw new ConfigurationException( "Failed to create target!", ioe );
          }
      }
  
      protected Formatter getFormatter( final Configuration conf )
      {
          final String type = conf.getAttribute( "type", "pattern" );
          final String format = conf.getValue( FORMAT );
  
          if( "extended".equals( type ) )
          {
              return new ExtendedPatternFormatter( format );
          }
          else if( "raw".equals( type ) )
          {
              return new RawFormatter();
          }
          else if( "syslog".equals( type ) )
          {
              return new SyslogFormatter();
          }
          else
          {
              return new PatternFormatter( format );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message