ich habe gerade einen Beitrag gelesen, in dem slf4j + logback empfohlen wird. Ich selbst nutze schon länger (lange vor dem ersten Release von log4j2) slf4j + log4j2.
Daraufhin habe ich mir gerade mal angesehen, wie es mit den Appendern bei logback aussieht - die Anzahl ist auch recht beachtlich.
logback ist die einzige native Implementierung von slf4j und kommt daher ohne Adapter aus.
Welche Gründe gibt es, die für oder gegen eine der beiden Implementierungen sprechen?
Hier hat mal jemand eine Gegenüberstellung geschrieben:
Logback:
HTTP-access logging with brains
Prudent mode
Lilith: logging and access event viewer for Logback, log4j 1.x and java.util.logging
JMX Configurator
Groovy Configuration
Joran Configuration
SLF4J
Log4j 2:
Configuration via XML, JSON, or YAML
Async Loggers
Custom log levels
Automatically reload its configuration upon modification without losing log events while reconfiguring.
Filtering: filtering based on context data, markers, regular expressions, and other components in the Log event. Filters can be associated with Loggers. Unlike Logback, you can use a common Filter class in any of these circumstances.
So ganz korrekt ist der Vergleich aber nicht. Zumindest kann ich bei log4j2 auch mittels JMX die Konfigurationsdatei ändern.
Dass die asynchronen Logger extrem performant sind, kann ich mir gut vorstellen. Die LMAX-Disruptor-Architektur verspricht zumindest in idealen Umgebungen eine gute Performance. /* Edit: jetzt erst den Blogbeitrag komplett gelesen: auch ohne asynchrones Logging ist log4j2 hinter slf4j oft schneller als logback. Das hätte ich nicht erwartet. */
Einen Grund von log4j2 auf logback zu wechseln gibt es für den “Standardanwendungsfall” aber nicht, oder?