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系统内存不足的情况,可以做个定时任务,定期清理一下日志

  • 相关阅读:
    TCPUDPSocket调试工具v2.2
    C#高性能Socket服务器IOCP实现
    c#使用HttpListener监听HTTP请求
    Winform Socket通信
    C# 方法中的this参数(扩展方法)
    C# 两种方法实现HTTP协议迷你服务器
    C#访问HTTP请求
    Socket通信原理
    C#数据decimal保留两位小数
    单机网站架构云化后架构图
  • 原文地址:https://www.cnblogs.com/wwzyy/p/9258203.html
Copyright © 2011-2022 走看看