1 17 package org.apache.log.output.test; 18 19 import java.net.InetAddress ; 20 import org.apache.log.Hierarchy; 21 import org.apache.log.LogTarget; 22 import org.apache.log.Logger; 23 import org.apache.log.format.Formatter; 24 import org.apache.log.format.RawFormatter; 25 import org.apache.log.format.SyslogFormatter; 26 import org.apache.log.output.net.DatagramOutputTarget; 27 28 32 public final class DatagramTest 33 { 34 public static void main( final String [] args ) 35 { 36 try 37 { 38 Formatter formatter = null; 39 String message = null; 40 41 if( 0 == args.length ) 42 { 43 formatter = new SyslogFormatter( SyslogFormatter.FACILITY_DAEMON ); 44 message = "hello!!!"; 45 } 46 else 47 { 48 formatter = new RawFormatter(); 52 message = args[ 0 ]; 53 } 54 55 final InetAddress address = InetAddress.getByName( "localhost" ); 56 final DatagramOutputTarget target = 57 new DatagramOutputTarget( address, 514, formatter ); 58 59 final Logger logger = Hierarchy.getDefaultHierarchy().getLoggerFor( "foo" ); 60 logger.setLogTargets( new LogTarget[]{target} ); 61 62 logger.warn( message, new Exception () ); 63 } 64 catch( final Throwable t ) 65 { 66 t.printStackTrace(); 67 } 68 } 69 } 70 | Popular Tags |