KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log > output > test > DatagramTest


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.log.output.test;
18
19 import java.net.InetAddress JavaDoc;
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 /**
29  *
30  * @author Peter Donald
31  */

32 public final class DatagramTest
33 {
34     public static void main( final String JavaDoc[] args )
35     {
36         try
37         {
38             Formatter formatter = null;
39             String JavaDoc message = null;
40
41             if( 0 == args.length )
42             {
43                 formatter = new SyslogFormatter( SyslogFormatter.FACILITY_DAEMON );
44                 message = "hello!!!";
45             }
46             else
47             {
48                 //final int facility = 9<<3; //Cron
49
//final int priority = 3; //ERROR
50
//final String message = "<" + (facility|priority) + "> hello!!!";
51
formatter = new RawFormatter();
52                 message = args[ 0 ];
53             }
54
55             final InetAddress JavaDoc 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 JavaDoc() );
63         }
64         catch( final Throwable JavaDoc t )
65         {
66             t.printStackTrace();
67         }
68     }
69 }
70
Popular Tags