Apache Logging Services

Monday September 26, 2016

A sneak peak into Log4j 2.7

Log4j 2.7 will be released in a few days. The community is now reviewing the release for any last minute showstopper. Meanwhile, you may be interested in a sneak peek into what is coming.

Log4j 2 is nominated for the JAX Innovation Awards!

Do you like its performance, garbage-free logging, and easy and flexible configuration?

Log4j 2 needs your love. Vote for Log4j 2!

Voting closes September 29th, 2016.

Scala API

Log4j 2.7 includes a Logging trait that removes some boilerplate code. Your Scala code can now look like this:
import org.apache.logging.log4j.scala.Logging
 
class MyClass extends BaseClass with Logging {
  def doStuff(): Unit = {
    logger.info("Doing stuff")
  }
}
This also enables a more compact form of parameterized logging. Instead of the common Java form:
logger.debug("Logging in user {} with birthday {}", user.getName(), user.calcBirthday());
In Scala, you can use string interpolation to achieve this:
logger.debug(s"Logging in user ${user.getName} with birthday ${user.calcBirthday}")

Non-Blocking Queues in Async Appender

In addition to Log4j 2's Asynchronous Loggers, which are based on the LMAX Disruptor library, the 2.7 release allows you to configure the Async Appender to use a different queue implementation, including a few non-blocking ones:
  • ArrayBlockingQueue - This is the default implementation that uses ArrayBlockingQueue
  • LinkedTransferQueue - This uses the JDK LinkedTransferQueue which was introduced in Java 7.
  • JCToolsBlockingQueue - This uses the MPSC bounded lock-free queue in JCTools.
  • DisruptorBlockingQueue - This uses the Conversant Disruptor BlockingQueue. (Not to be confused with the LMAX Disruptor.)

Custom Context Data Injection

Context data is data that is set by the application to be included in all subsequent log events. The default source for context data is the ThreadContext.

From Log4j 2.7, users can configure a custom ContextDataInjector that can

  • take context data from any source, and
  • use values of any type (not just Strings).
In addition, the ThreadContext map is now garbage-free. This is disabled by default, users need to enable this explicitly.

...and much more

RoutingAppender can now be configured with scripts, a new ScriptAppenderSelector was introduced that creates an Appender specified by a Script, FileAppender (and its Rolling equivalent) can now create files on-demand, and there are various other improvements.

Vote For Us!



Log4j 2 is nominated for the JAX Innovation Awards!

Do you like its performance, garbage-free logging, and easy and flexible configuration?

Log4j 2 needs your love. Vote for Log4j 2!

Comments:

Thank you very much! saved me over here! :)

Posted by Niccolo on September 30, 2016 at 08:27 PM UTC #

Post a Comment:
  • HTML Syntax: NOT allowed

Calendar

Search

Hot Blogs (today's hits)

Tag Cloud

Categories

Feeds

Links

Navigation