注解@Slf4j:(当前日志为logback,其他日志框架不祥)
直接使用log.xxxx("mothod is start") 例如:log.info("/returncode/add start");
========代替=====
如果不想每次都写 private final Logger logger = LoggerFactory.getLogger(XXX.class);
可以用注解@Slf4j;(idea需装lombok插件)
注明:
本文基于Spring Framework环境,并非基于SpringBoot.如果是基于SpringBoot,因为默认加入了Slf4j-api和logback的依赖,所以只需要添加lombok的依赖即可.
http://www.cnblogs.com/weiapro/p/7633645.html
https://blog.csdn.net/cslucifer/article/details/80953400
注解的包路径:import lombok.extern.slf4j.Slf4j;
@Slf4j public class LoggerTest {
//传统方式private final Logger logger = LoggerFactory.getLogger(LoggerTest.class); @Testpublic void test1(){logger.debug("debug message");logger.warn("warn message");logger.info("info message");logger.error("error message");logger.trace("trace message");}// 二、注解方式实现日志,
//这里直接使用 log.xxx("dddddd"),
// 而不是Logger logger = LoggerFactory.getLogger(LoggerTest.class),然后logger.debug("debug message");
@Testpublic void test2(){log.debug("debug message");log.warn("warn message");log.info("info message");log.error("error message");log.trace("trace message");} }