• Spring Boot之日志处理


    在主配置类中添加:

    Logger logger =LoggerFactory.getLogger(HelloworldApplicationTests.class);
    @Test
    	public void test_log(){
    		logger.trace("trace******");
    		logger.debug("debug******");
    		logger.info("info******");
    		logger.warn("warn******");
    		logger.error("error******");
    	}
    

      

     

     Spring boot默认的日志级别是INFO(即只打印 info及之后级别的信息):也可以自定义级别:

    全局配置文件中logging.level.com.doublechen.helloworld=warn

    在配置文件中写入logging.file.name=springboot.log,可以将日志信息输出到文件中。

    指定日志显示格式:

      a.在控制台中:

        logging.pattern.console=%d{yyyy-MM-dd} [%thread] %-5level %logger{50} - %msg%n

              %d:日期时间

              %thread:线程名称

              %-5level:显示日志级别,-5表示从左显示5个字符宽度

              %logger{50}:设置日志长度

              %msg:日志消息

              %n:回车
      b.在文件中:

        logging.pattern.file=%d{yyyy-MM-dd} ** [%thread] ** %-5level ** %logger{50}** %msg%n

  • 相关阅读:
    JS 数组去重复值
    git 上传项目 到github
    IntelliJ IDEA 创建maven 项目 并且,将springMVC 与Mybatis 整合
    easyui datagrid 动态添加columns属性
    codeMirror的简单使用,js比较文本差异(标注出增删改)
    sql注入
    Web For Pentester靶场
    一些数据库
    nginx的使用场景
    dockerfile
  • 原文地址:https://www.cnblogs.com/jccjcc/p/14181907.html
Copyright © 2020-2023  润新知