# Logging

## Logging frameworks

Bio-Formats uses SLF4J as a logging API. SLF4J is a facade and needs to be bound to a logging framework at deployment time. Two underlying logging frameworks are currently supported by Bio-Formats. Bio-Formats does not impose any specific SLF4J binding on downstream consumers as per the recommended SLF4J best practices. Some recommended bindings are as follows:

- logback is the recommended framework and natively implements the SLF4J API. A logback version of 1.2.x is recommended as Bio-Formats has a hard dependency for slf4j-api 1.7.30. This means that logback versions 1.3.x and higher are not yet supported in Bio-Formats as they rely on slf4j-api 2.x.

- log4j is the other logging framework supported by Bio-Formats and is primarily used in the MATLAB environment.

Examples of declaring these dependencies using Maven or Gradle are given in the Bio-Formats examples repository.

## Initialization

The DebugTools class contains a series of framework-agnostic methods for the initialization and control of the logging system. This class uses reflection to detect the underlying logging framework and delegate the method calls to either Log4jTools or LogbackTools.

The main methods are described below:

- `DebugTools.enableLogging()` will initialize the underlying logging framework. This call will result in a no-op if logging has been initialized either via a binding-specific configuration file (see logback configuration) or via a prior call to `DebugTools.enableLogging()`.

- `DebugTools.enableLogging(level)` will initialize the logging framework under the same conditions as described above and set the root logger level if the initialization was succesful.

- `DebugTools.setRootLevel(level)` will override the level of the root logger independently of how the logging system was initialized.

- `DebugTools.enableIJLogging()` (logback-only) will add an ImageJ-specific appender to the root logger.

Changed in version 5.2.0: Prior to Bio-Formats 5.2.0, `DebugTools.enableLogging(level)` unconditionally set the logging and root logger level. Use `DebugTools.setRootLevel(level)` to restore this behavior.