"Spring boot logback" Log logback generate log file under this project, not in the specified log file directory/specified log file reached the maximum value is not cut according to the configuration

Source: Internet
Author: User

The original log file is configured as follows:

<?XML version= "1.0" encoding= "UTF-8"?><ConfigurationScan= "true"Scanperiod= "Seconds"Debug= "false">    <Contextname>Logback</Contextname>    <!--define the storage address of the log file do not use relative paths in Logback configuration -    < Propertyname= "Log.path"value= "E:\\log\\logback.log" />    <!--Output to console -    <Appendername= "Console"class= "Ch.qos.logback.core.ConsoleAppender">        <Filterclass= "Ch.qos.logback.classic.filter.ThresholdFilter">            < Level>INFO</ Level>        </Filter>        <Withjansi>True</Withjansi>        <Encoder>            <!--<pattern>%d%p (%file:%line\)-%m%n</pattern> -            <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break -            <pattern>%black (console-)%red (%d{yyyy-mm-dd HH:mm:ss})%green ([%thread])%highlight (%-5level)%boldmagenta (%logger)-%cyan (%msg% N</pattern>            <CharSet>UTF-8</CharSet>        </Encoder>    </Appender>    <!--Output to File -    <Appendername= "File"class= "Ch.qos.logback.core.rolling.RollingFileAppender">        <file>${log.path}</file>        <Rollingpolicyclass= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy">            <Filenamepattern>Logback.%d{yyyy-mm-dd-hh-mm}.log</Filenamepattern>            <maxhistory>30</maxhistory>            <Totalsizecap>1GB</Totalsizecap>        </Rollingpolicy>        <Encoder>            <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break -            <pattern>File records-%d{yyyy-mm-dd HH:MM:SS} [%thread]%-5level%logger{36}-%msg%n</pattern>            <CharSet>GBK</CharSet>        </Encoder>    </Appender>    <Root Level= "Info">        <Appender-refref= "Console" />        <Appender-refref= "File" />    </Root>    <Loggername= "Com.sxd.controller"/>    <Loggername= "Com.sxd.util.LogTestController" Level= "WARN"additivity= "false">        <Appender-refref= "Console" />    </Logger></Configuration>
View Code

But during the operation, it was found that

The generated log file is not split according to the date of the month and year in the configuration above.

Does not automatically clean up when you hit the maximum number of files,

is not generated to the specified log file directory, but is generated under the project root directory.

<?XML version= "1.0" encoding= "UTF-8"?><ConfigurationScan= "true"Scanperiod= "Seconds"Debug= "false">    <Contextname>Logback</Contextname>    <!--define the storage address directory for log files -    < Propertyname= "Log_home"value= "e:/log/"/>    <!--Output to console -    <Appendername= "Console"class= "Ch.qos.logback.core.ConsoleAppender">        <Filterclass= "Ch.qos.logback.classic.filter.ThresholdFilter">            < Level>INFO</ Level>        </Filter>        <Withjansi>True</Withjansi>        <Encoder>            <!--<pattern>%d%p (%file:%line\)-%m%n</pattern> -            <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break -            <pattern>%black (console-)%red (%d{yyyy-mm-dd HH:mm:ss})%green ([%thread])%highlight (%-5level)%boldmagenta (%logger)-%cyan (%msg% N</pattern>            <CharSet>UTF-8</CharSet>        </Encoder>    </Appender>    <!--Output to File -    <Appendername= "File"class= "Ch.qos.logback.core.rolling.RollingFileAppender">        <Rollingpolicyclass= "Ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">            <Filenamepattern>${log_home}logback.%d{yyyy-mm-dd-hh-mm}[%i].log</Filenamepattern>            <MaxFileSize>10kb</MaxFileSize>            <maxhistory>30</maxhistory>            <Totalsizecap>1GB</Totalsizecap>        </Rollingpolicy>        <Encoder>            <!--formatted output:%d: Represents the date%thread: Indicates the thread name%-5level: The level shows 5 character widths from the left%msg: Log message%n: is a line break -            <pattern>File records-%d{yyyy-mm-dd HH:MM:SS} [%thread]%-5level%logger-%msg%n</pattern>            <CharSet>UTF-8</CharSet>        </Encoder>    </Appender>    <Root Level= "Info">        <Appender-refref= "Console" />        <Appender-refref= "File" />    </Root>    <Loggername= "Com.sxd.controller"/>    <Loggername= "Com.sxd.util.LogTestController" Level= "WARN"additivity= "false">        <Appender-refref= "Console" />    </Logger></Configuration>
View Code

"Spring boot logback" Log logback generate log file under this project, not in the specified log file directory/specified log file reached the maximum value is not cut according to the configuration

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.