springboot使用logbac日志工具

springboot使用logbac日志工具,第1张

1、添加依赖


    org.projectlombok
    lombok

2、在resources目录下添加logback-spring.xml文件







    
    
        
        
            debug
        
        
            %date [%-5p] [%thread] %logger{60} [%file : %line] %msg%n
            
            UTF-8
        
    
    
    
        
        E:/log/springboot-logback.log
        
            %date [%-5p] %thread %logger{60} [%file : %line] %msg%n
        
        
            

            

            E:/log/springboot-logback.log.%d{yyyy-MM-dd}.log
            30
        
    
    

    
        
        
    

3、使用,在controller中这样使用

package com.bjpowernode.springboot;

import com.bjpowernode.springboot.servlet.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/student/count")
    public @ResponseBody String studentCount(){
        log.info("查询当前学生总人数");
       Integer  studentCount =  studentService.queryStudentCount();
        return "学生总人数为:" + studentCount;
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/725474.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存