Improve logging. Stop using toString() on Player/User outside of logging.
This commit is contained in:
parent
0264de8035
commit
a0e9c1d974
|
@ -508,7 +508,7 @@ public class Game {
|
|||
if (null == host) {
|
||||
return null;
|
||||
}
|
||||
info.put(GameInfo.HOST, host.toString());
|
||||
info.put(GameInfo.HOST, host.getUser().getNickname());
|
||||
info.put(GameInfo.STATE, state.toString());
|
||||
final List<Integer> cardSetIdsCopy;
|
||||
synchronized (this.cardSetIds) {
|
||||
|
@ -528,14 +528,14 @@ public class Game {
|
|||
final Player[] playersCopy = players.toArray(new Player[players.size()]);
|
||||
final List<String> playerNames = new ArrayList<String>(playersCopy.length);
|
||||
for (final Player player : playersCopy) {
|
||||
playerNames.add(player.toString());
|
||||
playerNames.add(player.getUser().getNickname());
|
||||
}
|
||||
info.put(GameInfo.PLAYERS, playerNames);
|
||||
|
||||
final User[] spectatorsCopy = spectators.toArray(new User[spectators.size()]);
|
||||
final List<String> spectatorNames = new ArrayList<String>(spectatorsCopy.length);
|
||||
for (final User spectator : spectatorsCopy) {
|
||||
spectatorNames.add(spectator.toString());
|
||||
spectatorNames.add(spectator.getNickname());
|
||||
}
|
||||
info.put(GameInfo.SPECTATORS, spectatorNames);
|
||||
|
||||
|
@ -557,6 +557,12 @@ public class Game {
|
|||
return info;
|
||||
}
|
||||
|
||||
public final List<Player> getPlayers() {
|
||||
final List<Player> copy = new ArrayList<Player>(players.size());
|
||||
copy.addAll(players);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get player information for a single player.
|
||||
*
|
||||
|
@ -661,7 +667,9 @@ public class Game {
|
|||
started = false;
|
||||
}
|
||||
if (started) {
|
||||
logger.info(String.format("Starting game %d.", id));
|
||||
logger.info(String.format("Starting game %d with card sets %s, %d blanks, %d max players, " +
|
||||
"%d max spectators, %d score limit, players %s.",
|
||||
id, cardSetIds, blanksInDeck, playerLimit, spectatorLimit, scoreGoal, players));
|
||||
// do this stuff outside the players lock; they will lock players again later for much less
|
||||
// time, and not at the same time as trying to lock users, which has caused deadlocks
|
||||
synchronized (cardSetIds) {
|
||||
|
@ -885,8 +893,7 @@ public class Game {
|
|||
for (final Player player : roundPlayers) {
|
||||
final List<WhiteCard> cards = playedCards.getCards(player);
|
||||
if (cards == null || cards.size() < blackCard.getPick()) {
|
||||
logger.info(String.format("Skipping idle player %s in game %d.",
|
||||
player.getUser().toString(), id));
|
||||
logger.info(String.format("Skipping idle player %s in game %d.", player, id));
|
||||
player.skipped();
|
||||
|
||||
final HashMap<ReturnableData, Object> data = getEventMap();
|
||||
|
|
|
@ -116,6 +116,6 @@ public class Player {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return user.toString();
|
||||
return String.format("%s (%dp, %ds)", user.toString(), score, skipCount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,10 +21,13 @@ import net.socialgamer.cah.data.QueuedMessage;
|
|||
import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
||||
import net.socialgamer.cah.data.User;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
||||
public class BanHandler extends Handler {
|
||||
protected final Logger logger = Logger.getLogger(BanHandler.class);
|
||||
|
||||
public static final String OP = AjaxOperation.BAN.toString();
|
||||
|
||||
|
|
|
@ -33,8 +33,6 @@ import net.socialgamer.cah.Constants.ErrorCode;
|
|||
import net.socialgamer.cah.Constants.ReturnableData;
|
||||
import net.socialgamer.cah.RequestWrapper;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Implementations of this interface MUST also have a public static final String OP. There will be
|
||||
|
@ -43,7 +41,6 @@ import org.apache.log4j.Logger;
|
|||
* @author Andy Janata (ajanata@socialgamer.net)
|
||||
*/
|
||||
public abstract class Handler {
|
||||
protected final Logger logger = Logger.getLogger("net.socialgamer.cah.handlers.Handler");
|
||||
|
||||
/**
|
||||
* Handle a request.
|
||||
|
|
|
@ -19,10 +19,13 @@ import net.socialgamer.cah.data.QueuedMessage;
|
|||
import net.socialgamer.cah.data.QueuedMessage.MessageType;
|
||||
import net.socialgamer.cah.data.User;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
||||
public class KickHandler extends Handler {
|
||||
protected final Logger logger = Logger.getLogger(KickHandler.class);
|
||||
|
||||
public static final String OP = AjaxOperation.KICK.toString();
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ import net.socialgamer.cah.data.Game;
|
|||
import net.socialgamer.cah.data.GameManager;
|
||||
import net.socialgamer.cah.data.User;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
|
||||
|
@ -45,6 +47,8 @@ import com.google.inject.Inject;
|
|||
*/
|
||||
public class StopGameHandler extends GameWithPlayerHandler {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(GameWithPlayerHandler.class);
|
||||
|
||||
public static final String OP = AjaxOperation.STOP_GAME.toString();
|
||||
|
||||
@Inject
|
||||
|
@ -62,6 +66,8 @@ public class StopGameHandler extends GameWithPlayerHandler {
|
|||
} else if (game.getState() == GameState.LOBBY) {
|
||||
return error(ErrorCode.ALREADY_STOPPED);
|
||||
} else {
|
||||
logger.info(String.format("Game %d stopped by host %s. Players: %s", game.getId(), user,
|
||||
game.getPlayers()));
|
||||
game.resetState(false);
|
||||
return data;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue