01 import org.apache.log4j.Logger;
02
03 import javax.servlet.*;
04 import javax.servlet.http.*;
05 import java.io.PrintWriter;
06
07 public class LoggerWithConfig extends HttpServlet {
08
09 private Logger log = null;
10
11 public void init(){
12 /* root logger získa potrebné informácie z
13 WEB-INF/classes/log4j.properties */
14 log = Logger.getRootLogger();
15 log.info("LoggerWithConfig started ...");
16 }
17
18 public void doGet(HttpServletRequest request,HttpServletResponse response)
19 throws ServletException, java.io.IOException {
20
21 log.debug("Posielam DEBUG message ...");
22 log.info("Posielam INFO message ...");
23
24 response.setContentType("text/html");
25 PrintWriter out = response.getWriter();
26 out.println("<html><head></head><body>");
27 out.println("<h2>Logger with config file!</h2>");
28 out.println("Logger name is: " + log.getName()+"<br>");
29 out.println("</body></html>");
30 }
31 }
|