Log4j – 04 – Apache Log4j Konfigurasyon – 02

Merhaba Arkadaslar,
Bir onceki yazida Apache Log4j icin gerekli duzenlemeyi nasil ve nerede yapabilecegimiz konusundan bahsettik ve basit bir uygulama yaptik.

Log4j ‘yi projemizde/uygulamamizda kullanmadan once gerekli duzenlemeleri(konfigurasyon) uygulamamiza ozel olarak yapmamiz gerekir.

Bir onceki yazida konfigurasyon dosyasi(configuration file) araciligi ile duzenleme islemini yaptik.
Bu bolumde ise programlanabilir bir bicimde(programmatically) nasil yapacagimizi incelecegiz.

Programlanabilir bir bicimde , Log4j’yi kullanabilmek icin org.apache.log4j.BasicConfigurator sinifini ve configure() metodunu kullanacagiz.

BasicConfigurator.configure()

HelloLog4j.java

package log4j02.programmatically.configuration;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class HelloLog4j {

	static final Logger logger = Logger.getLogger(HelloLog4j.class);

	public static void main(String[] args) {
		BasicConfigurator.configure();
		logger.debug("Log4j debug message");
		logger.info("Log4j info message");
		logger.warn(" Log4j warn message");
		logger.error(" Log4j  error message");
		logger.fatal("Log4j  fatal message");
	}
}

 

0 [main] DEBUG log4j02.programmatically.configuration.HelloLog4j  - Log4j debug message
1 [main] INFO log4j02.programmatically.configuration.HelloLog4j  - Log4j info message
1 [main] WARN log4j02.programmatically.configuration.HelloLog4j  -  Log4j warn message
1 [main] ERROR log4j02.programmatically.configuration.HelloLog4j  -  Log4j  error message
1 [main] FATAL log4j02.programmatically.configuration.HelloLog4j  - Log4j  fatal message

Yazimi burada sonlandiriyorum.
Maven Projesi:Log4jTutorial_v2

Herkese Bol Javali Gunler dilerim.
Be an oracle man , import java.*;
Levent Erguder
OCP, Java SE 6 Programmer
injavawetrust

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published. Required fields are marked *