FileDocCategorySizeDatePackage
AbstractSessionLog.javaAPI DocGlassfish v2 API30160Thu Jul 19 11:52:00 BST 2007oracle.toplink.essentials.logging

AbstractSessionLog

public abstract class AbstractSessionLog extends Object implements SessionLog, Cloneable
Represents the abstract log that implements all the generic logging functions. It contains a singleton SessionLog that logs messages from outside any TopLink session. The singleton SessionLog can also be passed to a TopLink session when messages are logged through that session. When JDK1.4 is used, a singleton JavaLog is created. Otherwise a singleton DefaultSessionLog is created.
see
SessionLog
see
SessionLogEntry
see
DefaultSessionLog
see
JavaLog

Fields Summary
protected int
level
Represents the log level
protected static SessionLog
defaultLog
Represents the singleton SessionLog
protected Session
session
Represents the session that owns this SessionLog
protected String
sessionType
Represents the session type of the session that owns this SessionLog
protected String
sessionHashCode
Caches the session hash code string of the session that owns this SessionLog
protected static String
SEVERE_PREFIX
Represents prefix to logged severe
protected static String
WARNING_PREFIX
Represents prefix to logged warning
protected static String
INFO_PREFIX
Represents prefix to logged info
protected static String
CONFIG_PREFIX
Represents prefix to logged config
protected static String
FINE_PREFIX
Represents prefix to logged fine
protected static String
FINER_PREFIX
Represents prefix to logged finer
protected static String
FINEST_PREFIX
Represents prefix to logged finest
protected static String
TOPLINK_PREFIX
Cached TopLink prefix string.
protected static final String
CONNECTION_STRING
Connection string
protected static final String
THREAD_STRING
Thread string
protected Writer
writer
Represents the writer that will receive the formatted log entries
protected DateFormat
dateFormat
Format use to print the current date/time.
protected Boolean
shouldLogExceptionStackTrace
Allows the printing of the stack to be explictitly disabled/enabled. CR #3870467. null value is default behavoir of determining from log level.
protected Boolean
shouldPrintDate
Allows the printing of the date to be explictitly disabled/enabled. CR #3870467. null value is default behavoir of determining from log level.
protected Boolean
shouldPrintThread
Allows the printing of the thread to be explictitly disabled/enabled. CR #3870467. null value is default behavoir of determining from log level.
protected Boolean
shouldPrintSession
Allows the printing of the session to be explictitly disabled/enabled. CR #3870467. null value is default behavoir of determining from log level.
protected Boolean
shouldPrintConnection
Allows the printing of the connection to be explictitly disabled/enabled. CR #4157545. null value is default behavoir of determining from log level.
Constructors Summary
public AbstractSessionLog()
PUBLIC: Create a new AbstractSessionLog


              
      
        this.writer = new PrintWriter(System.out);
    
Methods Summary
protected java.text.DateFormatbuildDefaultDateFormat()
Build and return a date format. The default is a format that is sortable and easily parsed.

return
the date format

        return new SimpleDateFormat("yyyy.MM.dd hh:mm:ss.SSS");
    
protected voidbuildSessionHashCode()
Return the current session hash code.

        if (session != null) {
            sessionHashCode = String.valueOf(System.identityHashCode(session));
        } else {
            sessionHashCode = null;
        }
    
protected voidbuildSessionType()
Return the current session type.

        if (session != null) {
            sessionType = ((AbstractSession)session).getSessionTypeString();
        } else {
            sessionType = null;
        }
    
public java.lang.Objectclone()
INTERNAL: Each session owns its own session log because session is stored in the session log

        try {
            return super.clone();
        } catch (Exception exception) {
            return null;
        }
    
public voidconfig(java.lang.String message)
PUBLIC:

This method is called when a config level message needs to be logged. The message will be translated

param
message the message key

        log(CONFIG, message, (Object[])null);
    
public voidfine(java.lang.String message)
PUBLIC:

This method is called when a fine level message needs to be logged. The message will be translated

param
message the message key

        log(FINE, message, (Object[])null);
    
public voidfiner(java.lang.String message)
PUBLIC:

This method is called when a finer level message needs to be logged. The message will be translated

param
message the message key

        log(FINER, message, (Object[])null);
    
public voidfinest(java.lang.String message)
PUBLIC:

This method is called when a finest level message needs to be logged. The message will be translated

param
message the message key

        log(FINEST, message, (Object[])null);
    
protected java.lang.StringformatMessage(oracle.toplink.essentials.logging.SessionLogEntry entry)
Return the formatted message based on the information from the given SessionLogEntry. The message will either be translated and formatted or formatted only depending on if the shouldTranslate flag is set to true of false.

        String message = entry.getMessage();
        if (entry.shouldTranslate()) {
            if (entry.getLevel() > FINE) {
                message = LoggingLocalization.buildMessage(message, entry.getParameters());
            } else {
                message = TraceLocalization.buildMessage(message, entry.getParameters());
            }
        } else {
            //bug#2988,if there are entry parameters and the string "{0" contained in the message
            //body, we assume it needs to be formatted.
            if (entry.getParameters()!=null && entry.getParameters().length>0 && message.indexOf("{0") >= 0) {
                message = java.text.MessageFormat.format(message, entry.getParameters());
            }
        }
        return message;
    
protected java.lang.StringgetConnectionString(oracle.toplink.essentials.internal.databaseaccess.Accessor connection)
Return the specified connection information.

        // Bug 3630182 - if possible, print the actual connection's hashcode instead of just the accessor
        if (connection.getDatasourceConnection() == null){
            return CONNECTION_STRING + "(" + String.valueOf(System.identityHashCode(connection)) + ")";
        } else {
             return CONNECTION_STRING + "(" + String.valueOf(System.identityHashCode(connection.getDatasourceConnection())) + ")";   
        }
    
public java.text.DateFormatgetDateFormat()
PUBLIC: Return the date format to be used when printing a log entry date.

return
the date format

        if (dateFormat == null) {
            dateFormat = this.buildDefaultDateFormat();
        }
        return dateFormat;
    
protected java.lang.StringgetDateString(java.util.Date date)
Return the specified date and/or time information in string. The format will be determined by the date format settings.

        return this.getDateFormat().format(date);
    
public intgetLevel()
PUBLIC:

Return the log level. It is used when session is not available.

return
the log level

        return getLevel(null);
    
public intgetLevel(java.lang.String category)
PUBLIC:

Return the log level for the category name space.

return
the log level

param
category the string representation of a TopLink category, e.g. "sql", "transaction" ...

        return level;
    
public static oracle.toplink.essentials.logging.SessionLoggetLog()
PUBLIC:

Return the singleton SessionLog. If the singleton SessionLog does not exist, a new one is created based on the version of JDK being used from the Version class.

return
the singleton SessionLog

        if (defaultLog == null) {
            defaultLog = new DefaultSessionLog();
        }
        return defaultLog;
    
public oracle.toplink.essentials.sessions.SessiongetSession()
PUBLIC:

Get the session.

return
session

        return this.session;
    
protected java.lang.StringgetSessionString(oracle.toplink.essentials.sessions.Session session)
Return the current session including the type and id.

        // For bug 3422759 the session to log against should be the one in the
        // event, not the static one in the SessionLog, for there are many
        // sessions but only one SessionLog.
        if (session != null) {
            return ((AbstractSession)session).getLogSessionString();
        } else {
            return getSessionString();
        }
    
protected java.lang.StringgetSessionString()
Return the current session including the type and id.

        return sessionType + "(" + sessionHashCode + ")";
    
protected java.lang.StringgetSupplementDetailString(oracle.toplink.essentials.logging.SessionLogEntry entry)
Return the supplement detail information including date, session, thread and connection.

        StringWriter writer = new StringWriter();

        if (shouldPrintDate()) {
            writer.write(getDateString(entry.getDate()));
            writer.write("--");
        }
        if (shouldPrintSession() && (entry.getSession() != null)) {
            writer.write(this.getSessionString(entry.getSession()));
            writer.write("--");
        }
        if (shouldPrintConnection() && (entry.getConnection() != null)) {
            writer.write(this.getConnectionString(entry.getConnection()));
            writer.write("--");
        }
        if (shouldPrintThread()) {
            writer.write(this.getThreadString(entry.getThread()));
            writer.write("--");
        }
        return writer.toString();
    
protected java.lang.StringgetThreadString(java.lang.Thread thread)
Return the specified thread information.

        return THREAD_STRING + "(" + String.valueOf(thread) + ")";
    
public java.io.WritergetWriter()
PUBLIC:

Return the writer that will receive the formatted log entries.

return
the log writer

        return writer;
    
public voidinfo(java.lang.String message)
PUBLIC:

This method is called when a info level message needs to be logged. The message will be translated

param
message the message key

        log(INFO, message, (Object[])null);
    
public booleanisOff()
PUBLIC: Check if the log level is set to off.

        return this.level == OFF;
    
public voidlog(int level, java.lang.String message)
PUBLIC:

Log a message that does not need to be translated. This method is intended for external use when logging messages are wanted within the TopLink output.

param
level the log request level value

param
message the string message

        if (!shouldLog(level)) {
            return;
        }
		//Bug#4566524  Pass in false for external use
        log(level, message, (Object[])null, false);
    
public voidlog(int level, java.lang.String message, java.lang.Object param)
INTERNAL:

Log a message with one parameter that needs to be translated.

param
level the log request level value

param
message the string message

param
param a parameter of the message

        if (!shouldLog(level)) {
            return;
        }
        log(level, message, new Object[] { param });
    
public voidlog(int level, java.lang.String message, java.lang.Object param1, java.lang.Object param2)
INTERNAL:

Log a message with two parameters that needs to be translated.

param
level the log request level value

param
message the string message

param
param1 a parameter of the message

param
param2 second parameter of the message

        if (!shouldLog(level)) {
            return;
        }
        log(level, message, new Object[] { param1, param2 });
    
public voidlog(int level, java.lang.String message, java.lang.Object param1, java.lang.Object param2, java.lang.Object param3)
INTERNAL:

Log a message with three parameters that needs to be translated.

param
level the log request level value

param
message the string message

param
param1 a parameter of the message

param
param2 second parameter of the message

param
param3 third parameter of the message

        if (!shouldLog(level)) {
            return;
        }
        log(level, message, new Object[] { param1, param2, param3 });
    
public voidlog(int level, java.lang.String message, java.lang.Object[] params)
INTERNAL:

Log a message with an array of parameters that needs to be translated.

param
level the log request level value

param
message the string message

param
params array of parameters to the message

        log(level, message, params, true);
    
public voidlog(int level, java.lang.String message, java.lang.Object[] params, boolean shouldTranslate)
INTERNAL:

Log a message. shouldTranslate determines if the message needs to be translated.

param
level the log request level

param
message the string message

param
params array of parameters to the message

param
shouldTranslate true if the message needs to be translated

        if (!shouldLog(level)) {
            return;
        }
        log(new SessionLogEntry(level, null, message, params, null, shouldTranslate));
    
public abstract voidlog(oracle.toplink.essentials.logging.SessionLogEntry sessionLogEntry)
PUBLIC:

Log a SessionLogEntry

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

public voidlogThrowable(int level, java.lang.Throwable throwable)
PUBLIC:

Log a throwable with level.

param
level the log request level value

param
throwable a Throwable

        // Must not create the log if not logging as is a performance issue.
        if (shouldLog(level)) {
            log(new SessionLogEntry(null, level, null, throwable));
        }
    
protected voidprintPrefixString(int level)
Print the prefix string representing TopLink logging

        try {
            switch (level) {
            case SEVERE:
                if (SEVERE_PREFIX == null) {
                    SEVERE_PREFIX = LoggingLocalization.buildMessage("toplink_severe");
                }
                this.getWriter().write(SEVERE_PREFIX);
                break;
            case WARNING:
                if (WARNING_PREFIX == null) {
                    WARNING_PREFIX = LoggingLocalization.buildMessage("toplink_warning");
                }
                this.getWriter().write(WARNING_PREFIX);
                break;
            case INFO:
                if (INFO_PREFIX == null) {
                    INFO_PREFIX = LoggingLocalization.buildMessage("toplink_info");
                }
                this.getWriter().write(INFO_PREFIX);
                break;
            case CONFIG:
                if (CONFIG_PREFIX == null) {
                    CONFIG_PREFIX = LoggingLocalization.buildMessage("toplink_config");
                }
                this.getWriter().write(CONFIG_PREFIX);
                break;
            case FINE:
                if (FINE_PREFIX == null) {
                    FINE_PREFIX = LoggingLocalization.buildMessage("toplink_fine");
                }
                this.getWriter().write(FINE_PREFIX);
                break;
            case FINER:
                if (FINER_PREFIX == null) {
                    FINER_PREFIX = LoggingLocalization.buildMessage("toplink_finer");
                }
                this.getWriter().write(FINER_PREFIX);
                break;
            case FINEST:
                if (FINEST_PREFIX == null) {
                    FINEST_PREFIX = LoggingLocalization.buildMessage("toplink_finest");
                }
                this.getWriter().write(FINEST_PREFIX);
                break;
            default:
                if (TOPLINK_PREFIX == null) {
                    TOPLINK_PREFIX = LoggingLocalization.buildMessage("toplink");
                }
                this.getWriter().write(TOPLINK_PREFIX);
            }
        } catch (IOException exception) {
            throw ValidationException.logIOError(exception);
        }
    
public voidsetDateFormat(java.text.DateFormat dateFormat)
PUBLIC: Set the date format to be used when printing a log entry date.

param
dateFormat java.text.DateFormat

        this.dateFormat = dateFormat;
    
public voidsetLevel(int level)
PUBLIC:

Set the log level. It is used when session is not available.

param
level the new log level

        setLevel(level, null);
    
public voidsetLevel(int level, java.lang.String category)
PUBLIC:

Set the log level for the category name space.

param
level the new log level
param
category the string representation of a TopLink category, e.g. "sql", "transaction" ...

        this.level = level;
    
public static voidsetLog(oracle.toplink.essentials.logging.SessionLog sessionLog)
PUBLIC:

Set the singleton SessionLog.

param
sessionLog a SessionLog

        defaultLog = sessionLog;
        defaultLog.setSession(null);
    
public voidsetSession(oracle.toplink.essentials.sessions.Session session)
PUBLIC:

Set the session.

param
session a Session

        if (this.session == null) {
            this.session = session;
            buildSessionType();
            buildSessionHashCode();
        }
    
public voidsetShouldLogExceptionStackTrace(boolean shouldLogExceptionStackTrace)
By default the stack is logged for FINER or less (finest). The logging of the stack can also be explicitly turned on or off.

        if (shouldLogExceptionStackTrace) {
            this.shouldLogExceptionStackTrace = Boolean.TRUE;
        } else {
            this.shouldLogExceptionStackTrace = Boolean.FALSE;            
        }
    
public voidsetShouldPrintConnection(boolean shouldPrintConnection)
By default the connection is printed, this can be turned off.

        if (shouldPrintConnection) {
            this.shouldPrintConnection = Boolean.TRUE;
        } else {
            this.shouldPrintConnection = Boolean.FALSE;            
        }
    
public voidsetShouldPrintDate(boolean shouldPrintDate)
By default the date is always printed, but can be turned off.

        if (shouldPrintDate) {
            this.shouldPrintDate = Boolean.TRUE;
        } else {
            this.shouldPrintDate = Boolean.FALSE;            
        }
    
public voidsetShouldPrintSession(boolean shouldPrintSession)
By default the session (and its connection is available) are printed, this can be turned off.

        if (shouldPrintSession) {
            this.shouldPrintSession = Boolean.TRUE;
        } else {
            this.shouldPrintSession = Boolean.FALSE;            
        }
    
public voidsetShouldPrintThread(boolean shouldPrintThread)
By default the thread is logged for FINE or less (finer,etc.). The logging of the thread can also be explicitly turned on or off.

        if (shouldPrintThread) {
            this.shouldPrintThread = Boolean.TRUE;
        } else {
            this.shouldPrintThread = Boolean.FALSE;            
        }
    
public voidsetWriter(java.io.Writer writer)
PUBLIC:

Set the writer that will receive the formatted log entries.

param
writer the log writer

        this.writer = writer;
    
public voidsevere(java.lang.String message)
PUBLIC:

This method is called when a severe level message needs to be logged. The message will be translated

param
message the message key

        log(SEVERE, message, (Object[])null);
    
public booleanshouldLog(int level)
PUBLIC:

Check if a message of the given level would actually be logged. It is used when session is not available.

return
true if the given message level will be logged

param
level the log request level

        return shouldLog(level, null);
    
public booleanshouldLog(int level, java.lang.String category)
PUBLIC:

Check if a message of the given level would actually be logged for the category name space. !isOff() is checked to screen out the possibility when both log level and log request level are set to OFF.

return
true if the given message level will be logged

param
level the log request level
param
category the string representation of a TopLink category, e.g. "sql", "transaction" ...*

        return (this.level <= level) && !isOff();
    
public booleanshouldLogExceptionStackTrace()
By default the stack is logged for FINER or less (finest). The logging of the stack can also be explicitly turned on or off.

        if (shouldLogExceptionStackTrace == null) {
            return getLevel() <= FINER;
        } else {
            return shouldLogExceptionStackTrace.booleanValue();
        }
    
public booleanshouldPrintConnection()
By default the connection is printed, this can be turned off.

        return (shouldPrintConnection == null) || shouldPrintConnection.booleanValue();
    
public booleanshouldPrintDate()
By default the date is always printed, but can be turned off.

        return (shouldPrintDate == null) || (shouldPrintDate.booleanValue());
    
public booleanshouldPrintSession()
By default the session (and its connection is available) are printed, this can be turned off.

        return (shouldPrintSession == null) || shouldPrintSession.booleanValue();
    
public booleanshouldPrintThread()
By default the thread is logged for FINE or less (finer,etc.). The logging of the thread can also be explicitly turned on or off.

        if (shouldPrintThread == null) {
            return getLevel() <= FINE;
        } else {
            return shouldPrintThread.booleanValue();
        }
    
public voidthrowing(java.lang.Throwable throwable)
PUBLIC:

Log a throwable at FINER level.

param
throwable a Throwable

        if (shouldLog(FINER)) {
            SessionLogEntry entry = new SessionLogEntry(null, throwable);
            entry.setLevel(FINER);
            log(entry);
        }
    
public static java.lang.StringtranslateLoggingLevelToString(int loggingLevel)
INTERNAL: Translate the string value of the log level to the constant value. If value is null or invalid use the default.

        if (loggingLevel == OFF){
            return "OFF";
        } else if (loggingLevel == SEVERE){
            return "SEVERE";
        } else if (loggingLevel == WARNING){
            return "WARNING";
        } else if (loggingLevel == INFO){
            return "INFO";
        } else if (loggingLevel == CONFIG){
            return "CONFIG";
        } else if (loggingLevel == FINE){
            return "FINE";
        } else if (loggingLevel == FINER){
            return "FINER";
        } else if (loggingLevel == FINEST){
            return "FINEST";
        } else if (loggingLevel == ALL){
            return "ALL";
        }
        return "INFO";
    
public static inttranslateStringToLoggingLevel(java.lang.String loggingLevel)
INTERNAL: Translate the string value of the log level to the constant value. If value is null or invalid use the default.

        if (loggingLevel == null){
            return INFO;
        } else if (loggingLevel.equals("OFF")){
            return OFF;
        } else if (loggingLevel.equals("SEVERE")){
            return SEVERE;
        } else if (loggingLevel.equals("WARNING")){
            return WARNING;
        } else if (loggingLevel.equals("INFO")){
            return INFO;
        } else if (loggingLevel.equals("CONFIG")){
            return CONFIG;
        } else if (loggingLevel.equals("FINE")){
            return FINE;
        } else if (loggingLevel.equals("FINER")){
            return FINER;
        } else if (loggingLevel.equals("FINEST")){
            return FINEST;
        } else if (loggingLevel.equals("ALL")){
            return ALL;
        }
        return INFO;
    
public voidwarning(java.lang.String message)
PUBLIC:

This method is called when a warning level message needs to be logged. The message will be translated

param
message the message key

        log(WARNING, message, (Object[])null);