1 15 16 18 36 package ixenon.free.util; 37 38 import java.io.File ; 39 import java.io.IOException ; 40 import java.io.OutputStream ; 41 import java.io.FileOutputStream ; 42 import java.io.PrintWriter ; 43 import java.util.Date ; 44 import java.text.*; 46 49 public class LogFile { 50 51 protected File logfile = null; 52 protected PrintWriter pwriter = null; 53 54 protected SimpleDateFormat stamper = new SimpleDateFormat( "ddMMMyyyy--HH:mm:ss -- " ); 58 protected String newline = System.getProperty( "line.separator" ); 59 60 64 public LogFile() 65 throws IOException 66 { 67 this.logfile = new File ("<STDOUT>"); 68 pwriter = new PrintWriter ( System.out ); 69 } 70 71 75 public LogFile( String logfile ) throws IOException 76 { 77 this( new File (logfile)); 78 } 79 80 84 public LogFile( File logfile ) 85 throws IOException 86 { 87 this.logfile = logfile; 88 pwriter = new PrintWriter ( 89 new FileOutputStream ( logfile.getAbsolutePath(), true )); 90 } 91 92 93 public File getFile() 94 { 95 return logfile; 96 } 97 98 99 public String getFilename() 100 { 101 return logfile.getAbsolutePath(); 102 } 103 104 108 public synchronized void dtprint( String message ) 109 { 110 Date now = new Date (); 111 String dtstr = stamper.format( now ); 112 pwriter.print( dtstr + message ); 113 pwriter.flush(); 114 } 115 116 120 public void dtprintln( String message ) 121 { 122 dtprint( message + newline ); 123 } 124 125 128 public void dtprintln() 129 { 130 dtprint( newline ); 131 } 132 133 137 public synchronized void print( String message ) 138 { 139 pwriter.print( message ); 140 pwriter.flush(); 141 } 142 143 147 public synchronized void println( String message ) 148 { 149 pwriter.print( message + newline ); 150 pwriter.flush(); 151 } 152 153 157 public synchronized void println() 158 { 159 pwriter.println(); 160 pwriter.flush(); 161 } 162 } 163 164 | Popular Tags |