org.eclipse.core.runtime.adaptor
Class EclipseLog

java.lang.Object
  extended by org.eclipse.core.runtime.adaptor.EclipseLog
All Implemented Interfaces:
org.eclipse.osgi.framework.log.FrameworkLog

public class EclipseLog
extends java.lang.Object
implements org.eclipse.osgi.framework.log.FrameworkLog

The FrameworkLog implementation for Eclipse.

Clients may extend this class.

Since:
3.1

Field Summary
static java.lang.String BACKUP_MARK
          The extension markup to use for backup log files
protected  boolean consoleLog
          Indicates if the console messages should be printed to the console (System.out)
static int DEFAULT_LOG_FILES
          The default number of backup log files
static int DEFAULT_LOG_SIZE
          The default size a log file can grow before it is rotated
protected static java.lang.String ENTRY
          The entry tag
protected static java.lang.String LINE_SEPARATOR
          The line separator used in the log output
static java.lang.String LOG_EXT
          The extension used for log files
static int LOG_SIZE_MIN
          The minimum size limit for log rotation
protected static java.lang.String MESSAGE
          The message tag
protected  boolean newSession
          Indicates if the next log message is part of a new session
protected  java.io.File outFile
          The File object to store messages.
static java.lang.String PROP_LOG_FILE_MAX
          The system property used to specify the maximim number of backup log files to use
static java.lang.String PROP_LOG_SIZE_MAX
          The system property used to specify size a log file can grow before it is rotated
protected static java.lang.String SESSION
          The session tag
protected static java.lang.String STACK
          The stacktrace tag
protected static java.lang.String SUBENTRY
          The sub-entry tag
protected static java.lang.String TAB_STRING
          The tab character used in the log output
protected  java.io.Writer writer
          The Writer to log messages to.
 
Fields inherited from interface org.eclipse.osgi.framework.log.FrameworkLog
SERVICE_PERFORMANCE
 
Constructor Summary
EclipseLog()
          Constructs an EclipseLog which uses System.err to write log messages to
EclipseLog(java.io.File outFile)
          Constructs an EclipseLog which uses the specified File to log messages to
EclipseLog(java.io.Writer writer)
          Constructs an EclipseLog which uses the specified Writer to log messages to
 
Method Summary
protected  boolean checkLogFileSize()
          Checks the log file size.
 void close()
           
protected  void closeFile()
          If a File is used to log messages to then the writer is closed.
protected  java.lang.String getDate(java.util.Date date)
          Returns a date string using the correct format for the log.
 java.io.File getFile()
           
protected  java.lang.String getSessionTimestamp()
          Returns the session timestamp.
protected  java.lang.String getStackTrace(java.lang.Throwable t)
          Returns a stacktrace string using the correct format for the log
 void log(FrameworkEvent frameworkEvent)
           
 void log(org.eclipse.osgi.framework.log.FrameworkLogEntry logEntry)
           
protected  java.io.Writer logForStream(java.io.OutputStream output)
          Returns a Writer for the given OutputStream
protected  void openFile()
          If a File is used to log messages to then the File opened and a Writer is created to log messages to.
protected  void readLogProperties()
          Reads the PROP_LOG_SIZE_MAX and PROP_LOG_FILE_MAX properties.
 void setConsoleLog(boolean consoleLog)
           
 void setFile(java.io.File newFile, boolean append)
           
 void setWriter(java.io.Writer newWriter, boolean append)
           
protected  void write(java.lang.String message)
          Writes the given message to the log.
protected  void writeArgs(java.lang.String header, java.lang.String[] args)
          Helper method for writing out argument arrays.
protected  void writeEntry(int depth, org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
          Writes the ENTRY or SUBENTRY header for an entry.
protected  void writeln()
          Writes a newline log.
protected  void writeln(java.lang.String s)
          Writes the given message to the log and a newline.
protected  void writeLog(int depth, org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
          Writes the log entry to the log using the specified depth.
protected  void writeMessage(org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
          Writes the MESSAGE header to the log for the given entry.
protected  void writeSession()
          Writes the session
protected  void writeSpace()
          Writes a space to the log.
protected  void writeStack(org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
          Writes the STACK header to the log for the given entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION

protected static final java.lang.String SESSION
The session tag

See Also:
Constant Field Values

ENTRY

protected static final java.lang.String ENTRY
The entry tag

See Also:
Constant Field Values

SUBENTRY

protected static final java.lang.String SUBENTRY
The sub-entry tag

See Also:
Constant Field Values

MESSAGE

protected static final java.lang.String MESSAGE
The message tag

See Also:
Constant Field Values

STACK

protected static final java.lang.String STACK
The stacktrace tag

See Also:
Constant Field Values

LINE_SEPARATOR

protected static final java.lang.String LINE_SEPARATOR
The line separator used in the log output


TAB_STRING

protected static final java.lang.String TAB_STRING
The tab character used in the log output

See Also:
Constant Field Values

DEFAULT_LOG_SIZE

public static final int DEFAULT_LOG_SIZE
The default size a log file can grow before it is rotated

See Also:
Constant Field Values

DEFAULT_LOG_FILES

public static final int DEFAULT_LOG_FILES
The default number of backup log files

See Also:
Constant Field Values

LOG_SIZE_MIN

public static final int LOG_SIZE_MIN
The minimum size limit for log rotation

See Also:
Constant Field Values

PROP_LOG_SIZE_MAX

public static final java.lang.String PROP_LOG_SIZE_MAX
The system property used to specify size a log file can grow before it is rotated

See Also:
Constant Field Values

PROP_LOG_FILE_MAX

public static final java.lang.String PROP_LOG_FILE_MAX
The system property used to specify the maximim number of backup log files to use

See Also:
Constant Field Values

LOG_EXT

public static final java.lang.String LOG_EXT
The extension used for log files

See Also:
Constant Field Values

BACKUP_MARK

public static final java.lang.String BACKUP_MARK
The extension markup to use for backup log files

See Also:
Constant Field Values

consoleLog

protected boolean consoleLog
Indicates if the console messages should be printed to the console (System.out)


newSession

protected boolean newSession
Indicates if the next log message is part of a new session


outFile

protected java.io.File outFile
The File object to store messages. This value may be null.


writer

protected java.io.Writer writer
The Writer to log messages to.

Constructor Detail

EclipseLog

public EclipseLog(java.io.File outFile)
Constructs an EclipseLog which uses the specified File to log messages to

Parameters:
outFile - a file to log messages to

EclipseLog

public EclipseLog(java.io.Writer writer)
Constructs an EclipseLog which uses the specified Writer to log messages to

Parameters:
writer - a writer to log messages to

EclipseLog

public EclipseLog()
Constructs an EclipseLog which uses System.err to write log messages to

Method Detail

writeArgs

protected void writeArgs(java.lang.String header,
                         java.lang.String[] args)
                  throws java.io.IOException
Helper method for writing out argument arrays.

Parameters:
header - the header
args - the list of arguments
Throws:
java.io.IOException

getSessionTimestamp

protected java.lang.String getSessionTimestamp()
Returns the session timestamp. This is the time the platform was started

Returns:
the session timestamp

writeSession

protected void writeSession()
                     throws java.io.IOException
Writes the session

Throws:
java.io.IOException - if an error occurs writing to the log

close

public void close()
Specified by:
close in interface org.eclipse.osgi.framework.log.FrameworkLog

openFile

protected void openFile()
If a File is used to log messages to then the File opened and a Writer is created to log messages to.


closeFile

protected void closeFile()
If a File is used to log messages to then the writer is closed.


log

public void log(FrameworkEvent frameworkEvent)
Specified by:
log in interface org.eclipse.osgi.framework.log.FrameworkLog

log

public void log(org.eclipse.osgi.framework.log.FrameworkLogEntry logEntry)
Specified by:
log in interface org.eclipse.osgi.framework.log.FrameworkLog

setWriter

public void setWriter(java.io.Writer newWriter,
                      boolean append)
Specified by:
setWriter in interface org.eclipse.osgi.framework.log.FrameworkLog

setFile

public void setFile(java.io.File newFile,
                    boolean append)
             throws java.io.IOException
Specified by:
setFile in interface org.eclipse.osgi.framework.log.FrameworkLog
Throws:
java.io.IOException

getFile

public java.io.File getFile()
Specified by:
getFile in interface org.eclipse.osgi.framework.log.FrameworkLog

setConsoleLog

public void setConsoleLog(boolean consoleLog)
Specified by:
setConsoleLog in interface org.eclipse.osgi.framework.log.FrameworkLog

getDate

protected java.lang.String getDate(java.util.Date date)
Returns a date string using the correct format for the log.

Parameters:
date - the Date to format
Returns:
a date string.

getStackTrace

protected java.lang.String getStackTrace(java.lang.Throwable t)
Returns a stacktrace string using the correct format for the log

Parameters:
t - the Throwable to get the stacktrace for
Returns:
a stacktrace string

logForStream

protected java.io.Writer logForStream(java.io.OutputStream output)
Returns a Writer for the given OutputStream

Parameters:
output - an OutputStream to use for the Writer
Returns:
a Writer for the given OutputStream

writeLog

protected void writeLog(int depth,
                        org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
                 throws java.io.IOException
Writes the log entry to the log using the specified depth. A depth value of 0 idicates that the log entry is the root entry. Any value greater than 0 indicates a sub-entry.

Parameters:
depth - the depth of th entry
entry - the entry to log
Throws:
java.io.IOException - if any error occurs writing to the log

writeEntry

protected void writeEntry(int depth,
                          org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
                   throws java.io.IOException
Writes the ENTRY or SUBENTRY header for an entry. A depth value of 0 idicates that the log entry is the root entry. Any value greater than 0 indicates a sub-entry.

Parameters:
depth - the depth of th entry
entry - the entry to write the header for
Throws:
java.io.IOException - if any error occurs writing to the log

writeMessage

protected void writeMessage(org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
                     throws java.io.IOException
Writes the MESSAGE header to the log for the given entry.

Parameters:
entry - the entry to write the message for
Throws:
java.io.IOException - if any error occurs writing to the log

writeStack

protected void writeStack(org.eclipse.osgi.framework.log.FrameworkLogEntry entry)
                   throws java.io.IOException
Writes the STACK header to the log for the given entry.

Parameters:
entry - the entry to write the stacktrace for
Throws:
java.io.IOException - if any error occurs writing to the log

write

protected void write(java.lang.String message)
              throws java.io.IOException
Writes the given message to the log.

Parameters:
message - the message
Throws:
java.io.IOException - if any error occurs writing to the log

writeln

protected void writeln(java.lang.String s)
                throws java.io.IOException
Writes the given message to the log and a newline.

Parameters:
s - the message
Throws:
java.io.IOException - if any error occurs writing to the log

writeln

protected void writeln()
                throws java.io.IOException
Writes a newline log.

Throws:
java.io.IOException - if any error occurs writing to the log

writeSpace

protected void writeSpace()
                   throws java.io.IOException
Writes a space to the log.

Throws:
java.io.IOException - if any error occurs writing to the log

checkLogFileSize

protected boolean checkLogFileSize()
Checks the log file size. If the log file size reaches the limit then the log is rotated

Returns:
false if an error occured trying to rotate the log

readLogProperties

protected void readLogProperties()
Reads the PROP_LOG_SIZE_MAX and PROP_LOG_FILE_MAX properties.