Weston Gator
Weston Gator

Reputation: 11

Does netty io version 4.x support log4j2 version?

We have successfully moved our project from Netty 3.x to Netty 4.x. However, we are planning to move our project from log4j to log4j2.

First of all, does Netty 4.x support log4j2? If so, can you offer any suggestions or link explaining what to do?

Upvotes: 1

Views: 1785

Answers (1)

Neo
Neo

Reputation: 4880

Netty supports log4j2 from version 4.0.37.Final onwards. See issue link.

However you have to add an additional line of code (see first line below InternalLoggerFactory.setDe...):

InternalLoggerFactory.setDefaultFactory(Log4J2LoggerFactory.INSTANCE);
ServerBootstrap b = new ServerBootstrap();
serverBootstrap.group(parentGroup, childGroup)
    .channel(NioServerSocketChannel.class)
    .handler(new LoggingHandler(LogLevel.INFO))
    ... 

Then add the Logger entry as follows to your log4j2.xml. Example:

<Loggers>
  ...
  <Logger name="io.netty" level="DEBUG" additivity="false">
    <AppenderRef ref="Console"/>
  </Logger>
  ...
</Loggers>

Upvotes: 1

Related Questions