Spring Boot 4-日志配置

Posted zengpingtang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring Boot 4-日志配置相关的知识,希望对你有一定的参考价值。

日志配置
Springboot支持Log4j、Logback等作为日志框架。默认情况下使用Logback作为框架。

配置日志前日志情况
  .   ____          _            __ _ _
 /\\ / ___‘_ __ _ _(_)_ __  __ _ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  ‘  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.4.RELEASE)

2019-05-02 15:13:27.838  INFO 10600 --- [           main] c.t.h.SpringbootHelloworldApplication    : Starting SpringbootHelloworldApplication on DESKTOP-J6HT18A with PID 10600 (D:\eclipse-workspace\springboot-workspace\springboot-helloworld\target\classes started by tangzengping in D:\eclipse-workspace\springboot-workspace\springboot-helloworld)
2019-05-02 15:13:27.842  INFO 10600 --- [           main] c.t.h.SpringbootHelloworldApplication    : No active profile set, falling back to default profiles: default
2019-05-02 15:13:28.945  INFO 10600 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8086 (http)
2019-05-02 15:13:28.970  INFO 10600 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-02 15:13:28.972  INFO 10600 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-05-02 15:13:29.080  INFO 10600 --- [           main] o.a.c.c.C.[.[localhost].[/helloboot]     : Initializing Spring embedded WebApplicationContext
2019-05-02 15:13:29.080  INFO 10600 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1186 ms
2019-05-02 15:13:29.349  INFO 10600 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService ‘applicationTaskExecutor‘
2019-05-02 15:13:29.565  INFO 10600 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8086 (http) with context path ‘/helloboot‘
2019-05-02 15:13:29.570  INFO 10600 --- [           main] c.t.h.SpringbootHelloworldApplication    : Started SpringbootHelloworldApplication in 2.149 seconds (JVM running for 2.789)
2019-05-02 15:13:35.821  INFO 10600 --- [nio-8086-exec-1] o.a.c.c.C.[.[localhost].[/helloboot]     : Initializing Spring DispatcherServlet ‘dispatcherServlet‘
2019-05-02 15:13:35.821  INFO 10600 --- [nio-8086-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet ‘dispatcherServlet‘
2019-05-02 15:13:35.828  INFO 10600 --- [nio-8086-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms

 



配置日志文件和配置日志级别
logging:
  file: D:\eclipse-workspace\springboot-workspace\logdata\log.log
  level:
    org.springframework.web: DEBUG 

 

  .   ____          _            __ _ _
 /\\ / ___‘_ __ _ _(_)_ __  __ _ \ \ \ ( ( )\___ | ‘_ | ‘_| | ‘_ \/ _` | \ \ \  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  ‘  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.4.RELEASE)

2019-05-02 15:11:21.743  INFO 9480 --- [           main] c.t.h.SpringbootHelloworldApplication    : Starting SpringbootHelloworldApplication on DESKTOP-J6HT18A with PID 9480 (D:\eclipse-workspace\springboot-workspace\springboot-helloworld\target\classes started by tangzengping in D:\eclipse-workspace\springboot-workspace\springboot-helloworld)
2019-05-02 15:11:21.746  INFO 9480 --- [           main] c.t.h.SpringbootHelloworldApplication    : No active profile set, falling back to default profiles: default
2019-05-02 15:11:23.043  INFO 9480 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8086 (http)
2019-05-02 15:11:23.067  INFO 9480 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-05-02 15:11:23.068  INFO 9480 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.17]
2019-05-02 15:11:23.171  INFO 9480 --- [           main] o.a.c.c.C.[.[localhost].[/helloboot]     : Initializing Spring embedded WebApplicationContext
2019-05-02 15:11:23.171 DEBUG 9480 --- [           main] o.s.web.context.ContextLoader            : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2019-05-02 15:11:23.171  INFO 9480 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1379 ms
2019-05-02 15:11:23.270 DEBUG 9480 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/**/favicon.ico] in ‘faviconHandlerMapping‘
2019-05-02 15:11:23.391  INFO 9480 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService ‘applicationTaskExecutor‘
2019-05-02 15:11:23.406 DEBUG 9480 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2019-05-02 15:11:23.470 DEBUG 9480 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : 3 mappings in ‘requestMappingHandlerMapping‘
2019-05-02 15:11:23.487 DEBUG 9480 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Patterns [/webjars/**, /**] in ‘resourceHandlerMapping‘
2019-05-02 15:11:23.505 DEBUG 9480 --- [           main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2019-05-02 15:11:23.948  INFO 9480 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8086 (http) with context path ‘/helloboot‘
2019-05-02 15:11:23.952  INFO 9480 --- [           main] c.t.h.SpringbootHelloworldApplication    : Started SpringbootHelloworldApplication in 2.662 seconds (JVM running for 4.888)
2019-05-02 15:11:47.014  INFO 9480 --- [nio-8086-exec-3] o.a.c.c.C.[.[localhost].[/helloboot]     : Initializing Spring DispatcherServlet ‘dispatcherServlet‘
2019-05-02 15:11:47.015  INFO 9480 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet        : Initializing Servlet ‘dispatcherServlet‘
2019-05-02 15:11:47.015 DEBUG 9480 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet        : Detected StandardServletMultipartResolver
2019-05-02 15:11:47.021 DEBUG 9480 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet        : enableLoggingRequestDetails=‘false‘: request parameters and headers will be masked to prevent unsafe logging of potentially sensitive data
2019-05-02 15:11:47.022  INFO 9480 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms
2019-05-02 15:11:47.074 DEBUG 9480 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet        : GET "/helloboot/", parameters={}
2019-05-02 15:11:47.078 DEBUG 9480 --- [nio-8086-exec-3] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public java.lang.String com.tzp.helloworld.controller.HelloSpringBoot.hello()
2019-05-02 15:11:47.139 DEBUG 9480 --- [nio-8086-exec-3] m.m.a.RequestResponseBodyMethodProcessor : Using ‘text/html‘, given [text/html, application/xhtml+xml, image/webp, image/apng, application/signed-exchange;v=b3, application/xml;q=0.9, */*;q=0.8] and supported [text/plain, */*, text/plain, */*, application/json, application/*+json, application/json, application/*+json]
2019-05-02 15:11:47.139 DEBUG 9480 --- [nio-8086-exec-3] m.m.a.RequestResponseBodyMethodProcessor : Writing ["hello spring boot tony"]
2019-05-02 15:11:47.167 DEBUG 9480 --- [nio-8086-exec-3] o.s.web.servlet.DispatcherServlet        : Completed 200 OK

 

以上是关于Spring Boot 4-日志配置的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot 日志详解

spring boot 日志/页面处理实体类构建后台管理

spring-boot中logback日志配置

spring boot2.0+ 中配置log4j日志

SpringBootspringboot日志配置

SpringBootspringboot日志配置