Added slf4J + logback to Eclipse Maven project

It was a project I didn't intend to log, I was asked for a log so I added it

I was thinking of doing it with log4j without thinking about anything, Apparently it's already old w That's right ...

As a result of investigating and saying, log4j2 and slf4J + logback seem to be the mainstream In terms of puns, log4j2 was better, but Somehow select a new slf4J + logback!

Set up! !! Setting slf4J + logback from creating Maven project in Eclipse I imitated this as it is w

Open pom.xml and add the following

pom.xml


    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.18</version>
        <scope>provided</scope>
    </dependency>
  </dependencies>

Right-click on the project and click Maven --Project Update to reflect After reflecting it, it became Java 1.5, so I changed to use java 1.7

I added lombock to avoid writing the following description in the class every time.

public static final Logger log =...」

However, installation is required to use lombock with Eclipse. Execute the command and the installer will start up, so install it (it will end in an instant)

$ java -jar /Users/xxxxxx/.m2/repository/org/projectlombok/lombok/1.16.18/lombok-1.16.18.jar

But instead, I needed something like this (Personally, this is more difficult to understand, so I think I didn't have to put in lombock, but ...)

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Main {

When I looked at the logback manual, The output level setting and such are written in logback.xml. But I can't find it anywhere ...

I wonder if I made a mistake somewhere when creating a Maven project src/main/resources Solved by creating the source folder of and putting logback.xml in it

The rest was set with reference to this Set logback.xml

Recommended Posts

Added slf4J + logback to Eclipse Maven project
Output log to external file with slf4j + logback with Maven
Introduce Maven to Tomcat project
How to make a Maven project
Create Maven Project
Introduce Kotlin to your existing Java Maven Project
Change the URL of the application of Eclipse project (Maven).
[Eclipse / Tomcat] Servlet + JSP in Maven webapp project
To debug in eclipse
[Java] logback slf4j sample
How to specify "-parameters" compile options added in JDK 8 (Maven, IntelliJ, Spring Tool Suite = Eclipse)
Create Maven Web Project
Programmatically import a Maven project from your own Eclipse plugin