2013-04-12 19:32:25 -07:00
|
|
|
package magic.model;
|
|
|
|
|
2020-01-15 12:02:42 -08:00
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.PrintWriter;
|
2017-06-19 01:59:08 -07:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2020-01-15 12:02:42 -08:00
|
|
|
|
2014-08-17 01:58:35 -07:00
|
|
|
import magic.utility.MagicFileSystem;
|
|
|
|
import magic.utility.MagicFileSystem.DataPath;
|
2013-04-12 19:32:25 -07:00
|
|
|
|
|
|
|
public class MagicGameLog {
|
2014-08-17 02:03:24 -07:00
|
|
|
private MagicGameLog() {}
|
2015-11-07 01:34:22 -08:00
|
|
|
|
|
|
|
public static final String LOG_FILE = "game.log";
|
2015-12-31 02:54:52 -08:00
|
|
|
|
2014-04-01 22:52:00 -07:00
|
|
|
private static final String gameLog = (System.getProperty("game.log") != null) ?
|
2015-12-31 02:54:52 -08:00
|
|
|
System.getProperty("game.log") :
|
2015-11-07 01:34:22 -08:00
|
|
|
MagicFileSystem.getDataPath(DataPath.LOGS).resolve(LOG_FILE).toString();
|
2014-04-01 22:52:00 -07:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
private static PrintWriter writer;
|
2013-06-23 18:33:35 -07:00
|
|
|
|
2014-09-03 10:15:41 -07:00
|
|
|
public static String getLogFileName(){
|
2014-09-03 22:37:26 -07:00
|
|
|
return gameLog;
|
2014-09-03 10:15:41 -07:00
|
|
|
}
|
2015-12-31 02:54:52 -08:00
|
|
|
|
2013-04-12 19:32:25 -07:00
|
|
|
public static void initialize() {
|
|
|
|
try {
|
2017-06-16 20:58:13 -07:00
|
|
|
writer = new PrintWriter(gameLog, UTF_8.name());
|
2013-04-12 19:32:25 -07:00
|
|
|
final StringBuilder sb = new StringBuilder();
|
2017-06-19 01:59:08 -07:00
|
|
|
MagicLogger.setLogHeader(sb, "MAGARENA GAME LOG");
|
2013-04-12 19:32:25 -07:00
|
|
|
sb.append("\n\n");
|
|
|
|
log(sb.toString());
|
2017-06-16 20:58:13 -07:00
|
|
|
} catch (FileNotFoundException|UnsupportedEncodingException e) {
|
2013-04-12 19:32:25 -07:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|