directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r165594 - in /directory/network/trunk/src: examples/org/apache/mina/examples/echoserver/ examples/org/apache/mina/examples/reverser/ java/org/apache/mina/io/filter/ java/org/apache/mina/protocol/filter/ java/org/apache/mina/util/
Date Mon, 02 May 2005 07:21:24 GMT
Author: trustin
Date: Mon May  2 00:21:22 2005
New Revision: 165594

URL: http://svn.apache.org/viewcvs?rev=165594&view=rev
Log:
* Added LoggingFilter.defaultLevel property: The filter will log with that level
* LoggingFilter is not a singleton anymore due to introduction of new property.

Modified:
    directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java
    directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/IoLoggingFilter.java
    directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolLoggingFilter.java
    directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java?rev=165594&r1=165593&r2=165594&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/echoserver/Main.java Mon
May  2 00:21:22 2005
@@ -73,7 +73,7 @@
     private static void addLogger( ServiceRegistry registry )
     {
         IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "logger", IoLoggingFilter.getInstance() );
+        acceptor.getFilterChain().addLast( "logger", new IoLoggingFilter() );
         System.out.println( "Logging ON" );
     }
 }

Modified: directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java?rev=165594&r1=165593&r2=165594&view=diff
==============================================================================
--- directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java (original)
+++ directory/network/trunk/src/examples/org/apache/mina/examples/reverser/Main.java Mon May
 2 00:21:22 2005
@@ -51,7 +51,7 @@
     private static void addLogger( ServiceRegistry registry )
     {
         ProtocolAcceptor acceptor = registry.getProtocolAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "logger", ProtocolLoggingFilter.getInstance()
);
+        acceptor.getFilterChain().addLast( "logger", new ProtocolLoggingFilter() );
         System.out.println( "Logging ON" );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/IoLoggingFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/IoLoggingFilter.java?rev=165594&r1=165593&r2=165594&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/IoLoggingFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/IoLoggingFilter.java Mon May
 2 00:21:22 2005
@@ -48,67 +48,72 @@
      */
     public static final String LOGGER = SessionLog.LOGGER;
     
+    private Level defaultLevel = Level.INFO;
+    
     /**
-     * Session attribute key: {@link Level}
+     * Creates a new instance.
      */
-    public static final String LEVEL = SessionLog.LEVEL;
+    public IoLoggingFilter()
+    {
+    }
     
-    private static final IoLoggingFilter INSTANCE = new IoLoggingFilter();
-
     /**
-     * Returns a logging filter.
+     * Returns the default level of log entry this filter logs. 
      */
-    public static IoLoggingFilter getInstance()
-    {
-        return INSTANCE;
+    public Level getDefaultLevel() {
+        return defaultLevel;
     }
     
     /**
-     * Creates a new instance.
+     * Sets the default level of log entry this filter logs. 
      */
-    protected IoLoggingFilter()
-    {
+    public void setDefaultLevel(Level defaultLevel) {
+        if( defaultLevel == null )
+        {
+            defaultLevel = Level.INFO;
+        }
+        this.defaultLevel = defaultLevel;
     }
     
     public void sessionOpened( NextFilter nextFilter, IoSession session )
     {
-        SessionLog.log( session, "OPENED" );
+        SessionLog.log( defaultLevel, session, "OPENED" );
         nextFilter.sessionOpened( session );
     }
 
     public void sessionClosed( NextFilter nextFilter, IoSession session )
     {
-        SessionLog.log( session, "CLOSED" );
+        SessionLog.log( defaultLevel, session, "CLOSED" );
         nextFilter.sessionClosed( session );
     }
 
     public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status
)
     {
-        SessionLog.log( session, "IDLE: " + status );
+        SessionLog.log( defaultLevel, session, "IDLE: " + status );
         nextFilter.sessionIdle( session, status );
     }
 
     public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause
)
     {
-        SessionLog.log( session, "EXCEPTION:", cause );
+        SessionLog.log( defaultLevel, session, "EXCEPTION:", cause );
         nextFilter.exceptionCaught( session, cause );
     }
 
     public void dataRead( NextFilter nextFilter, IoSession session, ByteBuffer buf)
     {
-        SessionLog.log( session, "READ: " + buf.getHexDump() );
+        SessionLog.log( defaultLevel, session, "READ: " + buf.getHexDump() );
         nextFilter.dataRead( session, buf );
     }
 
     public void dataWritten( NextFilter nextFilter, IoSession session, Object marker)
     {
-        SessionLog.log( session, "WRITTEN: " + marker );
+        SessionLog.log( defaultLevel, session, "WRITTEN: " + marker );
         nextFilter.dataWritten( session, marker );
     }
 
     public void filterWrite( NextFilter nextFilter, IoSession session, ByteBuffer buf, Object
marker)
     {
-        SessionLog.log( session, "WRITE:" + marker + ", " + buf.getHexDump() );
+        SessionLog.log( defaultLevel, session, "WRITE:" + marker + ", " + buf.getHexDump()
);
         nextFilter.filterWrite( session, buf, marker );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolLoggingFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolLoggingFilter.java?rev=165594&r1=165593&r2=165594&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolLoggingFilter.java
(original)
+++ directory/network/trunk/src/java/org/apache/mina/protocol/filter/ProtocolLoggingFilter.java
Mon May  2 00:21:22 2005
@@ -47,67 +47,73 @@
      */
     public static final String LOGGER = SessionLog.LOGGER;
     
+    private Level defaultLevel = Level.INFO;
+    
     /**
-     * Session attribute key: {@link Level}
+     * Creates a new instance.
      */
-    public static final String LEVEL = SessionLog.LEVEL;
+    public ProtocolLoggingFilter()
+    {
+    }
+    
     
-    private static final ProtocolLoggingFilter INSTANCE = new ProtocolLoggingFilter();
-
     /**
-     * Returns a logging filter.
+     * Returns the default level of log entry this filter logs. 
      */
-    public static ProtocolLoggingFilter getInstance()
-    {
-        return INSTANCE;
+    public Level getDefaultLevel() {
+        return defaultLevel;
     }
     
     /**
-     * Creates a new instance.
+     * Sets the default level of log entry this filter logs. 
      */
-    protected ProtocolLoggingFilter()
-    {
+    public void setDefaultLevel(Level defaultLevel) {
+        if( defaultLevel == null )
+        {
+            defaultLevel = Level.INFO;
+        }
+        this.defaultLevel = defaultLevel;
     }
     
     public void sessionOpened( NextFilter nextFilter, ProtocolSession session )
     {
-        SessionLog.log( session, "OPENED" );
+        SessionLog.log( defaultLevel, session, "OPENED" );
         nextFilter.sessionOpened( session );
     }
 
     public void sessionClosed( NextFilter nextFilter, ProtocolSession session )
     {
-        SessionLog.log( session, "CLOSED" );
+        SessionLog.log( defaultLevel, session, "CLOSED" );
         nextFilter.sessionClosed( session );
     }
 
     public void sessionIdle( NextFilter nextFilter, ProtocolSession session, IdleStatus status
)
     {
-        SessionLog.log( session, "IDLE: " + status );
+        SessionLog.log( defaultLevel, session, "IDLE: " + status );
         nextFilter.sessionIdle( session, status );
     }
 
     public void exceptionCaught( NextFilter nextFilter, ProtocolSession session, Throwable
cause )
     {
-        SessionLog.log( session, "EXCEPTION:", cause );
+        SessionLog.log( defaultLevel, session, "EXCEPTION:", cause );
         nextFilter.exceptionCaught( session, cause );
     }
 
     public void messageReceived( NextFilter nextFilter, ProtocolSession session, Object message
)
     {
-        SessionLog.log( session, "RECEIVED: " + message );
+        SessionLog.log( defaultLevel, session, "RECEIVED: " + message );
         nextFilter.messageReceived( session, message );
     }
 
     public void messageSent( NextFilter nextFilter, ProtocolSession session, Object message
)
     {
-        SessionLog.log( session, "SENT: " + message );
+        SessionLog.log( defaultLevel, session, "SENT: " + message );
         nextFilter.messageSent( session, message );
     }
 
     public void filterWrite( NextFilter nextFilter, ProtocolSession session, Object message)
     {
-        SessionLog.log( session, "WRITE: " + message );
+        SessionLog.log( defaultLevel, session, "WRITE: " + message );
         nextFilter.filterWrite( session, message );
     }
 }

Modified: directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java?rev=165594&r1=165593&r2=165594&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/util/SessionLog.java Mon May  2 00:21:22
2005
@@ -8,8 +8,8 @@
 import org.apache.mina.protocol.ProtocolSession;
 
 /**
- * Call {@link #getLogger(Session)}, {@link #log(Session, String)}, and
- * {@link #log(Session, String, Throwable)} to log protocol-specific messages.
+ * Call {@link #getLogger(Session)}, {@link #log(Level,Session, String)}, and
+ * {@link #log(Level,Session, String, Throwable)} to log protocol-specific messages.
  * <p>
  * Set {@link #PREFIX}, {@link #LOGGER}, {@link #LEVEL} session attributes
  * to override prefix string, logger, and log level.
@@ -70,20 +70,18 @@
             return ( ( ProtocolSession ) session ).getHandler().getClass().getName();
     }
 
-    public static void log( Session session, String message )
+    public static void log( Level level, Session session, String message )
     {
         Logger log = getLogger( session );
-        Level level = ( Level ) session.getAttribute( LEVEL );
         if( log.isLoggable( level ) )
         {
             log.log( level, message );
         }
     }
 
-    public static void log( Session session, String message, Throwable cause )
+    public static void log( Level level, Session session, String message, Throwable cause
)
     {
         Logger log = getLogger( session );
-        Level level = ( Level ) session.getAttribute( LEVEL );
         if( log.isLoggable( level ) )
         {
             log.log( level, message, cause );



Mime
View raw message