1 26 27 package net.sourceforge.groboutils.codecoverage.v2.logger; 28 29 import java.io.File ; 30 import java.io.FileWriter ; 31 import java.io.Writer ; 32 import java.io.IOException ; 33 34 import java.util.Properties ; 35 36 37 53 public class FileSingleSourceLoggerFactory extends AbstractSingleSourceLoggerFactory 54 { 55 public static final String DIRECTORY_PROPERTY = "dir"; 56 public static final String FILENAME_PROPERTY = "file"; 57 private static final String DEFAULT_FILENAME_PREFIX = "single."; 58 private static final String FILENAME_SUFFIX = ".log"; 59 60 private File outfile; 61 62 66 protected Writer setupSource() 67 { 68 setReloadSourceAfterError( false ); 69 70 try 71 { 72 return new FileWriter ( this.outfile ); 74 } 75 catch (IOException e) 76 { 77 e.printStackTrace(); 78 return null; 79 } 80 } 81 82 83 88 protected void setupProps( String prefix, Properties props ) 89 { 90 super.setupProps( prefix, props ); 91 92 String pseudoRandom = Long.toString( 95 System.currentTimeMillis() ) + Long.toString( 96 Math.round( Math.random() * 1000.0 ) ) + 97 FILENAME_SUFFIX; 98 99 String filename = props.getProperty( prefix + FILENAME_PROPERTY ); 103 if (filename != null) 104 { 105 this.outfile = new File ( filename + pseudoRandom ); 106 } 107 else 108 { 109 String dir = props.getProperty( prefix + DIRECTORY_PROPERTY ); 110 if (dir != null) 111 { 112 this.outfile = new File ( dir, 113 DEFAULT_FILENAME_PREFIX + pseudoRandom ); 114 } 115 } 116 117 if (this.outfile == null) 118 { 119 this.outfile = new File ( DEFAULT_FILENAME_PREFIX + pseudoRandom ); 120 } 121 122 File parent = this.outfile.getParentFile(); 123 if (!parent.exists()) 124 { 125 parent.mkdirs(); 126 } 127 } 128 } 129 130 | Popular Tags |