java log function

javalog function source code….

usefull to log application/system activities.

/*
@Function Name: LogFunction
@purpose : to wite a log file
@author : Mohd Hafeez
@date : 21 Oct 2007 7:58 AM
@version 01

*/
import java.io.*;
//import java.io.FilOutputStream;
//import java.io.File;
import java.io.IOException;

public class LogFunction
{
//private ObjectOutputStream myFile;
private OutputStream myFile;

public void openFile()
{
try {
//myFile = new ObjectOutputStream( new FileOutputStream (“log.txt”) );
myFile = new FileOutputStream (“log.txt”,true);
} catch (IOException ioexception) {
System.err.println(“Error kat create File log.txt”);
}
}

public void writeLog( String myTxt )
{
try {
myFile.write(myTxt.getBytes ( ));
} catch ( IOException ioexception) {
System.err.println(“Error kat write Log”);
}
}

public void closeFile()
{
try {
if(myFile != null) myFile.close();
} catch(IOException ioexception) {
System.err.println(“Error close file”);
}
}
}

//file to test

import java.io.*;
//import java.io.FilOutputStream;
//import java.io.File;
import java.io.IOException;

public class tryLog {
public static void main( String args[] )
{
LogFunction app = new LogFunction();

app.openFile();
app.writeLog(“try-by-apit”);
app.closeFile();
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s