Session logger : Session « Servlets « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Servlets » Session 




Session logger
  
//Log4j from Apache is required


import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import javax.servlet.*;
import javax.servlet.http.*;

public class SessionLogger implements HttpSessionListener {

  private Logger log;

  public SessionLogger() {

    /*
     * The loggers are typically initialized by a special initialization
     * listener or servlet. If this is not the case, then initialize the
     * logger here:
     
     * java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle(
     * "com.java2s.global");
     * PropertyConfigurator.configure(bundle.getString(
     * "log-configure-path"));
     */

    log = Logger.getLogger(SessionLogger.class);

  }

  public void sessionCreated(HttpSessionEvent se) {

    //log request of the INFO level
    log.info("HttpSession created: " + se.getSession().getId());

  }

  public void sessionDestroyed(HttpSessionEvent se) {

    //log request about session's that are invalidated
    log.info("HttpSession invalidated: " + se.getSession().getId());

  }

}
           
         
    
  














Related examples in the same category
1.Using Sessions in Servlet
2.Session Tracker
3.Servlet: simple session
4.Servlet: Session display
5.Servlet: session listener
6.Servlet : session filter
7.Servlet: session attribute listener
8.Servlet: Session bind listener
9.Servlet Session Example
10.Use cookie to save session data
11.Use hidden fields to save session data
12.Use URL rewrite to save session data
13.Session Events: implements HttpSessionBindingListener
14.Session Expiration Filter
15.Map adaptor for HttpSession objects
16.Fake session
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.