2013-04-12 19:32:25 -07:00
|
|
|
package magic.model;
|
|
|
|
|
|
|
|
import magic.MagicMain;
|
2014-04-18 06:58:52 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
public class MagicGameLog {
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-04-01 22:52:00 -07:00
|
|
|
private static final String gameLog = (System.getProperty("game.log") != null) ?
|
|
|
|
System.getProperty("game.log") :
|
|
|
|
MagicMain.getLogsPath() + File.separator + "game.log";
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
private static PrintWriter writer;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
private MagicGameLog() {}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public static void initialize() {
|
|
|
|
try {
|
|
|
|
writer = new PrintWriter(gameLog);
|
|
|
|
final StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append("MAGARENA GAME LOG");
|
|
|
|
sb.append('\n');
|
|
|
|
sb.append("CREATED ON " + (new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")).format(new Date()));
|
|
|
|
sb.append('\n');
|
2013-12-01 10:01:06 -08:00
|
|
|
sb.append("MAGARENA VERSION " + MagicMain.VERSION);
|
2013-04-12 19:32:25 -07:00
|
|
|
sb.append(", JRE " + System.getProperty("java.version"));
|
|
|
|
sb.append(", OS " + System.getProperty("os.name"));
|
|
|
|
sb.append("_" + System.getProperty("os.version"));
|
|
|
|
sb.append(" " + System.getProperty("os.arch"));
|
|
|
|
sb.append("\n\n");
|
|
|
|
log(sb.toString());
|
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
System.err.println("Unable to create game log");
|
|
|
|
}
|
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public static void log(final String message) {
|
|
|
|
if (writer != null) {
|
|
|
|
writer.println(message);
|
|
|
|
writer.flush();
|
2013-06-23 18:33:35 -07:00
|
|
|
}
|
2013-04-12 19:32:25 -07:00
|
|
|
}
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public static void close() {
|
|
|
|
if (writer != null) {
|
|
|
|
writer.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|