2012-01-12 119 views
3

我有一個只有EJB(EJB3.0)並且沒有WAR模塊的EAR,服務器是JBOSS 4.3 over linux。什麼是使用EJB 3.0初始化log4j的最佳方式?

我想在服務器外用log4j.properties文件初始化LOG4J,並使用slf4j作爲外觀。

什麼是初始化我的log4j的最佳方式是什麼?

在此先感謝

回答

-1

我已經在啓動初始化,並把log4j的在META-INF文件夾中。只需使用log4j而不使用Slf4j。 (EJB 3.1)

我希望下面的代碼有幫助;

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

@Singleton 
@Startup 
public class InitClass { 

@PostConstruct 
private void log4jIlkle() { 
     String log4jProp = yourlog4jPath;//My path definition maybe put more flexible path: "../applications/DeployName/META-INF/log4j.properties"; 
     File logFile = new File(log4jProp); 
     if (logFile.exists()) { 
      System.out.println("Log4j init: " + log4jProp); 
      PropertyConfigurator.configure(log4jProp); 
     } 
     else { 
      System.err.println("*** " + log4jProp + " file not found, initialize with default settings"); 
      BasicConfigurator.configure(); 
     } 
    } 
} 
+0

這隻適用於EJB 3.1,而不適用於EJB 3.0。 – fnt 2012-12-02 17:30:45

+0

的想法是隻給出 – 2012-12-10 13:41:51

+0

這個想法對於EJB 3.0是沒用的。 – fnt 2012-12-13 01:35:41

相關問題