2 import java
.io
.PrintStream
;
3 import java
.io
.FileOutputStream
;
6 import java
.text
.DateFormat
;
7 import java
.text
.SimpleDateFormat
;
10 //import java.io.PrintWriter;
11 public class LogStream
extends PrintStream
13 static final private DateFormat formatter
= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z: ");
15 private String
getTimeStamp()
17 String timeStamp
= formatter
.format( new Date() );
20 public LogStream( String logFileName
) throws java
.io
.FileNotFoundException
22 super( new FileOutputStream( logFileName
) );
24 public void println(String x
)
26 super.println( getTimeStamp() + x
);
28 public static void main(String
[] args
)
30 if ( args
.length
> 0 )
34 LogStream log
= new LogStream( args
[0] );
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");
42 catch( java
.io
.FileNotFoundException fe
)
44 System
.err
.println("Error creating logStream: " + fe
);
50 System
.err
.println("specify log file java LogStream [logfile]");