mirror of
https://github.com/ME1312/SubServers-2.git
synced 2024-09-26 04:23:09 +02:00
37 lines
1.0 KiB
Java
37 lines
1.0 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 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();
|
||
|
}
|
||
|
}
|