New method logging with customized logging in ChessEngine
parent
e0d14e0811
commit
0d899a762a
|
|
@ -1,7 +1,11 @@
|
||||||
package de.hs_mannheim.informatik.chess.model;
|
package de.hs_mannheim.informatik.chess.model;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.ConsoleHandler;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.logging.SimpleFormatter;
|
||||||
|
|
||||||
import com.github.bhlangonijr.chesslib.Board;
|
import com.github.bhlangonijr.chesslib.Board;
|
||||||
import com.github.bhlangonijr.chesslib.Piece;
|
import com.github.bhlangonijr.chesslib.Piece;
|
||||||
|
|
@ -16,8 +20,8 @@ public class ChessEngine {
|
||||||
private int currentMoveIndex = 0;
|
private int currentMoveIndex = 0;
|
||||||
|
|
||||||
public ChessEngine() {
|
public ChessEngine() {
|
||||||
|
logging();
|
||||||
board = new Board();
|
board = new Board();
|
||||||
logger.info("Neues ChessEngine-Objekt erstellt.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean move(MoveDTO move) {
|
public boolean move(MoveDTO move) {
|
||||||
|
|
@ -166,4 +170,21 @@ public class ChessEngine {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void logging() {
|
||||||
|
|
||||||
|
// Eigener Handler nur für diese Klasse
|
||||||
|
ConsoleHandler handler = new ConsoleHandler();
|
||||||
|
handler.setLevel(Level.ALL);
|
||||||
|
handler.setFormatter(new SimpleFormatter() {
|
||||||
|
@Override
|
||||||
|
public synchronized String format(LogRecord lr) {
|
||||||
|
return String.format("[%s] %s%n%n", lr.getLevel().getLocalizedName(), lr.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
logger.setUseParentHandlers(false);
|
||||||
|
logger.addHandler(handler);
|
||||||
|
|
||||||
|
logger.info("ChessEngine wurde initialisiert.");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue