In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Recently I came into contact with a SpringBoot project, why did SpringBoot appear? What are the advantages of SpringBoot? In fact, SpringBoot was born in an era of high concurrency. SpringBoot is a Sping-based development that provides a faster entry experience, creating Spring applications that can run independently, embedding directly into Tomcat or Jetty servers, without packaging into WAR files, and providing recommended basic POM files (starter) to simplify Apache Maven configuration, automatically configure the Spring framework according to project dependencies as much as possible, and provide features that can be used directly in production environments, such as performance indicators. Application information and application health check, right out of the box, no code generation, no XML configuration. You can also modify the default values to meet specific requirements, and a large number of other projects are based on Spring Boot, such as Spring Cloud.
In short, SpringBoot makes coding easier, configuration easier, deployment easier, and monitoring easier.
So what are the shortcomings of SpringBoot? Rely on too much, any SpringBoot application is dozens of M, lack of monitoring integration scheme, security management scheme, Chinese documents and materials are too few and not deep enough.
The previous simple talk about the characteristics of SpringBoot, let's get back to business, learn the log of SpringBoot, you can refer to the official website https://docs.spring.io/spring-boot/docs/1.3.7.RELEASE/reference/htmlsingle/#b certain oot-features-logging related documents.
If you have read SpringBoot, then you must not read the file application.properties. Will be strange, we can also see the relevant description in the official documents.
Logging.level.*= # Log levels severity mapping. For instance `logging.level.org.springframework= DEBUG`
The above configuration can set the output level of the log.
Logging.level.com.zcp.test.springboot.service.UserService=debug
You can also set the log level of a specific class, as I did.
Logging.path= # Location of the log file. For instance `/ var/ log`
This setting is the path to set the log
Such as: logging.path=e:/tep/logs
Through such a simple setting, the specified level of logs can be printed in the directory we want to output. Isn't it easy?
There are other instructions as follows:
The default log level for springboot is info
* it can be set through logging.level.*=debug. * it can be a package or a class.
*
* examples of use:
Logging.level.com.zcp.test.springboot.service.UserService=debug
Logging.level.com.zcp.test.springboot.UserDao=OFF
*
* Log levels are: TRACE.DEBUG,INFO,WARN,ERROR,FATAL.OFF
* log level OFF means to disable logging
* logging.file=e:/tmp/my.log specifies the file's
* logging.path direct log directory (log name is spring.log at this time)
* Log file output. After the file size is 10m, it will be split.
* logging.pattern.console this is the patten that configures the output log of the console
* logging.pattern.file is the pattern that configures the log file input log
*
*
* springboot supports logback by default
* in other words, you only need to distribute a logback.xml,logback-spring.xml file in classpath to specify the output of the log.
We can see from the official website that SpringBoot supports all of our common logging components. Log4j,log4j2.logback.
So it will be easier if we use the default logback.xml to configure log information by default.
You only need to create a new logback.xml file under a path in classpath.
For learning, please refer to this document: http://www.cnblogs.com/warking/p/5710303.html
Common configuration information for logback.xml is as follows
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n
${LOG_HOME} / TestWeb.log.%d {yyyy-MM-dd} .log
thirty
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger {50} -% msg%n
10MB
What if you want your log level configuration to be more fine-grained? You can see the following configuration information:
% d {yyyy-MM-dd HH:mm:ss} [% thread]%-5level% logger -% msg%n
ERROR
ACCEPT
DENY
${log_dir} /% d {yyyy-MM-dd} / error-log.log
${maxHistory}
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger -% msg%n
WARN
ACCEPT
DENY
${log_dir} /% d {yyyy-MM-dd} / warn-log.log
${maxHistory}
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger -% msg%n
INFO
ACCEPT
DENY
${log_dir} /% d {yyyy-MM-dd} / info-log.log
${maxHistory}
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger -% msg%n
DEBUG
ACCEPT
DENY
${log_dir} /% d {yyyy-MM-dd} / debug-log.log
${maxHistory}
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger -% msg%n
TRACE
ACCEPT
DENY
${log_dir} /% d {yyyy-MM-dd} / trace-log.log
${maxHistory}
% d {yyyy-MM-dd HH:mm:ss.SSS} [% thread]%-5level% logger -% msg%n
If you do not want to use logback, you can refer to the following steps if you want to use other logging components:
*
* steps to use other logging components: ()
* 1. Exclude the default logging component: spring-boot-starter-logging
* 2: add a new log path dependency
* 3: put the corresponding configuration file under classpath
The following configuration is to exclude the default log4j2 and add the dependencies of the required logging components.
Org.springframework.boot
Spring-boot-starter
Org.springframework.boot
Spring-boot-starter-log4j2
Org.springframework.boot
Spring-boot-starter-log4j2
In fact, it is possible to put logback.xml directly under resources.
You can refer to the configuration information of a simple log4j.xml as follows:
The above part of the content comes from the network, if there is a copyright problem, please contact the author to delete it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.