KickJava   Java API By Example, From Geeks To Geeks.

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


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

19 package org.apache.log.output.test;
20
21 import java.net.InetAddress JavaDoc;
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 /**
31  *
32  * @author Peter Donald
33  */

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