博客一
Java中使用Log的方法 - renxiaoren - 博客园 (cnblogs.com)
方式一:
public class HelloLogWorld {
private static String name = HelloLogWorld.class.getName();
private static Logger log = Logger.getLogger(name);// <= (2)
public void sub() {
log.info("Hello Logging World"); // <= (3)
}
public static void main(String[] args) {
HelloLogWorld logWorld = new HelloLogWorld();
logWorld.sub();
}
}
Logger logger=Logger.getLogger(ECntrCbsChargingService.class); logger.info("success");
博客二(亲测更方便更好用)
使用@Slf4j打印日志_zcyt085的博客-CSDN博客
添加依赖:
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.0</version>
</dependency>
<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>
使用示例:
```java
package zc.test;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LogDemo {
public static void main(String[] args) {
log.info("message");
log.error("error");
log.warn("warning");
}
}