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

DefaultSessionLog

public class DefaultSessionLog extends AbstractSessionLog implements Serializable

Purpose: Default log used for the session when message logging is enabled. The session can log information such as,

  • all SQL executed
  • informational messages
  • debugging information
  • all exceptions that occur within TopLink
As well information about the message can be logged such as,
  • the session logging the message
  • the connection executing the SQL
  • the thread in which the log entry occured
  • the exact time (to milliseconds) that the log entry occured
  • the stack trace to the exception
see
SessionLog
see
Session#logMessage(String)
author
Big Country

Fields Summary
protected String
fileName
The filename associated with this DefaultSessionLog, if it is being written out to a file
private Map
categoryLogLevelMap
Represents the Map that stores log levels per the name space strings. The keys are category names. The values are log levels.
Constructors Summary
public DefaultSessionLog()
PUBLIC: Create a new default session log.


                
      
        super();
        this.level = INFO;
        for (int i = 0; i < loggerCategories.length; i++) {
            String loggerCategory = loggerCategories[i]; 
            categoryLogLevelMap.put(loggerCategory, null);
        }
    
public DefaultSessionLog(Writer writer)
PUBLIC: Create a new default session log for the given writer.

        this();
        this.initialize(writer);
    
Methods Summary
public intgetLevel(java.lang.String category)

        if(category != null) {
            Integer logLevel = categoryLogLevelMap.get(category);
            // if category-specific log level is not set, use parent level.
            if(logLevel != null) {
                return logLevel.intValue();
            }
        }
        return level;
    
public java.lang.StringgetWriterFilename()
PUBLIC: For the given writer, return it's associated filename. If associated writer does not have a filename, return null.

        return fileName;
    
protected voidinitialize(java.io.Writer writer)
Initialize the log.

        this.writer = writer;
    
public synchronized voidlog(oracle.toplink.essentials.logging.SessionLogEntry entry)
INTERNAL: Log the entry. This writes the log entries information to a writer such as System.out or a file. This must be synchronized as it will be called by many threads in three-tier.

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

        try {
            printPrefixString(entry.getLevel());
            this.getWriter().write(getSupplementDetailString(entry));

            if (entry.hasException()) {
                if (entry.getLevel() == SEVERE) {
                    entry.getException().printStackTrace(new PrintWriter(getWriter()));
                } else if (entry.getLevel() <= WARNING) {
                    if (shouldLogExceptionStackTrace()) {
                        entry.getException().printStackTrace(new PrintWriter(getWriter()));
                    } else {
                        writeMessage(entry.getException().toString());
                    }
                }
            } else {
                writeMessage(formatMessage(entry));
            }
            getWriter().write(Helper.cr());
            getWriter().flush();
        } catch (IOException exception) {
            throw ValidationException.logIOError(exception);
        }
    
public voidsetLevel(int level, java.lang.String category)

        if(category == null) {
            this.level = level;
        } else if(categoryLogLevelMap.containsKey(category)) {
            categoryLogLevelMap.put(category, level);
        }
    
public voidsetWriter(java.lang.String aFileName)
PUBLIC: Set the writer that will receive the formatted log entries for a file name.

        if (aFileName != null) {
            try {
                this.writer = new FileWriter(aFileName);
                this.fileName = aFileName;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
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

        return (getLevel(category) <= level);
    
protected voidwriteMessage(java.lang.String message)
Append the specified message information to the writer.

        this.getWriter().write(message);
    
protected voidwriteSeparator()
Append the separator string to the writer.

        this.getWriter().write("--");