KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.apache.log4j.net.test;
18
19 import org.apache.log4j.*;
20 import org.apache.log4j.net.SocketAppender;
21
22 public class Loop {
23
24   public static void main(String JavaDoc[] args) {
25     
26     
27     Logger root = Logger.getRootLogger();
28     Logger cat = Logger.getLogger(Loop.class.getName());
29
30     if(args.length != 2)
31       usage("Wrong number of arguments.");
32
33     String JavaDoc host = args[0];
34     int port = 0;
35
36     try {
37       port = Integer.valueOf(args[1]).intValue();
38     }
39     catch (NumberFormatException JavaDoc e) {
40         usage("Argument [" + args[1] + "] is not in proper int form.");
41     }
42
43     SocketAppender sa = new SocketAppender(host, port);
44     Layout layout = new PatternLayout("%5p [%t] %x %c - %m\n");
45     Appender so = new ConsoleAppender(layout, "System.out");
46     root.addAppender(sa);
47     root.addAppender(so);
48
49     int i = 0;
50
51     while(true) {
52       NDC.push(""+ (i++));
53       cat.debug("Debug message.");
54       root.info("Info message.");
55       NDC.pop();
56     }
57
58   }
59
60   static
61   void usage(String JavaDoc msg) {
62     System.err.println(msg);
63     System.err.println(
64       "Usage: java " +Loop.class.getName() + " host port");
65     System.exit(1);
66   }
67     
68
69 }
70
Popular Tags