org.mortbay.util
Class WriterLogSink

java.lang.Object
  |
  +--org.mortbay.util.WriterLogSink
All Implemented Interfaces:
LifeCycle, LogSink
Direct Known Subclasses:
FileLogSink

public class WriterLogSink
extends java.lang.Object
implements LogSink

A Log sink. This class represents both a concrete or abstract sink of Log data. The default implementation logs to a PrintWriter, but derived implementations may log to files, syslog, or other logging APIs. If a logFilename is specified, output is sent to that file. If the filename contains "yyyy_mm_dd", the log file date format is used to create the actual filename and the log file is rolled over at local midnight. If append is set, existing logfiles are appended to, otherwise a backup is created with a timestamp. Dated log files are deleted after retain days.

If the property LOG_DATE_FORMAT is set, then it is interpreted as a format string for java.text.SimpleDateFormat and used to format the log timestamps. Note: The character '+' is replaced with space in the date format string. Default value: HH:mm:ss.SSS

If LOG_TIMEZONE is set, it is used to set the timezone of the log date format, otherwise GMT is used.

If LOG_FILE_BACKUP_FORMAT is set, it is used as a format string for java.text.SimpleDateFormat and used to suffix the existing log file when it is backed up - log files are backed up when this class starts and finds the log file already exists and append is set to false (append is on by default, so this only needs to be overridden if append is turned off). Default value: HHmmssSSS

If LOG_FILE_RETAIN_DAYS is set, it is used to set the number of days after which old log files will be deleted. Default: 31

If LOG_FILE_DATE_FORMAT is set, it is used as a format string for java.text.SimpleDateFormat and used to format the date part of the log file name. Default value: yyyy_MM_dd

Version:
$Id: WriterLogSink.java,v 1.1 2001/09/02 01:13:09 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
Log

Field Summary
static char OPT_LABEL
           
static char OPT_ONELINE
           
static char OPT_STACKSIZE
           
static char OPT_STACKTRACE
           
static char OPT_TAG
           
static char OPT_TIMESTAMP
           
 
Constructor Summary
WriterLogSink()
          Constructor.
WriterLogSink(java.io.PrintWriter out)
          Constructor.
WriterLogSink(java.lang.String filename)
           
 
Method Summary
 void destroy()
          Destroy the LifeCycle.
 java.lang.String getFilename()
           
 boolean getFlushOn()
           
 java.lang.String getLogDateFormat()
           
 java.lang.String getLogTimezone()
           
 java.lang.String getOptions()
           
 int getRetainDays()
           
 java.io.PrintWriter getWriter()
           
 boolean isAppend()
           
 boolean isDestroyed()
           
 boolean isLogLabels()
           
 boolean isLogOneLine()
           
 boolean isLogStackSize()
           
 boolean isLogStackTrace()
           
 boolean isLogTags()
           
 boolean isLogTimeStamps()
           
 boolean isStarted()
           
 void log(java.lang.String formattedLog)
          Log a message.
 void log(java.lang.String tag, java.lang.Object msg, Frame frame, long time)
          Log a message.
 void setAppend(boolean a)
           
 void setFilename(java.lang.String filename)
           
 void setFlushOn(boolean on)
           
 void setLogDateFormat(java.lang.String logDateFormat)
           
 void setLogLabels(boolean logLabels)
           
 void setLogOneLine(boolean logOneLine)
           
 void setLogStackSize(boolean logStackSize)
           
 void setLogStackTrace(boolean logStackTrace)
           
 void setLogTags(boolean logTags)
           
 void setLogTimeStamps(boolean logTimeStamps)
           
 void setLogTimezone(java.lang.String logTimezone)
           
 void setOptions(boolean logTimeStamps, boolean logLabels, boolean logTags, boolean logStackSize, boolean logStackTrace, boolean logOneLine)
          Set the log options.
 void setOptions(java.lang.String logOptions)
          Set the log options.
 void setRetainDays(int retainDays)
           
 void setWriter(java.io.PrintWriter out)
           
 void start()
          Stop a log sink.
 void stop()
          Stop a log sink.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPT_TIMESTAMP

public static final char OPT_TIMESTAMP

OPT_LABEL

public static final char OPT_LABEL

OPT_TAG

public static final char OPT_TAG

OPT_STACKSIZE

public static final char OPT_STACKSIZE

OPT_STACKTRACE

public static final char OPT_STACKTRACE

OPT_ONELINE

public static final char OPT_ONELINE
Constructor Detail

WriterLogSink

public WriterLogSink()
              throws java.io.IOException
Constructor.

WriterLogSink

public WriterLogSink(java.io.PrintWriter out)
Constructor.
Parameters:
out -  

WriterLogSink

public WriterLogSink(java.lang.String filename)
              throws java.io.IOException
Method Detail

setOptions

public void setOptions(java.lang.String logOptions)
Description copied from interface: LogSink
Set the log options.
Specified by:
setOptions in interface LogSink
Following copied from interface: org.mortbay.util.LogSink
Parameters:
logOptions - A string of characters as defined for the LOG_OPTIONS system parameter.

getOptions

public java.lang.String getOptions()
Specified by:
getOptions in interface LogSink

setOptions

public void setOptions(boolean logTimeStamps,
                       boolean logLabels,
                       boolean logTags,
                       boolean logStackSize,
                       boolean logStackTrace,
                       boolean logOneLine)
Set the log options.
Parameters:
logOptions - A string of characters as defined for the LOG_OPTIONS system parameter.

getLogDateFormat

public java.lang.String getLogDateFormat()

setLogDateFormat

public void setLogDateFormat(java.lang.String logDateFormat)

getLogTimezone

public java.lang.String getLogTimezone()

setLogTimezone

public void setLogTimezone(java.lang.String logTimezone)

isLogTimeStamps

public boolean isLogTimeStamps()

setLogTimeStamps

public void setLogTimeStamps(boolean logTimeStamps)

isLogLabels

public boolean isLogLabels()

setLogLabels

public void setLogLabels(boolean logLabels)

isLogTags

public boolean isLogTags()

setLogTags

public void setLogTags(boolean logTags)

isLogStackSize

public boolean isLogStackSize()

setLogStackSize

public void setLogStackSize(boolean logStackSize)

isLogStackTrace

public boolean isLogStackTrace()

setLogStackTrace

public void setLogStackTrace(boolean logStackTrace)

isLogOneLine

public boolean isLogOneLine()

setLogOneLine

public void setLogOneLine(boolean logOneLine)

isAppend

public boolean isAppend()

setAppend

public void setAppend(boolean a)

setWriter

public void setWriter(java.io.PrintWriter out)

getWriter

public java.io.PrintWriter getWriter()

setFilename

public void setFilename(java.lang.String filename)

getFilename

public java.lang.String getFilename()

getRetainDays

public int getRetainDays()

setRetainDays

public void setRetainDays(int retainDays)

setFlushOn

public void setFlushOn(boolean on)
Parameters:
on - If true, log is flushed on every log.

getFlushOn

public boolean getFlushOn()
Returns:
true, log is flushed on every log.

log

public void log(java.lang.String tag,
                java.lang.Object msg,
                Frame frame,
                long time)
Log a message. This method formats the log information as a string and calls log(String). It should only be specialized by a derived implementation if the format of the logged messages is to be changed.
Specified by:
log in interface LogSink
Parameters:
tag - Tag for type of log
msg - The message
frame - The frame that generated the message.
time - The time stamp of the message.

log

public void log(java.lang.String formattedLog)
Log a message. The formatted log string is written to the log sink. The default implementation writes the message to a PrintWriter.
Specified by:
log in interface LogSink
Parameters:
formattedLog -  

start

public void start()
Stop a log sink. The default implementation does nothing
Specified by:
start in interface LifeCycle
Following copied from interface: org.mortbay.util.LifeCycle
Throws:
java.lang.Exception - An arbitrary exception may be thrown.

stop

public void stop()
Stop a log sink. An opportunity for subclasses to clean up. The default implementation does nothing
Specified by:
stop in interface LifeCycle

isStarted

public boolean isStarted()
Specified by:
isStarted in interface LifeCycle
Following copied from interface: org.mortbay.util.LifeCycle
Returns:
True if the LifeCycle has been started.

destroy

public void destroy()
Description copied from interface: LifeCycle
Destroy the LifeCycle. Activities are terminated.
Specified by:
destroy in interface LifeCycle

isDestroyed

public boolean isDestroyed()
Specified by:
isDestroyed in interface LifeCycle
Following copied from interface: org.mortbay.util.LifeCycle
Returns:
True if the LifeCycle has been destroyed.


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.