2010年5月12日 星期三

LOGGer

請看
http://caterpillar.onlyfun.net/Gossip/JavaGossip-V2/LoggingLevel.htm

此外我們可以設定 property 改變顯式的 LEVEL.
預設在 /usr/java/jdk1.6.0_20/jre/lib logging.properties

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
另一種方法是讀取給定的 logger , 在目前目錄下有 LoggingTest.java 和 LoggingTest.properties,
我們會用到將 LogManager 去讀取 Configuration file
LoggingTest.java
{{{
import java.util.logging.*;
import java.io.*;

/** Referece the caterpillar */
public class LoggingTest {
private static Logger logger = Logger.getLogger(LoggingTest.class.getName());
private static final String LOG_PROP = "LoggingTest.properties";

public static void main(String[] args) {
try {
InputStream is = new BufferedInputStream(new FileInputStream(LOG_PROP));
LogManager.getLogManager().readConfiguration(is);
is.close();
}
catch (IOException e) {
logger.warning("Read the logger faile");
System.exit(0);
}



logger.severe("嚴重訊息");
logger.warning("警示訊息");
logger.info("一般訊息");
logger.fine("細微的訊息");
logger.finer("更細微的訊息");
logger.finest("最細微的訊息");


}

}

}}}

LoggingTest.properties
{{{
handlers= java.util.logging.ConsoleHandler
.level= ALL
java.util.logging.ConsoleHandler.level = ALL
}}}


參考:
http://eric1300460.pixnet.net/blog/post/27586127
http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/Logger.html
http://java.sun.com/j2se/1.4.2/docs/api/java/util/logging/LogManager.html

沒有留言:

張貼留言