Logback logging framework is the successor for log4j. It standardizes several capabilities, which were earlier achieved in ad hoc manner by different project teams.
Here is a quick note on the key features that Logback brings on table:
Smaller memory footprint.
Faster – 1. Uses SLF4J style log method signatures, that requires string concatenation only if logging is needed. 2. Each logger saves its effective level, and must not query its ancestors for log level. 3. Message formatters are tuned for performance.
Automatic reloading and reconfiguring, based on config file changes. Now a mediocre implementation would have used a timer, and would scan for changes every n seconds, in a separate thread. Logback uses a ReconfigureOnChange filter, that is in the pipeline of writing log events. Based on how often the application writes logs, this filter is included after every m log events. If the scan period of n seconds has elapsed, this filter checks the logback config file, and reconfigures logback if needed.
Automatic log file maintenance – deletes logs older than a set period.
Size and time based rollover triggering.
Automatic, and asynchronous compression of archived logs.
Sifting Appender – Used to sift logging based on MDC attributes. For example, append logging events from different users to different files.
Stacktrace provides names of jars from where classes were loaded.
Allows inclusion of conditional processing using <if>, <then>, and <else>.
Multiple apps, running in different JVMs, can log to the same target (file). Such applications can use different logger context name, for differentiating the log events in the target file.
Reading external properties: Logback configuration file can read values of variables from an external configuration file, from Java System properties, or from JNDI context.
Fragments of a log back configurations can be “included” to create a more complex log back configuration.
Configuring the Logger: Levels are inherited, starting from the root logger; unless explicitly stated using level attribute.
Configuring the Appenders with the Logger: By default “appenders are cumulative”. A logger will log to the appenders attached to itself (if any) as well as all the appenders attached to its ancestors. Thus, attaching the same appender to multiple loggers will cause logging output to be duplicated. This can be overridden by setting the additivity attribute to false.
Configuration reference: http://logback.qos.ch/manual/configuration.html