SpringBoot Log日志

pom.xml依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

配置文件,这里我用的是

application.yml

logging:
  file:
    path: /log

UserService.java

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserDao userDao;
    @Autowired
    RedisUtil redisUtil;

    private final static Logger logger= LoggerFactory.getLogger(UserServiceImpl.class);

    @Override
    public int deleteById(int id) {
        logger.info("UserServiceImpl deleteById->"+id);
        return userDao.deleteById(id);
    }

UserController.java

@RequestMapping(value = "/user/{id}",method = {RequestMethod.GET,RequestMethod.DELETE})
    public String delteById(@PathVariable("id") int id){
        int result=userService.deleteById(id);
        if(result>=1){
            return "删除成功";
        }else{
            return "删除失败";
        }
    }

项目运行路径:http://localhost:8080/user/4

 

 我们看一下log

 

 

希望在以后的代码中,如果碰到bug,可以通过打印log日志的方式帮助你快速解决bug

感觉对自己有用的别忘记点赞收藏,关注一波不迷路

posted @ 2020-09-04 11:53  龙欺  阅读(359)  评论(0)    收藏  举报