log4j generate a log file name with a date

Source: Internet
Author: User
Tags log4j

For task requirements, the output log needs to be saved as file name + date format.

The workaround is simple:

Log4j.appender.file=org.apache.log4j.dailyrollingfileappender
#log4j. Appender.file.file=hibernate.log
Log4j.appender.file.file=. /logs/Log_
Log4j.appender.file.datepattern=yyyy-mm-dd '. txt ' #后缀可为. txt/. Log/. HTML, etc.
Log4j.appender.file.layout=org.apache.log4j.patternlayout
LOG4J.APPENDER.FILE.LAYOUT.CONVERSIONPATTERN=[%-5P]%d{yyyy-mm-dd Hh:mm:ss,sss} method:%l%n%m%n

The output file name is Log_, check the information, if the day's words, the file name for the moment is log_, and want to be named like "Log_20150724.txt" such a log file, when the time is over the day, such as 25th, will save the previous file as Log_ 20150724.txt, and then create a 25th Log_ file, and so on.

Therefore, you need to modify the system time to see the generated log when testing.

Related Article

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.