1 20 package org.apache.mina.filter; 21 22 import org.apache.mina.common.IdleStatus; 23 import org.apache.mina.common.IoFilterAdapter; 24 import org.apache.mina.common.IoSession; 25 import org.apache.mina.util.SessionLog; 26 import org.slf4j.Logger; 27 28 36 public class LoggingFilter extends IoFilterAdapter { 37 40 public static final String PREFIX = SessionLog.PREFIX; 41 42 45 public static final String LOGGER = SessionLog.LOGGER; 46 47 50 public LoggingFilter() { 51 } 52 53 public void sessionCreated(NextFilter nextFilter, IoSession session) { 54 SessionLog.info(session, "CREATED"); 55 nextFilter.sessionCreated(session); 56 } 57 58 public void sessionOpened(NextFilter nextFilter, IoSession session) { 59 SessionLog.info(session, "OPENED"); 60 nextFilter.sessionOpened(session); 61 } 62 63 public void sessionClosed(NextFilter nextFilter, IoSession session) { 64 SessionLog.info(session, "CLOSED"); 65 nextFilter.sessionClosed(session); 66 } 67 68 public void sessionIdle(NextFilter nextFilter, IoSession session, 69 IdleStatus status) { 70 if (SessionLog.isInfoEnabled(session)) { 71 SessionLog.info(session, "IDLE: " + status); 72 } 73 nextFilter.sessionIdle(session, status); 74 } 75 76 public void exceptionCaught(NextFilter nextFilter, IoSession session, 77 Throwable cause) { 78 if (SessionLog.isWarnEnabled(session)) { 79 SessionLog.warn(session, "EXCEPTION:", cause); 80 } 81 nextFilter.exceptionCaught(session, cause); 82 } 83 84 public void messageReceived(NextFilter nextFilter, IoSession session, 85 Object message) { 86 if (SessionLog.isInfoEnabled(session)) { 87 SessionLog.info(session, "RECEIVED: " + message); 88 } 89 nextFilter.messageReceived(session, message); 90 } 91 92 public void messageSent(NextFilter nextFilter, IoSession session, 93 Object message) { 94 if (SessionLog.isInfoEnabled(session)) { 95 SessionLog.info(session, "SENT: " + message); 96 } 97 nextFilter.messageSent(session, message); 98 } 99 100 public void filterWrite(NextFilter nextFilter, IoSession session, 101 WriteRequest writeRequest) { 102 if (SessionLog.isInfoEnabled(session)) { 103 SessionLog.info(session, "WRITE: " + writeRequest); 104 } 105 nextFilter.filterWrite(session, writeRequest); 106 } 107 108 public void filterClose(NextFilter nextFilter, IoSession session) 109 throws Exception { 110 SessionLog.info(session, "CLOSE"); 111 nextFilter.filterClose(session); 112 } 113 } 114 | Popular Tags |