简体   繁体   中英

How to test the pattern specified for Log4j date file name, and rolling appender?

I've updated the pattern used for naming the log file which should rollover if the log file reaches a size, and if the date/time roles rolls through midnight. But, how can I test the pattern specified for Log4j date file name, and rolling appender? I suppose I could play with my system time and see what happens but I'd rather do it some other way.

Also, I'd like to fill the log with some value that's close to the size specified in the configuration. Mainly if I have 10mb size limit, then I'd maybe like to pump say 9.9mb of junk into the file start up the service and watch as the log file is rolled in that case as well. How might I fill a file with random ascii text up to 9.9mb?

FWIW I am on a *nixy machine.

EDIT: Preferably without having to wait until midnight, or reducing the size of my configuration.

Leave your server running overnight and come back and check the next day, you would see the log file with the specified format.

Instead of specifying 10mb give some lower value like 1 mb and you could test that. If it works for 1 mn it would work for 10mb. Put a for loop and add some junck message to debug logs so that it would log those 1 mb.

For the size limit problem you can create a file full of random data until 9.9mb. The log library does not check the former information in the file, it just append the new log Yo the file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM