KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > echowebserver > 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 echowebserver;
16
17 import org.quickserver.net.server.*;
18 import org.quickserver.net.InitServerHook;
19
20 import java.io.*;
21 import java.util.logging.*;
22 import org.quickserver.util.logging.*;
23
24 /**
25  * SetupLoggingHook
26  * @author Akshathkumar Shetty
27  */

28 public class SetupLoggingHook implements InitServerHook {
29     private QuickServer quickserver;
30
31     public String JavaDoc info() {
32         return "Init Server Hook to setup logging.";
33     }
34
35     public void handleInit(QuickServer quickserver) throws Exception JavaDoc {
36         Logger logger = null;
37         FileHandler txtLog = null;
38         File log = new File("./log/");
39         if(!log.canRead())
40             log.mkdir();
41         try {
42             logger = Logger.getLogger("");
43             logger.setLevel(Level.FINEST);
44
45             logger = Logger.getLogger("org.quickserver");
46             txtLog = new FileHandler("log/EchoWebServer_QuickServer%u%g.txt",
47                 1024*1024, 20, true);
48             txtLog.setFormatter(new SimpleTextFormatter());
49             txtLog.setLevel(Level.FINE);
50             logger.addHandler(txtLog);
51             
52             logger = Logger.getLogger("");
53             txtLog = new FileHandler("log/EchoWebServer_Full%u%g.txt",
54                 1024*1024, 20, true);
55             txtLog.setFormatter(new SimpleTextFormatter());
56             txtLog.setLevel(Level.FINEST);
57             logger.addHandler(txtLog);
58
59             logger = Logger.getLogger("echowebserver");
60             txtLog = new FileHandler("log/EchoWebServer%u%g.txt",
61                 1024*1024, 20, true);
62             txtLog.setFormatter(new SimpleTextFormatter());
63             txtLog.setLevel(Level.FINE);
64             logger.addHandler(txtLog);
65
66             quickserver.setAppLogger(logger);//img
67
} catch(IOException e){
68             System.err.println("Could not create txtLog FileHandler : "+e);
69             throw e;
70         }
71     }
72 }
73
Popular Tags