Sobes.tech
Junior — Middle

Have you worked with the Logback library for logging in recent projects?

sobes.tech AI

Answer from AI

Logback is a popular logging library for Java, which is the successor to Log4j and part of the SLF4J project. It provides a flexible and efficient logging system with support for various logging levels, configurations, and formats.

In Logback projects, it is often used for:

  • Setting logging levels (ERROR, WARN, INFO, DEBUG, TRACE).
  • Configuring log output to the console, files, or remote services.
  • Log file rotation with automatic archiving.

Example of a simple Logback configuration in XML:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="debug">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

Usage in code:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyClass {
    private static final Logger logger = LoggerFactory.getLogger(MyClass.class);

    public void doSomething() {
        logger.info("Starting method execution");
        try {
            // code
        } catch (Exception e) {
            logger.error("Execution error", e);
        }
    }
}
Have you worked with the Logback library for logging… - sobes.tech