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