KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > log4j > net > test > SyslogMin


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

16
17
18 package org.apache.log4j.net.test;
19
20 import org.apache.log4j.Logger;
21 import org.apache.log4j.PropertyConfigurator;
22 import org.apache.log4j.Priority;
23 import org.apache.log4j.NDC;
24
25
26 public class SyslogMin {
27
28   static Logger CAT = Logger.getLogger(SyslogMin.class);
29
30   public
31   static
32   void main(String JavaDoc argv[]) {
33
34       if(argv.length == 1) {
35     ProgramInit(argv[0]);
36       }
37       else {
38     Usage("Wrong number of arguments.");
39       }
40       test("someHost");
41   }
42
43
44   static
45   void Usage(String JavaDoc msg) {
46     System.err.println(msg);
47     System.err.println( "Usage: java " + SyslogMin.class + " configFile");
48     System.exit(1);
49   }
50
51
52   static
53   void ProgramInit(String JavaDoc configFile) {
54     int port = 0;
55     PropertyConfigurator.configure(configFile);
56   }
57
58   static
59   void test(String JavaDoc host) {
60     NDC.push(host);
61     int i = 0;
62     CAT.debug( "Message " + i++);
63     CAT.info( "Message " + i++);
64     CAT.warn( "Message " + i++);
65     CAT.error( "Message " + i++);
66     CAT.log(Priority.FATAL, "Message " + i++);
67     CAT.debug("Message " + i++, new Exception JavaDoc("Just testing."));
68   }
69 }
70
Popular Tags