annotate flys-client/src/main/java/de/intevation/flys/client/server/BaseServlet.java @ 1368:ec0c81f2c7a4

Replaced stdout and stderr logging with log4j loggers in server classes. flys-client/trunk@3071 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 Oct 2011 12:41:16 +0000
parents d0eb2202ffbe
children 2ba44c1b2bab
rev   line source
1366
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import javax.servlet.ServletException;
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import javax.servlet.http.HttpServlet;
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import org.apache.log4j.Logger;
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import org.apache.log4j.PropertyConfigurator;
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 public class BaseServlet extends HttpServlet {
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 private static Logger logger = Logger.getLogger(BaseServlet.class);
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 @Override
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 public void init()
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 throws ServletException
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 {
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 System.out.println("BaseServlet.init");
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
1368
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
21 initLogging();
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
22 initConfigParameters();
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
23 }
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
24
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
25
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
26 protected void initLogging() {
1366
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 String log4jProperties = getInitParameter("log4j-properties");
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 if (log4jProperties != null && log4jProperties.length() > 0) {
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 String file = getServletContext().getRealPath(log4jProperties);
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 PropertyConfigurator.configure(file);
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 logger.info("Log4J logging initialized.");
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 }
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 else {
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 System.out.println("Error while setting up Log4J configuration.");
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 }
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 System.out.println("BaseServlet.init finished");
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 }
1368
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
42
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
43
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
44 protected void initConfigParameters() {
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
45 String url = getInitParameter("server-url");
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
46 logger.debug("Found server url: " + url);
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
47
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
48 getServletContext().setAttribute("server-url", url);
ec0c81f2c7a4 Replaced stdout and stderr logging with log4j loggers in server classes.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1366
diff changeset
49 }
1366
d0eb2202ffbe Added a BaseServlet that is used to setup config things like log4j.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 }

http://dive4elements.wald.intevation.org