zoukankan      html  css  js  c++  java
  • Spring Boot 简单日志配置

    在生产环境中,只打印error级别的错误,在测试环境中,可以调成debug
    application.properties文件

    ## 默认使用logback logging.level.root
    =error ##warn,debug logging.level.org.springframework.web=error logging.file=d://log/my.log logging.pattern.console=%d{yyyy/MM/dd-HH:mm:ss} [%thread] %-5level %logger- %msg%n logging.pattern.file=%d{yyyy/MM/dd-HH:mm} [%thread] %-5level %logger- %msg%n
    package com.wzy.ctl;
    
    
    import com.wzy.entity.User;
    import com.wzy.ser.UserSer;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RestController;
    
    import javax.annotation.Resource;
    import java.util.List;
    
    @RestController
    @RequestMapping("user")
    public class UserCtl {
        @Resource
        private UserSer u;
        private final static Logger logger = LoggerFactory.getLogger(UserCtl.class);
        @RequestMapping(method=RequestMethod.GET,value = "getUser")
        public List<User> getUser(){
            try{
                float a = 1 / 0;
            } catch (Exception e){
                logger.error("出现异常"+e.getMessage());
            }
            return u.getUser();
        }
        
    }

    当系统出现异常后:

    有一点值得注意:当日志一直打印,会出现linux系统内存不足的情况,可以做个定时任务,定期清理一下日志

  • 相关阅读:
    Poj-1088-滑雪
    Poj-2250-Compromise
    CF
    KMP算法
    01背包
    NY 269 VF
    PHP--1+2+3……100=?
    PHP企业发放的奖金--if...elseif...
    2019年中级考试题(附答案)
    PHP的IF条件语句-- 输入一个数字进行判断等级
  • 原文地址:https://www.cnblogs.com/wwzyy/p/9258203.html
Copyright © 2011-2022 走看看