The Artima Developer Community
Sponsored Link

Legacy Design Forum
Finalization and Cleanup

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

answer for writing a log file in java

Posted by ashok on January 22, 2002 at 11:39 PM

/* Author : Ashok.Telukuntla
Program namne: LogFile.java */

package logfile;

import java.io.*;
import java.util.*;

public class LogFile {
private FileOutputStream log;
private static LogFile logfile;

private LogFile(String s, String s1, String s2, String s3, String s4) {
try{
log=new FileOutputStream(s,true);

PrintStream ps=new PrintStream(log);

ps.println("CLASS : "+s1);
ps.println("METHOD : "+s2);
ps.println("EXCEPTION : "+s3);
ps.println("DESCRIPTION : "+s4);
ps.println("TIME : "+(new Date().toString().substring(11,19)));
ps.println("-----------------------------------------------------------");
ps.println();

}catch(Exception e){
// LogFile.logErr("LogFile","logErr",e.toString(),e.getMessage()); //call in your programs like this
}
}

public static void logErr(String s1, String s2, String s3, String s4) {
try{
Date d=new Date();
String ss=d.toString();
String file=ss.substring(8,10)+ss.substring(4,7)+ss.substring(30,34);
System.out.println(file+"File");
logfile=new LogFile("errorask.log",s1,s2,s3,s4);


}catch(Exception e){
// LogFile.logErr("LogFile","logErr",e.toString(),e.getMessage());
}
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us