diff --git a/WebContent/WEB-INF/log4j.properties b/WebContent/WEB-INF/log4j.properties new file mode 100644 index 0000000..33f8b75 --- /dev/null +++ b/WebContent/WEB-INF/log4j.properties @@ -0,0 +1,5 @@ +log4j.rootLogger=INFO, stdout + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n diff --git a/WebContent/admin.jsp b/WebContent/admin.jsp index 70afe29..058850a 100644 --- a/WebContent/admin.jsp +++ b/WebContent/admin.jsp @@ -31,6 +31,7 @@ Administration tools. <%@ page import="com.google.inject.Key" %> <%@ page import="com.google.inject.TypeLiteral" %> <%@ page import="net.socialgamer.cah.RequestWrapper" %> +<%@ page import="net.socialgamer.cah.StartupUtils" %> <%@ page import="net.socialgamer.cah.CahModule.BanList" %> <%@ page import="net.socialgamer.cah.Constants.DisconnectReason" %> <%@ page import="net.socialgamer.cah.Constants.LongPollEvent" %> @@ -116,6 +117,11 @@ if (unbanParam != null) { return; } +String reloadLog4j = request.getParameter("reloadLog4j"); +if ("true".equals(reloadLog4j)) { + StartupUtils.reconfigureLogging(this.getServletContext()); +} + %> @@ -218,6 +224,7 @@ User list: <% +// TODO remove this "verbose logging" crap now that log4j is working. Boolean verboseDebugObj = (Boolean) servletContext.getAttribute(StartupUtils.VERBOSE_DEBUG); boolean verboseDebug = verboseDebugObj != null ? verboseDebugObj.booleanValue() : false; %> @@ -225,6 +232,9 @@ boolean verboseDebug = verboseDebugObj != null ? verboseDebugObj.booleanValue() Verbose logging is currently <%= verboseDebug ? "ON" : "OFF" %>. Turn on. Turn off.

+

+ Reload log4j.properties. +

diff --git a/src/net/socialgamer/cah/StartupUtils.java b/src/net/socialgamer/cah/StartupUtils.java index 3e9da1b..b5b1f24 100644 --- a/src/net/socialgamer/cah/StartupUtils.java +++ b/src/net/socialgamer/cah/StartupUtils.java @@ -29,6 +29,8 @@ import java.util.Timer; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; +import org.apache.log4j.PropertyConfigurator; + import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.servlet.GuiceServletContextListener; @@ -102,6 +104,13 @@ public class StartupUtils extends GuiceServletContextListener { context.setAttribute(PING_TIMER_NAME, timer); context.setAttribute(INJECTOR, injector); context.setAttribute(DATE_NAME, serverStarted); + + reconfigureLogging(contextEvent.getServletContext()); + } + + public static void reconfigureLogging(final ServletContext context) { + PropertyConfigurator.configure(context.getRealPath( + "/WEB-INF/log4j.properties")); } @Override diff --git a/src/net/socialgamer/cah/handlers/Handler.java b/src/net/socialgamer/cah/handlers/Handler.java index b93dee0..c4cf7b5 100644 --- a/src/net/socialgamer/cah/handlers/Handler.java +++ b/src/net/socialgamer/cah/handlers/Handler.java @@ -25,7 +25,6 @@ package net.socialgamer.cah.handlers; import java.util.HashMap; import java.util.Map; -import java.util.logging.Logger; import javax.servlet.http.HttpSession; @@ -34,6 +33,8 @@ 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 diff --git a/src/net/socialgamer/cah/handlers/KickHandler.java b/src/net/socialgamer/cah/handlers/KickHandler.java index d672f12..35ff7dc 100644 --- a/src/net/socialgamer/cah/handlers/KickHandler.java +++ b/src/net/socialgamer/cah/handlers/KickHandler.java @@ -58,7 +58,7 @@ public class KickHandler extends Handler { kickUser.enqueueMessage(qm); connectedUsers.removeUser(kickUser, DisconnectReason.KICKED); - logger.info(String.format("Kicking %s by request of %s", kickUser.getNickname(), + logger.warn(String.format("Kicking %s by request of %s", kickUser.getNickname(), user.getNickname())); return new HashMap();