About Spring-boot the configuration of the log output to the console and the specified file

Source: Internet
Author: User
Tags log4j

(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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.