1 package installer; 2 import java.io.PrintStream; 3 import java.io.FileOutputStream; 4 5 import java.util.Date; 6 import java.text.DateFormat; 7 import java.text.SimpleDateFormat; 8 9 10 //import java.io.PrintWriter; 11 public class LogStream extends PrintStream 12 { 13 static final private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z: "); 14 15 private String getTimeStamp() 16 { 17 String timeStamp = formatter.format( new Date() ); 18 return timeStamp; 19 } 20 public LogStream( String logFileName ) throws java.io.FileNotFoundException 21 { 22 super( new FileOutputStream( logFileName ) ); 23 } 24 public void println(String x) 25 { 26 super.println( getTimeStamp() + x ); 27 } 28 public static void main(String[] args) 29 { 30 if ( args.length > 0 ) 31 { 32 try 33 { 34 LogStream log = new LogStream( args[0] ); 35 System.setErr(log); 36 System.setOut(log); 37 System.out.println("Test from logger from out"); 38 System.err.println("Test from logger from err"); 39 System.out.println("finised test from out"); 40 System.err.println("finised test from err"); 41 } 42 catch( java.io.FileNotFoundException fe ) 43 { 44 System.err.println("Error creating logStream: " + fe ); 45 fe.printStackTrace(); 46 } 47 } 48 else 49 { 50 System.err.println("specify log file java LogStream [logfile]"); 51 System.exit(1); 52 } 53 } 54 } 55