2021-06-08

Springboot中的日志管理

Slf4j+logback来实现

具体实现
重点:

  1. @Slf4j

private static Logger log = LoggerFactory.getLogger(DemoController.class);
3. 四个级别:debug—info—warning—error,从低到高
4. 注意:报错只能报比设置等级高的错误

设置:
可以在application.properties中设置等级:

# log日志
logging.level.root = info
logging.level.com.example.demo.controller = debug
@Slf4j
@RestController
//@RequestMapping("demo")//加一层项目路径
public class DemoController {

    private static Logger log =  LoggerFactory.getLogger(DemoController.class);

    @RequestMapping("hello world")
    @ResponseBody//将函数设置为响应体,而不是实现页面跳转
    public String helloWorld(){
        System.out.println("hello world");
        return "hello world";
    }

    @RequestMapping("index")
    //@ResponseBody//将函数设置为响应体,而不是实现页面跳转
    public String index(){
        System.out.println("hello index.jsp");
        return "index";
    }

    @RequestMapping("hello")
    public String helloworld() {
        System.out.println("hello world");
        log.debug("hello==={}++++{}", "world", "");
        return "hello world";
    }

    @RequestMapping("/jsonObj")
    public Map<String, Object> jsonObj() {
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("msg", "this is response json data");
        log.info("json_msg={}", resultMap.toString());
        return resultMap;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值