www.pudn.com > mobileMms.rar > LogManage.java


package cn.netjava.mmsclient.util; 
 
import java.util.logging.*; 
import java.util.Calendar; 
 
/** 
 *  
 * 

Title:中国移动mm7协议客户端 V0.1

*

Description: 日志管理器,这个太烂了

*

Company:蓝杰实训

* @author NetJava.cn * @version 0.1 */ public class LogManage { /**日志对像*/ public Logger logger; /**取得对像实例 */ public static LogManage ins() { if (instans == null) { instans = new LogManage(); } else { if (timeStamp != null && !timeStamp.equals(instans.getTimeStamp())) { instans.initLog(); } } return instans; } /**构造器,初始化时加入输出到文本的处理器*/ private LogManage() { initLog(); } private void initLog() { logger = Logger.getAnonymousLogger(); try { timeStamp = getTimeStamp(); hand = new FileHandler(getTimeStamp() + ".log", true); hand.setFormatter(new SimpleFormatter()); logger.addHandler(hand); } catch (Exception ef) { System.out.println(" **********************\n " + " cand create logAsDB file " + ef + "\n **********************"); } } //取得当天时间 public String getTimeStamp() { Calendar now = Calendar.getInstance(); String yyyy = String.valueOf(now.get(java.util.Calendar.YEAR)); String mm = totwo(String.valueOf(now.get(Calendar.MONTH) + 1)); String dd = totwo(String.valueOf(now.get(Calendar.DAY_OF_MONTH))); return yyyy + mm + dd; //hh+ff+ss; } public String totwo(String s) { if (s.length() < 2) { s = "0" + s; return s; } return s; } // for test this public static void main(String args[]) { LogManage.ins().logger.severe("this is server in method"); LogManage.ins().logger.logp(Level.INFO, "test", " ", " this is server in method"); } private static LogManage instans = null; private static Handler hand; private static String timeStamp; }