Junior — Middle
How is logging managed in your application?
sobes.tech AI
Answer from AI
Logging in my Java applications is usually implemented using libraries such as Log4j or SLF4J with Logback. Logs are recorded with different levels of importance: DEBUG, INFO, WARN, ERROR.
Example of logging setup using SLF4J and Logback:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyApp {
private static final Logger logger = LoggerFactory.getLogger(MyApp.class);
public void run() {
logger.info("Application started");
try {
// code
} catch (Exception e) {
logger.error("Execution error", e);
}
}
}
Logs can be saved to files, output to the console, or sent to remote servers for monitoring. It is important to structure logs and use levels for easier analysis.