`
dodoflying
  • 浏览: 180766 次
社区版块
存档分类
最新评论

今天解决了两个问题

阅读更多
今天解决了两问题,都是在javaworld.com.tw上得到解答的。
一个是困扰我比较久的关于loggin中FileHandler的问题,怎样才能将产生的所有日志都记录在一个文件中,我过去的方法比较笨,在各个类中传递Handler,今天才知道比较好的方式是利用Logger的阶层的概念
package logger;

import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;

public class Post {
    public static void main(String args[]); {
        FileHandler filehandler = null;
        try {
            filehandler = new FileHandler("d:\\post.log", true);;
        } catch (SecurityException e); {
            // TODO Auto-generated catch block
            e.printStackTrace();;
        } catch (IOException e); {
            // TODO Auto-generated catch block
            e.printStackTrace();;
        }
        Logger rootLogger = Logger.getLogger("root.");;
        rootLogger.addHandler(filehandler);;
        Logger logger = Logger.getLogger("root.Post");;
        logger.info("The Post start......");;
        People people = new People();;
    }
}


package logger;

import java.util.logging.*;

public class People {
    public People(); {
        Logger logger = Logger.getLogger("root.People");;
        logger.info("The People start......");;
        Buildings buildings = new Buildings();;
    }
}


/*
 * Created on 2005-1-18
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package logger;

import java.util.logging.Logger;

/**
 * @author LiDong
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class Buildings {
    public Buildings(); {
        Logger logger = Logger.getLogger("root.People.Buildings");;
        logger.info("The Buildings start......");;
    }

}


另一个问题是用ant进行j2me开发中classpath的配置问题(WTK2.2),moliwang帮助解决
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics