zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    SpringMVC学习笔记----常用注解
    python常用模块学习1
    python基础模块,包
    python-验证功能的装饰器示例
    python闭包及装饰器
    关于windows服务器配置
    python高阶函数
    python-生成器和迭代器
    linux--基础知识5
    python基础-文件操作的其他方法
  • 原文地址:https://www.cnblogs.com/jccjcc/p/14181907.html
Copyright © 2011-2022 走看看