Updated log4j to log4j2

This commit is contained in:
devgianlu 2021-12-11 10:29:31 +01:00
parent 221a132b84
commit ca781a807b
22 changed files with 69 additions and 47 deletions

View File

@ -322,9 +322,9 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j</artifactId> <artifactId>log4j-core</artifactId>
<version>1.2.17</version> <version>2.15.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>

View File

@ -35,7 +35,8 @@ import javax.servlet.ServletContext;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.inject.*; import com.google.inject.*;
import net.socialgamer.cah.data.GameOptions; import net.socialgamer.cah.data.GameOptions;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session; import org.hibernate.Session;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -56,7 +57,7 @@ import net.socialgamer.cah.metrics.UniqueIds;
*/ */
public class CahModule extends AbstractModule { public class CahModule extends AbstractModule {
private static final Logger LOG = Logger.getLogger(CahModule.class); private static final Logger LOG = LogManager.getLogger(CahModule.class);
private final Properties properties = new Properties(); private final Properties properties = new Properties();

View File

@ -25,6 +25,7 @@ package net.socialgamer.cah;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.net.URI;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -40,8 +41,8 @@ import net.socialgamer.cah.metrics.Metrics;
import net.socialgamer.cah.task.BroadcastGameListUpdateTask; import net.socialgamer.cah.task.BroadcastGameListUpdateTask;
import net.socialgamer.cah.task.UserPingTask; import net.socialgamer.cah.task.UserPingTask;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.PropertyConfigurator; import org.apache.logging.log4j.Logger;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -58,7 +59,7 @@ import com.google.inject.servlet.GuiceServletContextListener;
*/ */
public class StartupUtils extends GuiceServletContextListener { public class StartupUtils extends GuiceServletContextListener {
private static final Logger LOG = Logger.getLogger(StartupUtils.class); private static final Logger LOG = LogManager.getLogger(StartupUtils.class);
/** /**
* Context attribute key name for the Guice injector. * Context attribute key name for the Guice injector.
@ -167,7 +168,8 @@ public class StartupUtils extends GuiceServletContextListener {
public static void reconfigureLogging(final ServletContext context) { public static void reconfigureLogging(final ServletContext context) {
LOG.info("Reloading log4j.properties"); LOG.info("Reloading log4j.properties");
PropertyConfigurator.configure(context.getRealPath("/WEB-INF/log4j.properties")); URI log4jProps = URI.create(context.getRealPath("/WEB-INF/log4j.properties"));
((org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false)).setConfigLocation(log4jProps);
} }
protected Injector getInjector(final ServletContext context) { protected Injector getInjector(final ServletContext context) {

View File

@ -33,7 +33,8 @@ import net.socialgamer.cah.CahModule.CustomDecksAllowedUrls;
import net.socialgamer.cah.CahModule.CustomDecksEnabled; import net.socialgamer.cah.CahModule.CustomDecksEnabled;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
@ -52,7 +53,7 @@ import java.util.regex.Pattern;
public class CustomCardsService { public class CustomCardsService {
private static final Logger LOG = Logger.getLogger(CustomCardsService.class); private static final Logger LOG = LogManager.getLogger(CustomCardsService.class);
private static final int GET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(3); private static final int GET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(3);

View File

@ -37,7 +37,8 @@ import java.util.stream.Collectors;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -65,7 +66,7 @@ import net.socialgamer.cah.metrics.Metrics;
@Singleton @Singleton
public class ConnectedUsers { public class ConnectedUsers {
private static final Logger logger = Logger.getLogger(ConnectedUsers.class); private static final Logger logger = LogManager.getLogger(ConnectedUsers.class);
/** /**
* Duration of a ping timeout, in nanoseconds. * Duration of a ping timeout, in nanoseconds.

View File

@ -34,7 +34,8 @@ import net.socialgamer.cah.data.QueuedMessage.MessageType;
import net.socialgamer.cah.metrics.Metrics; import net.socialgamer.cah.metrics.Metrics;
import net.socialgamer.cah.task.SafeTimerTask; import net.socialgamer.cah.task.SafeTimerTask;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session; import org.hibernate.Session;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -76,7 +77,7 @@ public class Game {
* We need 20 * maxPlayers cards. This allows black cards up to "draw 9" to work correctly. * We need 20 * maxPlayers cards. This allows black cards up to "draw 9" to work correctly.
*/ */
public final static int MINIMUM_WHITE_CARDS_PER_PLAYER = 20; public final static int MINIMUM_WHITE_CARDS_PER_PLAYER = 20;
private static final Logger logger = Logger.getLogger(Game.class); private static final Logger logger = LogManager.getLogger(Game.class);
/** /**
* Time, in milliseconds, to delay before starting a new round. * Time, in milliseconds, to delay before starting a new round.
*/ */

View File

@ -31,7 +31,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.inject.BindingAnnotation; import com.google.inject.BindingAnnotation;
@ -54,7 +55,7 @@ import net.socialgamer.cah.task.BroadcastGameListUpdateTask;
@Singleton @Singleton
@GameId @GameId
public class GameManager implements Provider<Integer> { public class GameManager implements Provider<Integer> {
private static final Logger logger = Logger.getLogger(GameManager.class); private static final Logger logger = LogManager.getLogger(GameManager.class);
private final Provider<Integer> maxGamesProvider; private final Provider<Integer> maxGamesProvider;
private final Map<Integer, Game> games = new TreeMap<Integer, Game>(); private final Map<Integer, Game> games = new TreeMap<Integer, Game>();

View File

@ -30,7 +30,8 @@ import java.util.concurrent.PriorityBlockingQueue;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted; import com.google.inject.assistedinject.Assisted;
@ -48,7 +49,7 @@ import net.socialgamer.cah.Constants.Sigil;
*/ */
public class User { public class User {
private static final Logger LOG = Logger.getLogger(User.class); private static final Logger LOG = LogManager.getLogger(User.class);
private final String nickname; private final String nickname;

View File

@ -44,13 +44,14 @@ import net.socialgamer.cah.data.QueuedMessage;
import net.socialgamer.cah.data.QueuedMessage.MessageType; import net.socialgamer.cah.data.QueuedMessage.MessageType;
import net.socialgamer.cah.data.User; import net.socialgamer.cah.data.User;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
public class BanHandler extends Handler { public class BanHandler extends Handler {
protected final Logger logger = Logger.getLogger(BanHandler.class); protected final Logger logger = LogManager.getLogger(BanHandler.class);
public static final String OP = AjaxOperation.BAN.toString(); public static final String OP = AjaxOperation.BAN.toString();

View File

@ -28,7 +28,8 @@ import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -54,7 +55,7 @@ import net.socialgamer.cah.util.ChatFilter;
*/ */
public class ChatHandler extends Handler { public class ChatHandler extends Handler {
private static final Logger LOG = Logger.getLogger(ChatHandler.class); private static final Logger LOG = LogManager.getLogger(ChatHandler.class);
public static final String OP = AjaxOperation.CHAT.toString(); public static final String OP = AjaxOperation.CHAT.toString();
private final ChatFilter chatFilter; private final ChatFilter chatFilter;

View File

@ -32,7 +32,8 @@ import java.util.Set;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
@ -67,7 +68,7 @@ import net.socialgamer.cah.db.PyxCardSet;
*/ */
public class FirstLoadHandler extends Handler { public class FirstLoadHandler extends Handler {
private static final Logger LOG = Logger.getLogger(FirstLoadHandler.class); private static final Logger LOG = LogManager.getLogger(FirstLoadHandler.class);
public static final String OP = AjaxOperation.FIRST_LOAD.toString(); public static final String OP = AjaxOperation.FIRST_LOAD.toString();
private final Set<String> banList; private final Set<String> banList;

View File

@ -28,7 +28,8 @@ import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -55,7 +56,7 @@ import net.socialgamer.cah.util.ChatFilter;
*/ */
public class GameChatHandler extends GameWithPlayerHandler { public class GameChatHandler extends GameWithPlayerHandler {
private static final Logger LOG = Logger.getLogger(GameChatHandler.class); private static final Logger LOG = LogManager.getLogger(GameChatHandler.class);
public static final String OP = AjaxOperation.GAME_CHAT.toString(); public static final String OP = AjaxOperation.GAME_CHAT.toString();
private final ChatFilter chatFilter; private final ChatFilter chatFilter;

View File

@ -19,13 +19,14 @@ import net.socialgamer.cah.data.QueuedMessage;
import net.socialgamer.cah.data.QueuedMessage.MessageType; import net.socialgamer.cah.data.QueuedMessage.MessageType;
import net.socialgamer.cah.data.User; import net.socialgamer.cah.data.User;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
public class KickHandler extends Handler { public class KickHandler extends Handler {
protected final Logger logger = Logger.getLogger(KickHandler.class); protected final Logger logger = LogManager.getLogger(KickHandler.class);
public static final String OP = AjaxOperation.KICK.toString(); public static final String OP = AjaxOperation.KICK.toString();

View File

@ -33,7 +33,8 @@ import javax.servlet.http.HttpSession;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpHeaders; import org.apache.http.HttpHeaders;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -65,7 +66,7 @@ import net.socialgamer.cah.util.IdCodeMangler;
*/ */
public class RegisterHandler extends Handler { public class RegisterHandler extends Handler {
private static final Logger LOG = Logger.getLogger(RegisterHandler.class); private static final Logger LOG = LogManager.getLogger(RegisterHandler.class);
public static final String OP = AjaxOperation.REGISTER.toString(); public static final String OP = AjaxOperation.REGISTER.toString();
private static final Pattern VALID_NAME = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]{2,29}"); private static final Pattern VALID_NAME = Pattern.compile("[a-zA-Z_][a-zA-Z0-9_]{2,29}");

View File

@ -37,7 +37,8 @@ import net.socialgamer.cah.data.Game;
import net.socialgamer.cah.data.GameManager; import net.socialgamer.cah.data.GameManager;
import net.socialgamer.cah.data.User; import net.socialgamer.cah.data.User;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -47,7 +48,7 @@ import com.google.inject.Inject;
*/ */
public class StopGameHandler extends GameWithPlayerHandler { public class StopGameHandler extends GameWithPlayerHandler {
protected final Logger logger = Logger.getLogger(GameWithPlayerHandler.class); protected final Logger logger = LogManager.getLogger(GameWithPlayerHandler.class);
public static final String OP = AjaxOperation.STOP_GAME.toString(); public static final String OP = AjaxOperation.STOP_GAME.toString();

View File

@ -29,7 +29,8 @@ import java.net.InetAddress;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -48,7 +49,7 @@ import com.maxmind.geoip2.model.CityResponse;
@Singleton @Singleton
public class GeoIP { public class GeoIP {
private static final Logger LOG = Logger.getLogger(GeoIP.class); private static final Logger LOG = LogManager.getLogger(GeoIP.class);
private DatabaseReader reader; private DatabaseReader reader;
private boolean initialized = false; private boolean initialized = false;

View File

@ -47,7 +47,8 @@ import org.apache.kafka.common.PartitionInfo;
import org.apache.kafka.common.config.SaslConfigs; import org.apache.kafka.common.config.SaslConfigs;
import org.apache.kafka.common.config.SslConfigs; import org.apache.kafka.common.config.SslConfigs;
import org.apache.kafka.common.serialization.StringSerializer; import org.apache.kafka.common.serialization.StringSerializer;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONValue; import org.json.simple.JSONValue;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -73,7 +74,7 @@ public class KafkaMetrics implements Metrics {
// 0.1: initial version // 0.1: initial version
// 0.2: added cardDealt // 0.2: added cardDealt
private static final String metricsVersion = "0.2"; private static final String metricsVersion = "0.2";
private static final Logger LOG = Logger.getLogger(KafkaMetrics.class); private static final Logger LOG = LogManager.getLogger(KafkaMetrics.class);
private final ProducerCallback callback = new ProducerCallback(); private final ProducerCallback callback = new ProducerCallback();
private final String build; private final String build;

View File

@ -27,7 +27,8 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.maxmind.geoip2.model.CityResponse; import com.maxmind.geoip2.model.CityResponse;
@ -45,7 +46,7 @@ import net.socialgamer.cah.data.WhiteCard;
@Singleton @Singleton
public class NoOpMetrics implements Metrics { public class NoOpMetrics implements Metrics {
private static final Logger LOG = Logger.getLogger(NoOpMetrics.class); private static final Logger LOG = LogManager.getLogger(NoOpMetrics.class);
@Override @Override
public void shutdown() { public void shutdown() {

View File

@ -31,7 +31,8 @@ import java.util.concurrent.atomic.AtomicLong;
import net.socialgamer.cah.CahModule.ServerStarted; import net.socialgamer.cah.CahModule.ServerStarted;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Provider; import com.google.inject.Provider;
@ -51,7 +52,7 @@ import com.google.inject.Singleton;
@Singleton @Singleton
public class UniqueIds implements Provider<String> { public class UniqueIds implements Provider<String> {
private static final Logger LOG = Logger.getLogger(UniqueIds.class); private static final Logger LOG = LogManager.getLogger(UniqueIds.class);
private static final String hostname; private static final String hostname;

View File

@ -1,11 +1,12 @@
package net.socialgamer.cah.task; package net.socialgamer.cah.task;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public abstract class SafeTimerTask implements Runnable { public abstract class SafeTimerTask implements Runnable {
private static final Logger logger = Logger.getLogger(SafeTimerTask.class); private static final Logger logger = LogManager.getLogger(SafeTimerTask.class);
@Override @Override
public final void run() { public final void run() {

View File

@ -35,7 +35,8 @@ import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -51,7 +52,7 @@ import net.socialgamer.cah.data.User;
*/ */
@Singleton @Singleton
public class ChatFilter { public class ChatFilter {
private static final Logger LOG = Logger.getLogger(ChatFilter.class); private static final Logger LOG = LogManager.getLogger(ChatFilter.class);
private static final int DEFAULT_CHAT_FLOOD_MESSAGE_COUNT = 4; private static final int DEFAULT_CHAT_FLOOD_MESSAGE_COUNT = 4;
private static final int DEFAULT_CHAT_FLOOD_TIME_SECONDS = 30; private static final int DEFAULT_CHAT_FLOOD_TIME_SECONDS = 30;

View File

@ -28,7 +28,8 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Base64; import java.util.Base64;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -36,7 +37,7 @@ import net.socialgamer.cah.CahModule.IdCodeSalt;
public class IdCodeMangler { public class IdCodeMangler {
private static final Logger LOG = Logger.getLogger(IdCodeMangler.class); private static final Logger LOG = LogManager.getLogger(IdCodeMangler.class);
private final String salt; private final String salt;
private final Base64.Encoder encoder = Base64.getEncoder(); private final Base64.Encoder encoder = Base64.getEncoder();