KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > filesrv > 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 filesrv;
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 /**
26  * FileServer Example
27  * @author Akshathkumar Shetty
28  */

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