Dag
Dag

Reputation: 10549

Route Restlet logging to log4j2

I want to bridge the restlet logging to log4j2, so the LogServices is logged correctly. Currently I have full qualified classnames in my log pattern, eg: [org.restlet.Component.InternalRouter], but the LogService is logged as [.Logservice] (which is not the desired behaviour). I don't have the classes for the slf4j bridge in my classpath nor want them (except for the slf4j api-classes). I use all dependencies to bridge JUL,log4j1.x, Slf4j.

Using slf4j previously I used the code from the restlet documentation/section "SLF4J bridge from JULI" to bridge the output. Using the code to remove the handler will result in an exception, since there is no Handler anymore.

I'm using log4j2 2.2 and restlet 2.0.15

Upvotes: 0

Views: 351

Answers (1)

Thiago Kronig
Thiago Kronig

Reputation: 176

Restlet uses JDK's logging API that you can bridge to log4j.

Your own classes can use the SLF4J API, if you prefer (I prefer the logj4 API though), which also can bridge to log4j.

You'll need two bridges in the runtime classpath: log4j-jul e log4j-slf4j-impl.

In Maven, do:

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-jul</artifactId>
  <version>2.2</version>
  <scope>runtime</scope>
</dependency>

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j-impl</artifactId>
  <version>2.2</version>
  <scope>runtime</scope>
</dependency>

That way, you can configure both using Log4j.

Upvotes: 1

Related Questions