2
votes

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

1
Try adding a threshold parameter to your new appender: <param name="Threshold" value="DEBUG"/>Brent Worden
With <param name="Threshold" value="DEBUG"/> nothing change :(Kaltresian

1 Answers

1
votes

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.