mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-06-28 07:34:58 +02:00
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.
40 lines
1.1 KiB
Java
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;
|
|
}
|
|
}
|