问题描述
今天在复习springboot的时候突然发现springboot2.1.3的版本,在写好启动类启动之后在控制台查看启动信息,突然发现日志信息变少了。就比如下面这样。
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2019-05-07 19:18:31.529 INFO 15104 --- [ main] com.App : Starting App on L006 with PID 15104 (D:\idea\springboot_demo1\target\classes started by Administrator in D:\idea\springboot_demo1)
2019-05-07 19:18:31.535 INFO 15104 --- [ main] com.App : No active profile set, falling back to default profiles: default
2019-05-07 19:18:35.934 INFO 15104 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-05-07 19:18:35.974 INFO 15104 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-05-07 19:18:35.974 INFO 15104 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2019-05-07 19:18:35.982 INFO 15104 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\RuanJian\Java\jdk1.8.0_162\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;D:\RuanJian\Java\jdk1.8.0_162\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;D:\RuanJian\TortoiseSVN\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;;.]
2019-05-07 19:18:36.136 INFO 15104 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-05-07 19:18:36.136 INFO 15104 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4448 ms
2019-05-07 19:18:36.413 INFO 15104 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-07 19:18:36.651 INFO 15104 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-07 19:18:36.654 INFO 15104 --- [ main] com.App : Started App in 5.813 seconds (JVM running for 9.255)
前提是我写的东西没报错,然后在浏览器也可以正常访问,但是日志信息就是不详细,然后就去网上查找资料。
原因分析
在网上找了找之后发现是在springboot版本升级的时候更改了日志显示的方式。详细信息可以去springboot的官网看文档。
解决办法
在springboot的配置文件中设置日志的级别,就像下面这样
配置文件名称 -- application.properties
logging.level.web=trace
在配置文件中填上这句话问题就解决了,效果如下
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.3.RELEASE)
2019-05-07 19:26:31.480 INFO 16500 --- [ main] com.App : Starting App on L006 with PID 16500 (D:\idea\springboot_demo1\target\classes started by Administrator in D:\idea\springboot_demo1)
2019-05-07 19:26:31.485 INFO 16500 --- [ main] com.App : No active profile set, falling back to default profiles: default
2019-05-07 19:26:35.959 INFO 16500 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2019-05-07 19:26:35.986 INFO 16500 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-05-07 19:26:35.986 INFO 16500 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.16]
2019-05-07 19:26:35.997 INFO 16500 --- [ main] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [D:\RuanJian\Java\jdk1.8.0_162\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;D:\RuanJian\Java\jdk1.8.0_162\bin;C:\Program Files\MySQL\MySQL Utilities 1.6\;D:\RuanJian\TortoiseSVN\bin;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;;.]
2019-05-07 19:26:36.127 INFO 16500 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-05-07 19:26:36.128 DEBUG 16500 --- [ main] o.s.web.context.ContextLoader : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2019-05-07 19:26:36.128 INFO 16500 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4508 ms
2019-05-07 19:26:36.132 TRACE 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Added existing Servlet initializer bean 'dispatcherServletRegistration'; order=2147483647, resource=class path resource [org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration.class]
2019-05-07 19:26:36.147 TRACE 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean 'characterEncodingFilter'; order=-2147483648, resource=class path resource [org/springframework/boot/autoconfigure/web/servlet/HttpEncodingAutoConfiguration.class]
2019-05-07 19:26:36.147 TRACE 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean 'hiddenHttpMethodFilter'; order=-10000, resource=class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]
2019-05-07 19:26:36.147 TRACE 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean 'formContentFilter'; order=-9900, resource=class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]
2019-05-07 19:26:36.147 TRACE 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Created Filter initializer for bean 'requestContextFilter'; order=-105, resource=class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]
2019-05-07 19:26:36.153 DEBUG 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Mapping filters: characterEncodingFilter urls=[/*], hiddenHttpMethodFilter urls=[/*], formContentFilter urls=[/*], requestContextFilter urls=[/*]
2019-05-07 19:26:36.153 DEBUG 16500 --- [ main] o.s.b.w.s.ServletContextInitializerBeans : Mapping servlets: dispatcherServlet urls=[/]
2019-05-07 19:26:36.277 TRACE 16500 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped [/**/favicon.ico] onto ResourceHttpRequestHandler [class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/], ServletContext resource [/], class path resource []]
2019-05-07 19:26:36.278 DEBUG 16500 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Patterns [/**/favicon.ico] in 'faviconHandlerMapping'
2019-05-07 19:26:36.431 INFO 16500 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-05-07 19:26:36.445 DEBUG 16500 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : ControllerAdvice beans: 0 @ModelAttribute, 0 @InitBinder, 1 RequestBodyAdvice, 1 ResponseBodyAdvice
2019-05-07 19:26:36.514 TRACE 16500 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :
c.c.HelloController:
{GET /hello/{name}/{password}}: hello(String,String)
2019-05-07 19:26:36.521 TRACE 16500 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :
c.c.UserController:
{ /user/{id}}: userInFo(Integer)
2019-05-07 19:26:36.524 TRACE 16500 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping :
o.s.b.a.w.s.e.BasicErrorController:
{ /error}: error(HttpServletRequest)
{ /error, produces [text/html]}: errorHtml(HttpServletRequest,HttpServletResponse)
2019-05-07 19:26:36.527 DEBUG 16500 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : 4 mappings in 'requestMappingHandlerMapping'
2019-05-07 19:26:36.531 DEBUG 16500 --- [ main] o.s.w.s.h.BeanNameUrlHandlerMapping : Detected 0 mappings in 'beanNameHandlerMapping'
2019-05-07 19:26:36.538 TRACE 16500 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped [/webjars/**] onto ResourceHttpRequestHandler ["classpath:/META-INF/resources/webjars/"]
2019-05-07 19:26:36.539 TRACE 16500 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped [/**] onto ResourceHttpRequestHandler ["classpath:/META-INF/resources/", "classpath:/resources/", "classpath:/static/", "classpath:/public/", "/"]
2019-05-07 19:26:36.539 DEBUG 16500 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Patterns [/webjars/**, /**] in 'resourceHandlerMapping'
2019-05-07 19:26:36.547 DEBUG 16500 --- [ main] .m.m.a.ExceptionHandlerExceptionResolver : ControllerAdvice beans: 0 @ExceptionHandler, 1 ResponseBodyAdvice
2019-05-07 19:26:36.687 INFO 16500 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2019-05-07 19:26:36.692 INFO 16500 --- [ main] com.App
下面对上面到的日志级别关键字进行解释
logging.level.web=trace
-
trace 很低的日志级别,一般不会使用。
-
all 最低等级的,用于打开所有日志记录。
-
debug 指出细粒度信息事件对调试应用程序是非常有帮助的,主要用于开发过程中打印一些运行信息。
-
info 消息在粗粒度级别上突出强调应用程序的运行过程。打印一些你感兴趣的或者重要的信息,这个可以用于生产环境中输出程序运行的一些重要信息,但是不能滥用,避免打印过多的日志。
-
warn 表明会出现潜在错误的情形,有些信息不是错误信息,但是也要给程序员的一些提示。
-
error 指出虽然发生错误事件,但仍然不影响系统的继续运行。打印错误和异常信息,如果不想输出太多的日志,可以使用这个级别。
-
fatal 指出每个严重的错误事件将会导致应用程序的退出。这个级别比较高了。重大错误,这种级别你可以直接停止程序了。
-
off 最高等级的,用于关闭所有日志记录。
要是有不合适的地方还请大佬们多多指点。
======================= end =======================
网友评论