使用 EJB 3.0 初始化 log4j 的最佳方法是什么?

发布于 2024-12-26 13:08:20 字数 172 浏览 4 评论 0原文

我有一个 EAR,它只有 EJB (EJB3.0),没有 WAR 模块,服务器是 Linux 上的 JBOSS 4.3。

我想在服务器外部使用 log4j.properties 文件初始化 LOG4J 并使用 slf4j 作为外观。

初始化 log4j 的最佳方法是什么?

提前致谢

I have an EAR who has only EJBs (EJB3.0) and with out a WAR module, the server is JBOSS 4.3 over linux.

I want to initialize LOG4J with a log4j.properties file outside the server and use slf4j as facade.

What is the best way to initialize my log4j?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深巷少女 2025-01-02 13:08:20

我已经在启动中初始化并将 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();
        }
    }
}

I have initialized in Startup and put log4j in META-INF folder. And just use log4j without Slf4j. (EJB 3.1)

I hope below code helps;

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();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文