01 package mypackage.mylogger;
02
03 import org.apache.log4j.Logger;
04 import javax.servlet.*;
05 import javax.servlet.http.*;
06 import java.io.*;
07
08 public class LoggerWithConfigNew extends HttpServlet {
09
10 private Logger log = null;
11
12 public void init(){
13 log = Logger.getLogger(LoggerWithConfigNew.class);
14 log.info("LoggerWithConfigNew started.");
15 }
16
17 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
18
19 //správa na úrovni DEBUG
20 log.debug("Posielam DEBUG message.");
21
22 //správa na úrovni INFO
23 log.info("Posielam INFO message.");
24
25 //zobrazíme aj HTML
26 response.setContentType("text/html");
27 PrintWriter out = response.getWriter();
28 out.println("<html><head><title>Servlet logging</title></head><body>");
29
30 out.println("<h2>Logger with configuration in log4j.properties file</h2>");
31
32 out.println("Your logger name is: "+log.getName()+"<br>");
33
34 out.println("Your logger parent is: "+ log.getParent().getName()+"<br>");
35
36 out.println("</body></html>");
37 }
38 }
|