I just want to easily try slf4j on the console ~~ However, all the information to be examined seems to be long and long. ~~
then, let's begin.
http://logback.qos.ch/download.html Get logback-1.2.3.tar.gz.
Find out, create ./lib/ and store it there
Test.java
   import org.slf4j.LoggerFactory;
   import org.slf4j.Logger;
   public class Test {
     public static void main(String[] args){
       Logger logger = LoggerFactory.getLogger("Test");
       logger.info("info: {}", "information");
       logger.warn("warn: {}", "warning");
       logger.error("error: {}", "error");
     }
   }
Current directory structure at this point
$ tree
.
|-- Test.java
`-- lib
    |-- logback-classic-1.2.3.jar
    |-- logback-core-1.2.3.jar
    `-- slf4j-api-1.7.25.jar
$ javac -cp .:./lib/logback-core-1.2.3.jar:./lib/logback-classic-1.2.3.jar:./lib/slf4j-api-1.7.25.jar Test.java
$ java -cp .:./lib/logback-core-1.2.3.jar:./lib/logback-classic-1.2.3.jar:./lib/slf4j-api-1.7.25.jar Test
14:46:17.371 [main] INFO Test - info:information
14:46:17.375 [main] WARN Test - warn:warning
14:46:17.376 [main] ERROR Test - error:error
Prepare logback.xml.
$ tree
.
|-- Test.java
|-- lib
|   |-- logback-classic-1.2.3.jar
|   |-- logback-core-1.2.3.jar
|   `-- slf4j-api-1.7.25.jar
`-- logback.xml ★ this
The contents of logback.xml. For the time being, this will come out.
<configuration>
  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>test.log</file>
    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>
  <root level="DEBUG">
    <appender-ref ref="FILE" />
  </root>
</configuration>
Perform steps (3) and (4)
Recommended Posts