EMMA Coverage Report (generated Sat Sep 03 11:42:34 KST 2005)
[all classes][org.apache.mina.util]

COVERAGE SUMMARY FOR SOURCE FILE [SessionLog.java]

nameclass, %method, %block, %line, %
SessionLog.java0%   (0/1)0%   (0/6)0%   (0/140)0%   (0/23)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SessionLog0%   (0/1)0%   (0/6)0%   (0/140)0%   (0/23)
<static initializer> 0%   (0/1)0%   (0/35)0%   (0/2)
SessionLog (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getClassName (Session): String 0%   (0/1)0%   (0/15)0%   (0/3)
getLogger (Session): Logger 0%   (0/1)0%   (0/42)0%   (0/9)
log (Level, Session, String): void 0%   (0/1)0%   (0/22)0%   (0/4)
log (Level, Session, String, Throwable): void 0%   (0/1)0%   (0/23)0%   (0/4)

1/*
2 *   @(#) $Id: SessionLog.java 264677 2005-08-30 02:44:35Z trustin $
3 *
4 *   Copyright 2004 The Apache Software Foundation
5 *
6 *   Licensed under the Apache License, Version 2.0 (the "License");
7 *   you may not use this file except in compliance with the License.
8 *   You may obtain a copy of the License at
9 *
10 *       http://www.apache.org/licenses/LICENSE-2.0
11 *
12 *   Unless required by applicable law or agreed to in writing, software
13 *   distributed under the License is distributed on an "AS IS" BASIS,
14 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 *   See the License for the specific language governing permissions and
16 *   limitations under the License.
17 *
18 */
19package org.apache.mina.util;
20 
21import java.util.logging.Level;
22import java.util.logging.Logger;
23 
24import org.apache.mina.common.Session;
25import org.apache.mina.io.IoSession;
26import org.apache.mina.protocol.ProtocolSession;
27 
28/**
29 * Call {@link #getLogger(Session)}, {@link #log(Level,Session, String)}, and
30 * {@link #log(Level,Session, String, Throwable)} to log protocol-specific messages.
31 * <p>
32 * Set {@link #PREFIX} and {@link #LOGGER} session attributes
33 * to override prefix string, logger, and log level.
34 *
35 * @author The Apache Directory Project (dev@directory.apache.org)
36 * @author Trustin Lee (trustin@apache.org)
37 * @version $Rev: 264677 $, $Date: 2005-08-30 11:44:35 +0900 $
38 *
39 */
40public class SessionLog {
41    /**
42     * Session attribute key: prefix string
43     */
44    public static final String PREFIX = SessionLog.class.getName() + ".prefix";
45 
46    /**
47     * Session attribute key: {@link Logger}
48     */
49    public static final String LOGGER = SessionLog.class.getName() + ".logger";
50    
51    public static Logger getLogger( Session session )
52    {
53        
54        Logger log = (Logger) session.getAttribute( LOGGER );
55        if( log == null )
56        {
57            log = Logger.getLogger( getClassName( session ) );
58            String prefix = ( String ) session.getAttribute( PREFIX );
59            if( prefix == null )
60            {
61                prefix = "[" + session.getRemoteAddress() + "] ";
62                session.setAttribute( PREFIX, prefix );
63            }
64                
65            session.setAttribute( LOGGER, log );
66        }
67        
68        return log;
69    }
70    
71    private static String getClassName( Session session )
72    {
73        if( session instanceof IoSession )
74            return ( ( IoSession ) session ).getHandler().getClass().getName();
75        else
76            return ( ( ProtocolSession ) session ).getHandler().getClass().getName();
77    }
78 
79    public static void log( Level level, Session session, String message )
80    {
81        Logger log = getLogger( session );
82        if( log.isLoggable( level ) )
83        {
84            log.log( level, String.valueOf( session.getAttribute( PREFIX ) ) + message );
85        }
86    }
87 
88    public static void log( Level level, Session session, String message, Throwable cause )
89    {
90        Logger log = getLogger( session );
91        if( log.isLoggable( level ) )
92        {
93            log.log( level, String.valueOf( session.getAttribute( PREFIX ) ) + message, cause );
94        }
95    }
96}

[all classes][org.apache.mina.util]
EMMA 2.0.4217 (C) Vladimir Roubtsov