Junior — Middle
How did you implement the logging system in your project?
sobes.tech AI
Answer from AI
To implement a logging system in a Java project, I usually use popular libraries such as Log4j or SLF4J with Logback.
Main steps:
- Add the dependency to the project (for example, via Maven or Gradle).
- Create a configuration file (log4j.properties or logback.xml), where I set up logging levels, message formats, and output (console, file).
- In the code, create a logger:
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
- Use the logger to record messages:
logger.info("Data processing started");
logger.error("Error connecting to the database", exception);
This approach allows centralized management of logs, filtering by level, and saving for later analysis.