1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| package com.datalion.zsamurai.util;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class Log
{
private static Log instance = null;
private String path;
private File file;
private FileWriter writer;
private Log(String uri) throws IOException
{
this.path = "/var/log/";
String[] name = new File (".").getCanonicalPath().split("/");
this.path+=name[name.length-1];
this.path+="/";
if(uri==null)
{
this.path += Date.getDate('-')+".log";
}
else
{
this.path+=uri+".log";
}
System.out.println(this.path);
this.file=new File(this.path);
this.writer= new FileWriter(this.file,this.file.exists());
}
public static Log getInstance(String uri) throws IOException
{
if(Log.instance == null)
{
Log.instance = new Log(uri);
}
return Log.instance;
}
public static void write(String uri, String str) throws IOException
{
Log.getInstance(uri).writer.write(str+"\n");
}
public static void close(String uri) throws IOException
{
Log.getInstance(uri).writer.flush();
}
} |