FileDocCategorySizeDatePackage
JavaLog.javaAPI DocGlassfish v2 API11342Tue Jul 03 19:09:50 BST 2007oracle.toplink.essentials.logging

JavaLog

public class JavaLog extends AbstractSessionLog
PUBLIC:

This is a wrapper class for java.util.logging. It is used when messages need to be logged through java.util.logging.

see
SessionLog
see
AbstractSessionLog
see
SessionLogEntry
see
Session

Fields Summary
public static final String
TOPLINK_NAMESPACE
Stores the default session name in case there is the session name is missing.
public static final String
DEFAULT_TOPLINK_NAMESPACE
public static final String
SESSION_TOPLINK_NAMESPACE
private static final Level[]
levels
Stores all the java.util.logging.Levels. The indexes are TopLink logging levels.
private static Logger
defaultTopLinkLogger
Stores the Logger for default TopLink namespace, i.e. "oracle.toplink.essentials". This namespace should be a child of the TopLink namespace, e.g. "oracle.toplink.essentials.default", otherwise AbstractSessionLog will set the explicit level for all TopLink loggers (overriding the container settings) in the VM on the first PU with the specified log level.
private Map
nameSpaceMap
Represents the HashMap that stores all the name space strings. The keys are category names. The values are namespace strings.
private String
sessionNameSpace
Stores the namespace for session, i.e."oracle.toplink.essentials.session.".
private Logger
sessionLogger
Stores the Logger for session namespace, i.e. "oracle.toplink.essentials.session.".
private Map
categoryloggers
Constructors Summary
Methods Summary
public java.lang.Objectclone()
INTERNAL: Each session owns its own session log because session is stored in the session log

        // There is no special treatment required for cloning here
        // The state of this object is described  by member variables sessionLogger and categoryLoggers.
        // This state depends on session.
        // If session for the clone is going to be the same as session for this there is no
        // need to do "deep" cloning.
        // If not, the session being cloned should call setSession() on its JavaLog object to initialize it correctly.
        JavaLog cloneLog = (JavaLog)super.clone();
        return cloneLog;
    
private java.util.logging.LevelgetJavaLevel(int level)
INTERNAL: Return the corresponding java.util.logging.Level for a given TopLink level.

        return levels[level];
    
public intgetLevel(java.lang.String category)
PUBLIC:

Return the effective log level for the name space extracted from session and category. If a Logger's level is set to be null then the Logger will use an effective Level that will be obtained by walking up the parent tree and using the first non-null Level.

return
the effective log level.



                                                                 
        
        Logger logger = getLogger(category);
        while ((logger != null) && (logger.getLevel() == null)) {
            logger = logger.getParent();
        }

        if (logger == null) {
            return OFF;
        }

        //For a given java.util.logging.Level, return the index (ie, TopLink logging level)
        int logLevel = logger.getLevel().intValue();
        for (int i = 0; i < levels.length ; i++) {
            if (logLevel == levels[i].intValue()) {
                return i;
            }
        }
        return OFF;
    
protected java.util.logging.LoggergetLogger(java.lang.String category)
INTERNAL: Return the Logger for the given category

        if (session == null) {
            return defaultTopLinkLogger;
        } else if ((category == null) || (category.length() == 0)) {
            return sessionLogger;
        } else {
            Logger logger = (Logger) categoryloggers.get(category);
            // If session != null, categoryloggers should have an entry for this category
            assert logger != null;
            return logger;
        }
    
protected java.lang.StringgetNameSpaceString(java.lang.String category)
INTERNAL: Return the name space for the given category from the map.

        if (session == null) {
            return DEFAULT_TOPLINK_NAMESPACE;
        } else if ((category == null) || (category.length() == 0)) {
            return sessionNameSpace;
        } else {
            return  (String)nameSpaceMap.get(category);
        }
    
protected voidinternalLog(oracle.toplink.essentials.logging.SessionLogEntry entry, java.util.logging.Level javaLevel, java.util.logging.Logger logger)
INTERNAL:

Build a LogRecord

param
entry SessionLogEntry that holds all the information for a TopLink logging event
param
javaLevel the message level

        // Format message so that we do not depend on the bundle
        TopLinkLogRecord lr = new TopLinkLogRecord(javaLevel, formatMessage(entry)); 

        lr.setSourceClassName(null);
        lr.setSourceMethodName(null);
        lr.setLoggerName(getNameSpaceString(entry.getNameSpace()));
        if (shouldPrintSession()) {
            lr.setSessionString(getSessionString(entry.getSession()));
        }
        if (shouldPrintConnection()) {
            lr.setConnection(entry.getConnection());
        }
        lr.setThrown(entry.getException());
        lr.setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace());
        lr.setShouldPrintDate(shouldPrintDate());
        lr.setShouldPrintThread(shouldPrintThread());
        logger.log(lr);
    
public voidlog(oracle.toplink.essentials.logging.SessionLogEntry entry)
PUBLIC:

Log a SessionLogEntry

param
entry SessionLogEntry that holds all the information for a TopLink logging event

        if (!shouldLog(entry.getLevel(), entry.getNameSpace())) {
            return;
        }

        Logger logger = getLogger(entry.getNameSpace());
        Level javaLevel = getJavaLevel(entry.getLevel());

        internalLog(entry, javaLevel, logger);
    
public voidsetLevel(int level, java.lang.String category)
PUBLIC:

Set the log level to a logger with name space extracted from the given category.

        final Logger logger = getLogger(category);
        if (logger == null) {
            return;
        }
        
        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                logger.setLevel(getJavaLevel(level));
                return null; // nothing to return
            }
        });
    
public voidsetSession(oracle.toplink.essentials.sessions.Session session)
PUBLIC:

Set the session and session namespace.

param
session a Session

        super.setSession(session);
        if (session != null) {
            String sessionName = session.getName();
            if ((sessionName != null) && (sessionName.length() != 0)) {
                sessionNameSpace = SESSION_TOPLINK_NAMESPACE + "." + sessionName;
            } else {
                sessionNameSpace = DEFAULT_TOPLINK_NAMESPACE;
            }

            //Initialize loggers eagerly
            sessionLogger = Logger.getLogger(sessionNameSpace);
            for (int i = 0; i < loggerCategories.length; i++) {
                String loggerCategory =  loggerCategories[i]; 
                String loggerNameSpace = sessionNameSpace + "." + loggerCategory;
                nameSpaceMap.put(loggerCategory, loggerNameSpace);
                categoryloggers.put(loggerCategory, Logger.getLogger(loggerNameSpace));
            }
        }
    
public booleanshouldLog(int level, java.lang.String category)
PUBLIC:

Check if a message of the given level would actually be logged by the logger with name space built from the given session and category. Return the shouldLog for the given category from

return
true if the given message level will be logged

        Logger logger = getLogger(category);
        return logger.isLoggable(getJavaLevel(level));
    
public voidthrowing(java.lang.Throwable throwable)
PUBLIC:

Log a throwable.

param
throwable a throwable

        getLogger(null).throwing(null, null, throwable);