SubServers-2/SubServers.Host/src/net/ME1312/SubServers/Host/Library/Log/FileLogger.java
ME1312 7821c1f88e SubServers.Host Alpha 2
This update to SubServers.Host adds the core functions to the program.
It can now be used to host and create servers on other machines. API
while available is quite limited right now. This is also a very early
build, so it's probably not so stable just yet fyi.
2017-04-01 01:37:48 -04:00

40 lines
1.1 KiB
Java

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 final 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);
if (file != null) {
file.write((char) b);
file.flush();
}
}
public static void end() throws IOException {
if (file != null) file.close();
file = null;
}
}