I am currently using the DailyRollingFileAppender Class in log4j to do daily log file appending but I want to have the log files separated in the following format:
DATA.log.<date>_<time>_<random_#>
This should be done once per program execution so I end up with something like...
DATA.log.2011-01-13_12-46-38_<26>
DATA.log.2011-01-13_12-46-38_<79>
DATA.log.2011-01-13_12-46-38_<590>
Where different log files from different environments can be pooled together.
Is there anyway to do this without extending the FileAppender Class? At least, is there a way to do:
DATA.log.<date>_<time>_<sequential_#>.log
Thanks
Edit: I am already using DailyRollingFileAppender to get something like DATA.log.2011-01-13. What I want to know how to do is get the log file to rollover after each program execution (or before each program execution) and add a random numeric string at the end.
Log4j is a logging framework written in Java that provides an easy way for logging in Selenium. In a nutshell, the framework gives out information about everything that goes on during the software execution. Log4j also provides insight into anything that may have gone wrong during software execution or automation.
The Log4j logging settings are stored in the file app_data /conf/server/log4j. properties, where app_data is the application data folder. You can edit this file directly on the server or open it by clicking Settings > Logging.
have a look at : Setting a log file name to include current date in Log4j
EDIT : Add this class to your project, and use it as appender :
import java.util.Random;
import org.apache.log4j.DailyRollingFileAppender;
public class MyAppender extends DailyRollingFileAppender {
@Override
public void setFile(String fileName) {
if (fileName.indexOf("%rnd") >= 0) {
Random r = new Random();
fileName = fileName.replaceAll("%rnd", Integer.toString(r.nextInt()));
}
super.setFile(fileName);
}
}
Then just set your appender's filename to something like : filename.%rnd.log
log4j.appender.R=MyAppender.MyAppender
log4j.appender.R.File=.\\test.%rnd.log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With