官术网_书友最值得收藏!

Logs and problem solving

Spring Boot starter packages provide a logback, that we can use for logging without any configuration. The following sample code shows how to use logging:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CardatabaseApplication {
private static final Logger logger = LoggerFactory.getLogger(CardatabaseApplication.class);
public static void main(String[] args) {
SpringApplication.run(CardatabaseApplication.class, args);
logger.info("Hello Spring Boot");
}
}

Logging messages can be seen in the console after you run the project:

There are seven different levels for logging—TRACE, DEBUG, INFO, WARN, ERROR, FATAL, and OFF. You can configure the level of logging in your Spring Boot application.properties file. The file can be found in the resources folder inside your project:

If we set the logging level to INFO, we can see log messages from levels that are under INFO (INFO, WARN, ERROR, and FATAL). In the following example, we set the log level for the root, but you can also set it at the package level:

logging.level.root=INFO

Now, when you run the project, you can't see the TRACE and DEBUG messages anymore. That might be a good setting for a production version of your application:

Spring Boot is using Apache Tomcat (http://tomcat.apache.org/) as an application server, by default. As a default, Tomcat is running in port 8080. You can change the port in the application.properties file. The following setting will start Tomcat in port 8081:

server.port=8081

If the port is occupied, the application won't start and you will see the following message in the console:

You have to stop the process that is listening on port 8080 or use another port in your Spring Boot application.

主站蜘蛛池模板: 庆阳市| 堆龙德庆县| 鄂伦春自治旗| 沅江市| 那曲县| 绥江县| 金沙县| 桑日县| 西林县| 绍兴县| 霍城县| 惠安县| 临邑县| 松江区| 屏山县| 固阳县| 都江堰市| 汶上县| 江都市| 元阳县| 桐乡市| 鲁山县| 聂拉木县| 措勤县| 安平县| 靖安县| 资兴市| 夏津县| 汨罗市| 安塞县| 马边| 会宁县| 杭州市| 云安县| 宜良县| 大姚县| 麻城市| 泸定县| 张掖市| 罗山县| 宝应县|