SubServers-2/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Log/FileLogger.java

37 lines
1.0 KiB
Java
Raw Normal View History

package net.ME1312.SubServers.Host.Library.Log;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* Log File Writer Class
*/
public class FileLogger extends OutputStream {
private static FileWriter file = null;
private PrintStream origin;
protected FileLogger(PrintStream origin, File dir) throws IOException {
this.origin = origin;
if (file == null) {
new File(dir, "Logs").mkdirs();
file = new FileWriter(new File(dir, "Logs" + File.separator + "SubServers #" + (new File(dir, "Logs").list().length + 1) + " (" + new SimpleDateFormat("MM-dd-yyyy").format(Calendar.getInstance().getTime()) + ").log"));
}
}
@Override
public void write(int b) throws IOException {
origin.write((char)b);
file.write((char) b);
file.flush();
}
public static void end() throws IOException {
file.close();
}
}