Question

Can anyone give an example of pom.xml dependencies configuration that will make OpenEJB to use slf4j logging, instead of JCL (this is what it uses now, as I understand).

see also How to configure OpenEJB logging?

Was it helpful?

Solution 3

This is how I made OpenEJB to use external logging:

[...]
@Before
public void before() throws Exception {
  System.setProperty("openejb.logger.external", "true");
  InitialContext ctx = new InitialContext();
}
[...]

Maybe it's possible to move this system property to some global resource, like pom.xml?

OTHER TIPS

We have support for:

New implementations of LogStreamFactory can be plugged in by setting the class name as the value of openejb.log.factory system property.

Feel free to copy one of the existing impls and update for either JCL or SLF4J. The project is always accepting new committers if you get the urge to hack on other things as well!

Thanks to David's pointers, this is actually quite easy. You only need to implement two clases: - Slf4jLogStreamFactory - Slf4jLogStream

then set your factory : System.setProperty("openejb.log.factory", "de.glauche.Slf4jLogStreamFactory");

package de.glauche;

import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.LogStream;
import org.apache.openejb.util.LogStreamFactory;

public class Slf4jLogStreamFactory implements LogStreamFactory {

    @Override
    public LogStream createLogStream(LogCategory logCategory) {
        return new Slf4jLogStream(logCategory);
    }

}

and the Slf4jLogStream:

package de.glauche;

import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.LogStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Slf4jLogStream implements LogStream {
    private Logger log;

    public Slf4jLogStream(LogCategory logCategory) {
        log = LoggerFactory.getLogger(logCategory.getName());
    }

    @Override
    public boolean isFatalEnabled() {
        return log.isErrorEnabled();
    }

    @Override
    public void fatal(String message) {
        log.error(message);
    }

    @Override
    public void fatal(String message, Throwable t) {
        log.error(message,t);
    }
        ... (overwrite the remaining methods like this)

With this i'm getting all output nicely formated in my logback logger via slf4j :)

If you add the API and JCL dependencies then your logging using the SLF4J API will get directed to the default JCL logs.

Is that what you want? Or do you want to use some other back end for the logging?

 <dependencies>
   <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-jcl</artifactId>
        <version>1.6.1</version>
    </dependency>
</dependencies>

Not a Maven expert, but from my understanding, you want this:

<dependency>
    <groupId>org.slf4j</groupId>
        <artifactId>jul-to-slf4j</artifactId>
    <version>1.6.1</version>
</dependency>

If OpenEJB doesn't support JCL, it would be pointless to add that dependency, so go with JUL or Log4j.

You can find more details at Maven repository.

Just in case you really want to use JCL bridge, use this:

<dependency>
    <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
    <version>1.6.1</version>
</dependency>

If you are executing via Maven's exec plugin, try this:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <configuration>
       <mainClass>your Mainclass here</mainClass>
       <systemProperties>
          <systemProperty>
             <key>openejb.log.factory</key>
             <value>slf4j</value>
          </systemProperty>
       </systemProperties>
    </configuration>
 </plugin>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top