Scheme 1 :

Add parameters     -Dspring.output.ansi.enabled=ALWAYS

As shown in the figure below :



Rerun   The effect of



Scheme 2 :

springboot The default is logback journal , The initial build log is also colored , And then it disappeared because of some color , How to configure the configuration file ?

The steps are as follows :

Corresponding contents resource Add down logback.xml



The configuration file code is as follows :
<?xml version="1.0" encoding="UTF-8"?> <!-- Logback configuration. See
http://logback.qos.ch/manual/index.html --> <configuration scan="true"
scanPeriod="10 seconds"> <!--<include
resource="org/springframework/boot/logging/logback/base.xml" /> -->
<!-- Define the storage address and prefix name of the log file --> <property name="LOG_HOME" value="logs" /> <property
name="LOG_PREFIX" value="zuul-gateway" /> <!-- General information is generated by daily log file --> <appender
name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${LOG_HOME}/${LOG_PREFIX}-info.log</File> <rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!-- Filing every day
--> <fileNamePattern>${LOG_HOME}/${LOG_PREFIX}-info-%d{yyyyMMdd}.log.%i
</fileNamePattern> <!-- Maximum number of single log files 500MB, 30 Log cycle of days , Maximum cannot exceed 20GB -->
<maxFileSize>100MB</maxFileSize> <maxHistory>30</maxHistory>
<totalSizeCap>20GB</totalSizeCap> </rollingPolicy> <encoder>
<!-- Format output :%d Represents the date ,%thread Represents the thread name ,%-5level: Levels are shown from the left 5 Character width %msg: Log messages ,%n It's a newline -->
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}
-%msg%n</Pattern> </encoder> </appender> <!-- Error messages are generated daily --> <appender
name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level> </filter> <File>${LOG_HOME}/${LOG_PREFIX}-error.log</File>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <!-- Filing every day
--> <fileNamePattern>${LOG_HOME}/${LOG_PREFIX}-error-%d{yyyyMMdd}.log.%i
</fileNamePattern> <!-- Maximum number of single log files 500MB, 30 Log cycle of days , Maximum cannot exceed 20GB -->
<maxFileSize>100MB</maxFileSize> <maxHistory>30</maxHistory>
<totalSizeCap>20GB</totalSizeCap> </rollingPolicy> <encoder>
<!-- Format output :%d Represents the date ,%thread Represents the thread name ,%-5level: Levels are shown from the left 5 Character width %msg: Log messages ,%n It's a newline -->
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36}
-%msg%n</Pattern> </encoder> </appender> <appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender"> <encoder>
<!-- Format output :%d Represents the date ,%thread Represents the thread name ,%-5level: Levels are shown from the left 5 Character width %msg: Log messages ,%n It's a newline :
|%blue(%thread) thread as :DiscoveryClient-CacheRefreshExecutor-0-->
<pattern>%yellow(%date{yyyy-MM-dd HH:mm:ss}) |%highlight(%-5level)
|%green(%logger:%line) |%black(%msg%n)</pattern> </encoder> </appender> <!--
Log output level This setting does not print the log --> <root level="INFO"> <appender-ref ref="STDOUT" />
<appender-ref ref="INFO_FILE" /> <appender-ref ref="ERROR_FILE" /> </root>
</configuration>
 

stdout The core code is as follows : among yellow Equal color is a description of the output log color :
<pattern>%yellow(%date{yyyy-MM-dd HH:mm:ss}) |%highlight(%-5level)
|%green(%logger:%line) |%black(%msg%n)</pattern>
Operation effect diagram :



You can join if you don't understand   QQ Communication group :369022804 Group adding remarks :LP frame