1 14 15 package org.quickserver.util.logging; 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 39 public class SimpleJDKLoggingHook implements InitServerHook { 40 private QuickServer quickserver; 41 42 public String info() { 43 return "Init Server Hook to setup logging."; 44 } 45 46 public void handleInit(QuickServer quickserver) throws Exception { 47 Logger logger = null; 48 FileHandler txtLog = null; 49 File log = new File("./log/"); 50 if(!log.canRead()) 51 log.mkdir(); 52 try { 53 String level = System.getProperty( 54 "org.quickserver.util.logging.SimpleJDKLoggingHook.Level"); 55 56 logger = Logger.getLogger(""); 57 logger.setLevel(Level.FINEST); 58 59 int count = 20; 60 String temp = System.getProperty( 61 "org.quickserver.util.logging.SimpleJDKLoggingHook.Count"); 62 if(temp!=null) { 63 try { 64 count = Integer.parseInt(temp); 65 } catch(Exception e) {} 66 } 67 68 txtLog = new FileHandler("log/"+quickserver.getName()+"_%u%g.txt", 69 1024*1024, count, true); 70 txtLog.setFormatter(new SimpleTextFormatter()); 71 setLevel(txtLog, level); 72 logger.addHandler(txtLog); 73 74 logger = Logger.getLogger("filesrv"); 75 quickserver.setAppLogger(logger); 76 } catch(IOException e){ 77 System.err.println("Could not create txtLog FileHandler : "+e); 78 throw e; 79 } 80 } 81 82 private static void setLevel(FileHandler target, String temp) { 83 if(temp==null) { 84 target.setLevel(Level.FINE); 85 return; 86 } 87 temp = temp.toUpperCase(); 88 89 if(temp.equals("SEVERE")) 90 target.setLevel(Level.SEVERE); 91 else if(temp.equals("WARNING")) 92 target.setLevel(Level.WARNING); 93 else if(temp.equals("INFO")) 94 target.setLevel(Level.INFO); 95 else if(temp.equals("CONFIG")) 96 target.setLevel(Level.CONFIG); 97 else if(temp.equals("FINE")) 98 target.setLevel(Level.FINE); 99 else if(temp.equals("FINER")) 100 target.setLevel(Level.FINER); 101 else if(temp.equals("FINEST")) 102 target.setLevel(Level.FINEST); 103 } 104 } 105 | Popular Tags |