Skip to content

Instantly share code, notes, and snippets.

@pedromtavares
Created April 8, 2010 02:24
Show Gist options
  • Save pedromtavares/359707 to your computer and use it in GitHub Desktop.
Save pedromtavares/359707 to your computer and use it in GitHub Desktop.
import java.io.FileWriter;
import java.io.IOException;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
public class Logger implements HttpSessionListener{
public void sessionCreated(HttpSessionEvent e){
java.util.Date data = new java.util.Date();
FileWriter writer = null;
try {
writer = new FileWriter( "log.txt" );
writer.write( String.format( "Usuário logado em: %s%n", data ) );
writer.flush();
} catch (IOException e1) {
e1.printStackTrace();
} finally {
if ( writer != null ) {
try {
writer.close();
} catch ( IOException e1 ) {
e1.printStackTrace();
}
}
}
System.out.println("ativei");
}
public void sessionDestroyed(HttpSessionEvent e){
System.out.println("desativei");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment