3

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?

Community
  • 1
  • 1
yegor256
  • 102,010
  • 123
  • 446
  • 597

6 Answers6

2

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!

David Blevins
  • 19,178
  • 3
  • 53
  • 68
  • Could you please give an example of what exactly I have to change, and where? I tried to add `openejb.log.factory=org.apache.openejb.util.Log4jLogStreamFactory` into `jndi.properties`, with no effect :( – yegor256 Nov 11 '10 at 06:30
  • The log4j implementation is the default one, so setting it explicitly wouldn't change anything. To get it to use something other than Log4j or java.util.logging, you'd have to write a new LogStreamFactory and set it using that property. – David Blevins Nov 12 '10 at 06:35
  • If log4j is the default implementation, why my `log4j.properties` is ignored then? – yegor256 Nov 14 '10 at 09:28
  • Please review this question as well: http://stackoverflow.com/questions/4176924. I still can't understand how to configure OpenEJB logging... None of approaches explained in documentation really work. – yegor256 Nov 14 '10 at 11:21
  • I used `System.setProperty("openejb.log.factory","slf4j");` or `-Dopenejb.log.factory=slf4j` . Other values can be seen in `org.apache.openejb.util.Logger`: `log4j`, `pax` . – raisercostin Oct 28 '15 at 15:07
2

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 :)

mglauche
  • 3,344
  • 4
  • 28
  • 31
1

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?

yegor256
  • 102,010
  • 123
  • 446
  • 597
0

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>
magarciaschopohl
  • 325
  • 4
  • 11
0

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>
hallidave
  • 9,579
  • 6
  • 31
  • 27
0

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>
darioo
  • 46,442
  • 10
  • 75
  • 103