log 4 jのデフォルトロードプロセス
ログ4 jのプロファイルが分からない場合にもログを印刷できるのは、ログ4 jがロガーを呼び出しているためである.getLoggerの場合、自動的にclasspathの下にプロファイルを探しに行きます.具体的なコード:
LogLog.setInternalDebugging(true); このスイッチをオンにするとlog 4 j内部の初期化ログが表示されます.分かりやすい.
出力結果:
log4j: Trying to find [log4j.xml] using context classloader [email protected]: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@126b249 class loader.log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().log4j: Trying to find [log4j.properties] using context classloader [email protected]: Using URL [file:/D:/projs/java-test/bin/log4j.properties] for automatic log4j configuration.log4j: Reading configuration from URL file:/D:/projs/java-test/bin/log4j.propertieslog4j: Parsing for [root] with value=[debug,appender1].log4j: Level token is [debug].log4j: Category root set to DEBUGlog4j: Parsing appender named "appender1".log4j: Parsing layout options for "appender1".log4j: End of parsing for "appender1".log4j: Parsed "appender1"options.log4j: Finished configuring.[main] DEBUG com.coderdream.log4j.HelloLog4j - This is debug message.[main] INFO com.coderdream.log4j.HelloLog4j - This is info message.[main] ERROR com.coderdream.log4j.HelloLog4j - This is error message.
実装クラス:
___________ ______________
|LogManager|----->|OptionConverter |
参照先:
log 4 j簡明マニュアル
package com.coderdream.log4j;
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.LogLog;
public class HelloLog4j {
private static Logger logger;
static{
LogLog.setInternalDebugging(true);
logger = Logger.getLogger(HelloLog4j.class);
}
/**
* @param args
*/
public static void main(String[] args) {
// System.out.println("This is println message.");
// debug �?
logger.debug("This is debug message.");
// info �?
logger.info("This is info message.");
// error �?
logger.error("This is error message.");
}
}
LogLog.setInternalDebugging(true); このスイッチをオンにするとlog 4 j内部の初期化ログが表示されます.分かりやすい.
出力結果:
log4j: Trying to find [log4j.xml] using context classloader [email protected]: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@126b249 class loader.log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().log4j: Trying to find [log4j.properties] using context classloader [email protected]: Using URL [file:/D:/projs/java-test/bin/log4j.properties] for automatic log4j configuration.log4j: Reading configuration from URL file:/D:/projs/java-test/bin/log4j.propertieslog4j: Parsing for [root] with value=[debug,appender1].log4j: Level token is [debug].log4j: Category root set to DEBUGlog4j: Parsing appender named "appender1".log4j: Parsing layout options for "appender1".log4j: End of parsing for "appender1".log4j: Parsed "appender1"options.log4j: Finished configuring.[main] DEBUG com.coderdream.log4j.HelloLog4j - This is debug message.[main] INFO com.coderdream.log4j.HelloLog4j - This is info message.[main] ERROR com.coderdream.log4j.HelloLog4j - This is error message.
実装クラス:
___________ ______________
|LogManager|----->|OptionConverter |
参照先:
log 4 j簡明マニュアル