1 46 package org.mr.core.log; 47 48 import java.io.File ; 49 import java.io.IOException ; 50 51 import org.apache.log4j.RollingFileAppender; 52 53 57 public class MantaLogAppender extends RollingFileAppender { 58 static String mantaName = null; 59 static boolean first = true; 60 public synchronized void setFile(String arg0, boolean arg1, boolean arg2, 61 int arg3) throws IOException { 62 if(mantaName!=null){ 63 arg0= arg0.replaceAll("%peer_name%",mantaName ); 64 File f = new File (arg0); 65 String path =f.getAbsolutePath(); 66 String name = f.getName(); 67 String dirPath = path.substring(0,path.lastIndexOf(name)); 68 File dir =new File (dirPath); 69 if(dir.exists() == false){ 70 StartupLogger.log.info("Log folder does not exist, creating log folder at "+dirPath, "MantaLogAppender"); 72 dir.mkdir(); 73 }else{ 74 if(first){ 75 StartupLogger.log.info("Log folder found at "+dirPath, "MantaLogAppender"); 77 first = false; 78 } 79 80 } 81 } 82 super.setFile(arg0, arg1, arg2, arg3); 83 84 } 85 86 public static synchronized void setMantaName(String name){ 87 mantaName = name; 88 89 } 90 91 92 93 } 94 | Popular Tags |