Use of Java~slf4 logging framework

The slf4 log can be enabled by supporting annotations, and then use placeholders directly when using it, without the need to manually concatenate strings, which is also the best in terms of performance.

A build.gradle dependency

    compileOnly('org.projectlombok:lombok')

Second, add annotations to the class

@Slf4j
public class LoggerDemo {
  public void test() {
    UserInfo userInfo = UserInfo.builder().name("zzl").email("[email protected]").build();
    log.debug("{} format print {}", "hello", userInfo);
  }
}

3. If the annotation is not recognized, configure it in the lombok plugin

Through the above process, our log will be printed to the console, and then managed by the log collection tool, without the need to write it to the file as before, because when the log becomes larger, it will be written to the file. , you have to clean it up, and it is not conducive to query and analysis, so that method is destined to be eliminated!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325307055&siteId=291194637