(1) Problem: A program developed locally using Spring-boot has always wanted files to be exported to a folder by day. But has been successful.
Resolution process:
Think of the log first to configure the Log4j.properties file, but has not been successful, I put the file in the source directory. does not take effect.
Then check the data to understand that the Spring-boot log output is using the form of logback. So set up:
(1) Set Application.properties file
Logging.level.com.huike=info
(2) Set Logback-spring.xml file
<?xml version= "1.0" encoding= "UTF-8"?
<configuration scan= "true" scanperiod= "seconds" debug= " False "
<contextname>logback</contextname>
<!--output to console-->
<appender name=" Console "class=" Ch.qos.logback.core.ConsoleAppender "
<!--<filter class=" Ch.qos.logback.classic.filter.ThresholdFilter,
<level>error</level>
</filter>--
<encoder>
<pattern>%d{yyyy-mm-dd HH:mm:ss} [%thread]%5level%logger{36}-%msg%n</pattern
</encoder>
</appender>
<!--generate logs by day--
<appender name= "LogFile" class= "Ch.qos.logback.core.rolling.RollingFileAppender" >
<Prudent>true</Prudent>
<rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" >
<FileNamePattern>
Poslog/%d{yyyy-mm-dd}.log
</FileNamePattern>
</rollingPolicy>
<layout class= "Ch.qos.logback.classic.PatternLayout" >
<Pattern>
%d{yyyy-mm-dd HH:MM:SS} [%thread]%5level%logger{36}-%msg%n
</Pattern>
</layout>
</appender>
<root level= "Debug,error" >
<appender-ref ref= "Console"/>
<appender-ref ref= "LogFile"/>
</root>
<!--<logger name= "Com.pos" level= "INFO" additivity= "false" >
<appender-ref ref= "Console"/>
</logger>
</configuration>
The final file is generated under the Files folder in the project directory:
Summary: The spring framework uses a log profile that is used to generate files. A configuration file such as log4j is not in effect.
About Spring-boot the configuration of the log output to the console and the specified file