|
@@ -0,0 +1,47 @@
|
|
|
|
|
+package id.co.hanoman.servlet;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+
|
|
|
|
|
+import javax.servlet.ServletConfig;
|
|
|
|
|
+import javax.servlet.ServletException;
|
|
|
|
|
+import javax.servlet.http.HttpServlet;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+
|
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
|
+import org.apache.log4j.PropertyConfigurator;
|
|
|
|
|
+
|
|
|
|
|
+public class Log4JInitServlet extends HttpServlet {
|
|
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
|
|
+ static Logger logger = Logger.getLogger(Log4JInitServlet.class.getName());
|
|
|
|
|
+
|
|
|
|
|
+ public Log4JInitServlet() {
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void init(ServletConfig sc) throws ServletException {
|
|
|
|
|
+ super.init(sc);
|
|
|
|
|
+ String sPath = getServletContext().getRealPath("/");
|
|
|
|
|
+ String sLogConfigFile = getInitParameter("log4j-init-file");
|
|
|
|
|
+
|
|
|
|
|
+ if (sLogConfigFile != null)
|
|
|
|
|
+ PropertyConfigurator.configure((new StringBuilder(String.valueOf(sPath))).append(sLogConfigFile).toString());
|
|
|
|
|
+ getServletContext().log((new StringBuilder("logging to: ")).append(sPath).append(sLogConfigFile).toString());
|
|
|
|
|
+
|
|
|
|
|
+ logger.info("Logger has been initialized...");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void destroy() {
|
|
|
|
|
+ super.destroy();
|
|
|
|
|
+ logger.info("Destroy");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected void doPost(HttpServletRequest req, HttpServletResponse res)
|
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
|
+ logger.info("doPost()");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ protected void doGet(HttpServletRequest req, HttpServletResponse res)
|
|
|
|
|
+ throws ServletException, IOException {
|
|
|
|
|
+ logger.info("doGet()");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|