package ;
import ;
import ;
import ;
import ;
import ;
import .;
import .;
import .;
public class PerRunRollingFileAppender extends FileAppender {
public static String LoggerNamePrefix="default";
private static final String DOT = ".";
private static final String UNDERLINE="_";
public PerRunRollingFileAppender() {
}
public PerRunRollingFileAppender(Layout layout, String filename, boolean append,
boolean bufferedIO, int bufferSize) throws IOException {
super(layout, filename, append, bufferedIO, bufferSize);
}
public PerRunRollingFileAppender(Layout layout, String filename, boolean append)
throws IOException {
super(layout, filename, append);
}
public PerRunRollingFileAppender(Layout layout, String filename)
throws IOException {
super(layout, filename);
}
public void activateOptions() {
if (fileName != null) {
try {
fileName = getNewLogFileName();
setFile(fileName, fileAppend, bufferedIO, bufferSize);
} catch (Exception e) {
("Error while activating log options", e,
ErrorCode.FILE_OPEN_FAILURE);
}
}
}
private String getNewLogFileName() {
if (fileName != null) {
final String LEFTPARENTHESIS="(";
final String RIGHTPARENTHESIS=")";
final File logFile = new File(fileName);
final String fileName = ();
final int dotIndex = (DOT);
String newFileName = "";
Integer number = -1;
File[] files = ().listFiles(new CustomFilter());
Pattern pattern = ("(?<=\\()[\\d]+");
if(files!=null&&>0){
number++;
for (File file : files) {
Matcher matcher = (());
if(()){
if(number<((0))){
number=((0));
}
}
}
}
if (dotIndex != -1) {
// the file name has an extension. so, insert the time stamp
// between the file name and the extension
String tempFileName = (0,dotIndex);
final int parenthesis = (LEFTPARENTHESIS);
if(parenthesis!=-1){
tempFileName=(parenthesis);
}
if(number>-1){
newFileName = LoggerNamePrefix + UNDERLINE+ tempFileName
+ LEFTPARENTHESIS+(++number)+RIGHTPARENTHESIS
+ (dotIndex);
}else{
newFileName = LoggerNamePrefix + UNDERLINE+ tempFileName
+ (dotIndex);
}
} else {
//是否存在文件名中存在()
if(number>-1){
newFileName = LoggerNamePrefix
+ UNDERLINE
+ fileName
+ LEFTPARENTHESIS+(++number)+RIGHTPARENTHESIS;
}else{
newFileName = LoggerNamePrefix + UNDERLINE+ fileName;
}
}
return () + + newFileName;
}
return null;
}
class CustomFilter implements FilenameFilter{
public boolean accept(File dir,String name){
File logFile = new File(fileName);
String fileName = ();
int indexDot = (DOT);
if(indexDot!=-1){
return (LoggerNamePrefix+UNDERLINE+(0,indexDot));
}else{
return (LoggerNamePrefix+UNDERLINE+fileName);
}
}
}
}