tomcat/lib 中的 JAR 文件无法使用 log4j 进行日志记录

发布于 2024-12-31 22:38:22 字数 677 浏览 1 评论 0原文

大家好,

我有一个由多个 Web 应用程序共享的 JAR。它必须位于 Tomcat/lib 中,因为它在内存中创建由多个 WAR 文件共享的对象。 (顺便说一句,我没有设计这个。)这就是为什么它没有包含在每个 WAR 中。

长话短说,我希望能够从这个 JAR 文件登录到 log4j。我将它作为 Maven 依赖项包含在内,并且在部署到 Tomcat 中时它不会记录日志。

我尝试在 JAR、Tomcat 等中使用 log4j.properties,但没有成功。我还尝试在类中对配置进行硬编码:

/** * 获取一个记录器实例来使用和配置它,因为它还没有完成 * 通过 Tomcat 的设置: */ 私有静态记录器 LOGGER = Logger.getLogger(RoomRatePlan.class);

static {
    ConsoleAppender ca = new ConsoleAppender();
    ca.setWriter(new OutputStreamWriter(System.out));
    ca.setLayout(new PatternLayout("%5p %d [%t] (%F:%L) - %m%n"));
    LOGGER.addAppender(ca);
}

即使这样也不会产生日志输出。有什么想法吗?

Aloha All,

I have a JAR that is shared by multiple web apps. It must be in Tomcat/lib because it creates in memory objects that are shared by multiple WAR files. (I did not design this BTW.) This is why it is not included in each WAR.

Long story short I'd like to be able to log from this JAR file to log4j. I have it included as a maven dependency and it is not logging when deployed in Tomcat.

I tried using a log4j.properties in the JAR, in Tomcat, etc with no luck. I also tried hard coding a config in a class:

/**
* Get a logger instance to use and configure it since its not getting done
* via Tomcat's settngs:
*/
private static Logger LOGGER = Logger.getLogger(RoomRatePlan.class);

static {
    ConsoleAppender ca = new ConsoleAppender();
    ca.setWriter(new OutputStreamWriter(System.out));
    ca.setLayout(new PatternLayout("%5p %d [%t] (%F:%L) - %m%n"));
    LOGGER.addAppender(ca);
}

and even this does not produce log output. Any ideas?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文