framework.java

来自「JAVA实现的一个类库」· Java 代码 · 共 113 行

JAVA
113
字号
package cn.edu.nju.software.sd.cll; import java.util.Hashtable;/** * FrameWork class ,some like the class of 'Hiererchy' in the Log4j project.  * @author SuSE * */public class FrameWork {     	private static  DefaultRootLogger root;	    private static Hashtable<String,Logger> RecordLogger=new Hashtable<String,Logger>();                //Hashtable to store the loggers;    	          private static  FrameWork framework;     private FrameWork(){}    /**     *     Singleton pattern     * @return     */     public static FrameWork getframework(){            if (framework==null){         framework=new FrameWork();      }       return framework;     }        	@SuppressWarnings("static-access")	/**	 * Default construct	 */	public FrameWork(DefaultRootLogger root) {	    this.root = root;	    RecordLogger.put("", root);            // as the root shows no name;	 }   /**   * initLog, complete the getLogger process.   * Something is hidden.   * return void;   *    * @param Name   * @return   */public static Logger initLog(String Name) {					RecordLogger.put(Name, new Logger(Name));                		configure(Name);            		return RecordLogger.get(Name);	}	     	private static   void configure(String Name) {                       if  (RecordLogger.get(Name).readConfig()!=true){            	           // System.out.println("No configuration file read in.");               String temp=Name;               String parent=temp;           			for(int i=temp.lastIndexOf(".");i>-1;i=temp.lastIndexOf("."))						{				parent=temp.substring(0,i);								if(RecordLogger.get(parent)!=null)								{					RecordLogger.get(Name).copy(RecordLogger.get(parent));					return;				}				temp=parent;			}			RecordLogger.get(Name).copy(root);		} 	}        	/**	 * getLogger function,which is called by getLogger method in the LoggerFactory class	 * the  final realization of the factory pattern.	 * @param name	 * @return	 */      	public static Logger getLogger(String name) {    		Logger logger =RecordLogger.get(name);    		 if (logger!=null)     		       		      return logger;    		 else                      return initLog(name);    	}   	}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?