KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > echoserver > SetupLoggingHook


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package echoserver;
16
17 import org.quickserver.net.server.*;
18 import org.quickserver.net.InitServerHook;
19
20 import java.io.*;
21
22 import org.quickserver.util.logging.*;
23 import java.util.logging.*;
24
25 public class SetupLoggingHook implements InitServerHook {
26     private QuickServer quickserver;
27
28     public String JavaDoc info() {
29         return "Init Server Hook to setup logging.";
30     }
31
32     public void handleInit(QuickServer quickserver) throws Exception JavaDoc {
33         Logger logger = null;
34         FileHandler txtLog = null;
35         File log = new File("./log/");
36         if(!log.canRead())
37             log.mkdir();
38         try {
39             logger = Logger.getLogger("");
40             logger.setLevel(Level.FINEST);
41
42             logger = Logger.getLogger("");
43             txtLog = new FileHandler("log/EchoServer_Full%u%g.txt",
44                 1024*1024, 5, true);
45             txtLog.setFormatter(new SimpleTextFormatter());
46             txtLog.setLevel(Level.FINEST);
47             logger.addHandler(txtLog);
48
49             logger = Logger.getLogger("org.quickserver");
50             txtLog = new FileHandler("log/EchoServer_QuickServer%u%g.txt",
51                 1024*1024, 20, true);
52             txtLog.setFormatter(new SimpleTextFormatter());
53             txtLog.setLevel(Level.FINEST);
54             logger.addHandler(txtLog);
55             
56             logger = Logger.getLogger("echoserver");
57             txtLog = new FileHandler("log/EchoServer%u%g.txt",
58                 1024*1024, 20, true);
59             txtLog.setFormatter(new SimpleTextFormatter());
60             txtLog.setLevel(Level.FINEST);
61             logger.addHandler(txtLog);
62
63             quickserver.setAppLogger(logger); //img
64

65             //debug non-blocking mode
66
//quickserver.debugNonBlockingMode(false);
67
} catch(IOException e){
68             System.err.println("Could not create txtLog FileHandler : "+e);
69             throw e;
70         }
71     }
72 }
73
Popular Tags