Spring Boot uses Commons Logging for all internal Logging, but the default configuration also provides support for common Logging, such as Java Util Logging, Log4J, Log4J2, and Logback. Each Logger can be configured to output log content using either a console or a file.

The default log output is: 2016-04-1308:23:50.120 INFO 37397– [main] org.hibernate.Version: HHH000412: Hibernate Core {4.3.11.final} output elements are as follows: Time date – millisecond log level – ERROR, WARN, INFO, DEBUG or TRACE Process ID separator – identifies the thread name from which the actual log is started. – The Logger name is enclosed in square brackets (which may truncate console output). – The log content usually uses the class name of the source code

Console output

ERROR, WARN, and INFO log output to the console is configured by default in Spring Boot. You can switch to the DEBUG level in two ways: add the -debug flag after running a command, for example: $Java -jar myapp.jar -debug =true in application.properties The core Loggers (including embedded containers, Hibernate, and Spring) will output more, but your own application logs will not output at DEBUG level.

Colorful output

If your terminal supports ANSI, setting color output will make the log more readable. Through the application. The properties set in the spring. The output. The ANSI. Enabled parameters to support. NEVER: disables anSI-colored output (the default). DETECT: The system checks whether the terminal supports ANSI-colored output. If yes, color output is used

The output file

The Spring Boot default configuration is only printed to the console and is not recorded in a file, but is usually recorded in a file when used in production environments. To increase file output, you need to configure the logging.file or logging.path property in application.properties. Logging.file, set the file, which can be an absolute or relative path. For example, logging.file=my.log logging.path. If you set the directory, the spring.log file will be created in this directory and the log content will be written, for example: Logging. path=/var/log log files are truncated when the size is 10Mb. New log files are generated. The default levels are ERROR, WARN, and INFO

Level control

In Spring Boot, you only need to configure the logging level control in application.properties. *= level logging.level: log level control prefix, * is the package name or Logger name. Level: Options TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF Example: Logging.level.com.didispace=DEBUG:com.didispace package logging. All the class in order to DEBUG level output level. The root = WARN: root log to WARN level output

Custom log configuration

Since the logging service is typically initialized before the ApplicationContext is created, it does not have to be controlled through Spring’s configuration file. Therefore, log control and management can still be well supported through system properties and traditional Spring Boot external configuration files. Logback: logback-spring. XML, logback-spring.groovy, logback. XML, logback.groovy Log4j: Properties, log4j-spring. XML, log4j.properties, log4j. XML Log4j2: JDK (Java Util Logging) : Logging.properties Spring Boot officially recommends using a -spring file name for your logging configuration (e.g. using logback-spring. XML instead of logback.xml).

Customize the output format

In Spring Boot, you can control the output format by setting the following parameters in application.properties: logging.pattern.console: Logging.pattern.file: Define styles for output to a file (JDK Logger is not supported)

Note: like friends can like attention, learning progress together