How to force OpenEJB to use slf4j?

Can anyone give an example of a dependency configuration pom.xmlthat forces OpenEJB to use slf4j logging rather than JCL (now this is what it uses, as I understand it).

see also How to configure OpenEJB logging?

+3
source share
6 answers

Here's how I did OpenEJB to use external logging:

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

Perhaps it is possible to move this system property to some global resource, for example pom.xml?

+1
source

We have support for:

LogStreamFactory , openejb.log.factory .

JCL SLF4J. , !

+2

. : - Slf4jLogStreamFactory - Slf4jLogStream

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);
    }

}

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)

, loglog logger slf4j:)

+2

API JCL, API SLF4J JCL .

, ? - ?

 <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>
0
source

Not a Maven expert, but in my opinion you want:

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

If OpenEJB does not support JCL, it would be pointless to add this dependency, so go to JUL or Log4j.

More details can be found in the Maven Repository .

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

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

If you are using the Maven exec plugin, try the following:

<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>
0
source

Source: https://habr.com/ru/post/1773819/


All Articles