SLF4J Log4J Jboss 4.3 和 EJB 3.0

发布于 2024-12-28 07:47:17 字数 3726 浏览 0 评论 0原文

我用ejb3 + slf4j和maven做了一个新程序

要使用SLF4J和LOG4J我有

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.6.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.2</version>
  <scope>compile</scope>
</dependency>

但是我说不要把log4j的jar放在我耳朵里使用JBOSS的jar

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>apache-log4j-extras</artifactId>
        <version>1.1</version>
        <scope>provided</scope>
    </dependency>

有一个名为jboss-log4j.xml的配置文件

Jboss在根目录中 说使用附加器异步

  <root>
      <appender-ref ref="ASYNC"/>
  </root>

附加器异步使用附加器文件

 <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
    <param name="Threshold" value="INFO"/>
    <appender-ref ref="FILE"/>
</appender>

附加器文件是

 <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
     <param name="File" value="${jboss.server.log.dir}/server.log"/>
     <param name="Append" value="false"/>
     <param name="DatePattern" value="'.'yyyy-MM-dd"/>
     <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n"/>
     </layout>
  </appender>

这个附加器正在工作很多东西都写在这里 文件。

但我想要为我的服务创建一个新文件

,我添加了一个类别,类别的名称是包含我所有新开发的包的名称

    <category name="com.mycompany.ti.minewsystem">
            <priority value="DEBUG" />
            <appender-ref ref="MYAPPENDER"/>
    </category>

,附加程序是

    <appender name="MYAPPENDER" class="org.jboss.logging.appender.DailyRollingFileAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
            <param name="File" value="${jboss.server.home.dir}/log/ws-mysystem.log"/>
            <param name="Append" value="false"/>
            <param name="DatePattern" value="'.'yyyy-MM-dd"/>
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n"/>
            </layout>
    </appender>

最后 mi EJB 导入 SLF4J

  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;

创建记录器

  private Logger logger = LoggerFactory.getLogger(MyEJB.class);

并使用

  logger.debug("--------- HI! ------------------");

日志文件(ws-mysystem.log) 已创建,但仍处于零字节:(

一切都结束了 JBOSS 4.3 上的 Red Hat 和 Java 6

有人知道我的程序出了什么问题吗?

也许是 Slf4J 和 ClassLoaders?还是2012 和世界末日?

JBOSS?还是EJB3.0和

I made a new program with ejb3 + slf4j with maven

To use SLF4J with LOG4J I have

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.6.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.6.2</version>
  <scope>compile</scope>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.6.2</version>
  <scope>compile</scope>
</dependency>

But I said dont put the jars of log4j in my ear to use the jar of JBOSS

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>apache-log4j-extras</artifactId>
        <version>1.1</version>
        <scope>provided</scope>
    </dependency>

Jboss has a configuration file named jboss-log4j.xml

inside the root says use the appende ASYNC

  <root>
      <appender-ref ref="ASYNC"/>
  </root>

The appender Async use the appender FILE

 <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
    <param name="Threshold" value="INFO"/>
    <appender-ref ref="FILE"/>
</appender>

And the appender FILE is

 <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
     <param name="File" value="${jboss.server.log.dir}/server.log"/>
     <param name="Append" value="false"/>
     <param name="DatePattern" value="'.'yyyy-MM-dd"/>
     <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n"/>
     </layout>
  </appender>

This appender is working many things are writed in this file.

But I want a new file for my service

I added a category, the name of the category is the name of the package who contanins all my new develop

    <category name="com.mycompany.ti.minewsystem">
            <priority value="DEBUG" />
            <appender-ref ref="MYAPPENDER"/>
    </category>

And The appender is

    <appender name="MYAPPENDER" class="org.jboss.logging.appender.DailyRollingFileAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
            <param name="File" value="${jboss.server.home.dir}/log/ws-mysystem.log"/>
            <param name="Append" value="false"/>
            <param name="DatePattern" value="'.'yyyy-MM-dd"/>
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n"/>
            </layout>
    </appender>

And Finaly mi EJB imports de SLF4J

  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;

create de logger

  private Logger logger = LoggerFactory.getLogger(MyEJB.class);

and used

  logger.debug("--------- HI! ------------------");

The Log file (ws-mysystem.log) is created, but still at zero bytes :(

All is over Red Hat and Java 6 on JBOSS 4.3

Somebody knows what is wrong with my procedure?

Maybe is something Dark with Slf4J and JBOSS? or EJB3.0 and ClassLoaders? or 2012 and the end of the world?

Thanks in Advance

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

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

发布评论

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

评论(1

海拔太高太耀眼 2025-01-04 07:47:17

检查类加载器设置 - JBoss 中的统一类加载器默认情况下太统一了(我遇到了独立 Web 上下文之间的类和资源泄漏)。尝试禁用统一类加载器并更改父级优先设置。

Check classloader settings - unified classloaders in JBoss sind little too unified by default ( I encountered class and resource leaks between independent web contexts). Try to disable unified classloaders and change parent first settings.

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