1 26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers; 27 28 import java.io.File ; 29 import java.io.FileWriter ; 30 import java.io.PrintWriter ; 31 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base.DeploymentLogger; 32 33 41 public class DefaultDeploymentLogger 42 implements DeploymentLogger 43 { 44 private PrintWriter print; 50 private File file; 51 60 public DefaultDeploymentLogger(String filepath) 61 throws Exception 62 { 63 File file=new File (filepath); 64 file.createNewFile(); 65 print= new PrintWriter (new FileWriter (file)); 66 } 67 70 public DefaultDeploymentLogger() 71 { 72 } 73 private void 79 setTemporaryLogFile() 80 { 81 try{ 82 file=File.createTempFile("DeploymentLog"+System.currentTimeMillis(),".log"); 83 file.createNewFile(); 84 print= new PrintWriter (new FileWriter (file)); 85 } 86 catch(Exception e){ 87 e.printStackTrace(); 88 } 89 90 } 91 public void 97 setLogFile(String filepath) 98 throws Exception 99 { 100 file=new File (filepath); 101 file.createNewFile(); 102 print= new PrintWriter (new FileWriter (file)); 103 } 104 105 106 public void 107 removeLogFile() 108 { 109 try{ 110 print.close(); 111 file.delete(); 112 } 113 catch(Exception e) 114 { 115 System.err.println("A problem occured during log file removing"); 116 } 117 } 118 122 public void 123 log(String ch) 124 { 125 if(print==null) 126 setTemporaryLogFile(); 127 else 128 { 129 print.println(ch); 130 print.flush(); 131 } 132 } 133 } 134 | Popular Tags |