marf.util
Class Logger

java.lang.Object
  extended by java.lang.Thread
      extended by marf.util.BaseThread
          extended by marf.util.Logger
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
Debug

public class Logger
extends BaseThread

MARF Runnable Logging Facility.

All methods are properly synchronized should multiple threads access the same logger.

$Id: Logger.java,v 1.10 2007/12/23 06:29:47 mokhov Exp $

Since:
0.3.0.2
Version:
$Revision: 1.10 $
Author:
Serguei Mokhov

Nested Class Summary
 class Logger.LogPrintStream
          Our own LogPrintStream for log delivery.
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  boolean bAvailable
          Indicates if logging is available.
protected  boolean bNoTimestamp
          If set to true, no timestamp is issued with a message.
protected  int iLogDirection
          Indicates where the log should go.
static int LOG_STDERR_TO_FILE
          Indicates to redirect STDERR to a file.
static int LOG_STDOUT_STDERR_TO_FILE
          Indicates to redirect STDOUT and STDERR to a file.
static int LOG_STDOUT_TO_FILE
          Indicates to redirect STDOUT to a file.
static int LOG_TO_FILE_STDOUT_STDERR
          Indicates to emit messages to three destinations: a file, STDOUT, and STDERR.
protected  Logger.LogPrintStream oLog
          Underlying LogPrintStream for messages and files.
protected  java.lang.String strFilename
          Redirection filename.
protected  java.lang.String strLogMessage
          Log message to log.
 
Fields inherited from class marf.util.BaseThread
iTID, oTarget, siNextTID
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Logger(java.lang.String pstrFilename)
          Takes the log filename and sets the direction to log to the file, STDERR, and STDOUT.
Logger(java.lang.String pstrFilename, int piLogDirection)
          Creates a logger with output filename and desired direction.
Logger(java.lang.String pstrFilename, int piLogDirection, boolean pbTimestampRequired)
          Creates a logger with output filename, desired direction, and possibly a timestamp.
 
Method Summary
 void enableTimestamp(boolean pbEnable)
          Enables or disables timestamps.
 int getLogDirection()
           
 java.lang.String getLogFilename()
           
 Logger.LogPrintStream getLogPrintStream()
          Returns references to the internal log stream.
static java.lang.String getMARFSourceCodeRevision()
          Returns source code revision information.
 boolean isTimestampEnabled()
          Verifies if the timestamps are enabled.
 void setLogDirection(int piLogDirection)
          Sets new log direction.
 void setLogFilename(java.lang.String pstrFilename)
           
 void setLogPrintStream(Logger.LogPrintStream poLogPrintStream)
          Allows to set new log stream.
 
Methods inherited from class marf.util.BaseThread
getNextTID, getTarget, getTID
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG_TO_FILE_STDOUT_STDERR

public static final int LOG_TO_FILE_STDOUT_STDERR
Indicates to emit messages to three destinations: a file, STDOUT, and STDERR.

See Also:
Constant Field Values

LOG_STDOUT_TO_FILE

public static final int LOG_STDOUT_TO_FILE
Indicates to redirect STDOUT to a file.

See Also:
Constant Field Values

LOG_STDERR_TO_FILE

public static final int LOG_STDERR_TO_FILE
Indicates to redirect STDERR to a file.

See Also:
Constant Field Values

LOG_STDOUT_STDERR_TO_FILE

public static final int LOG_STDOUT_STDERR_TO_FILE
Indicates to redirect STDOUT and STDERR to a file.

See Also:
Constant Field Values

bNoTimestamp

protected boolean bNoTimestamp
If set to true, no timestamp is issued with a message.


strFilename

protected java.lang.String strFilename
Redirection filename.


bAvailable

protected boolean bAvailable
Indicates if logging is available.


oLog

protected Logger.LogPrintStream oLog
Underlying LogPrintStream for messages and files.


strLogMessage

protected java.lang.String strLogMessage
Log message to log.


iLogDirection

protected int iLogDirection
Indicates where the log should go. See the LOG_* constants for possible directions.

See Also:
LOG_TO_FILE_STDOUT_STDERR, LOG_STDOUT_TO_FILE, LOG_STDERR_TO_FILE, LOG_STDOUT_STDERR_TO_FILE
Constructor Detail

Logger

public Logger(java.lang.String pstrFilename)
       throws java.lang.Exception
Takes the log filename and sets the direction to log to the file, STDERR, and STDOUT.

Parameters:
pstrFilename - desired log filename
Throws:
java.lang.Exception

Logger

public Logger(java.lang.String pstrFilename,
              int piLogDirection)
       throws java.lang.Exception
Creates a logger with output filename and desired direction. Timestamps are always added.

Parameters:
pstrFilename - desired log filename
piLogDirection - desired logging direction
Throws:
java.lang.Exception
See Also:
LOG_TO_FILE_STDOUT_STDERR, LOG_STDOUT_TO_FILE, LOG_STDERR_TO_FILE, LOG_STDOUT_STDERR_TO_FILE

Logger

public Logger(java.lang.String pstrFilename,
              int piLogDirection,
              boolean pbTimestampRequired)
       throws java.lang.Exception
Creates a logger with output filename, desired direction, and possibly a timestamp.

Parameters:
pstrFilename - desired log filename
piLogDirection - desired logging direction
pbTimestampRequired - true if a timestamp desired in logs
Throws:
java.lang.Exception
See Also:
LOG_TO_FILE_STDOUT_STDERR, LOG_STDOUT_TO_FILE, LOG_STDERR_TO_FILE, LOG_STDOUT_STDERR_TO_FILE
Method Detail

isTimestampEnabled

public boolean isTimestampEnabled()
Verifies if the timestamps are enabled.

Returns:
Returns the bNoTimestamp.

enableTimestamp

public void enableTimestamp(boolean pbEnable)
Enables or disables timestamps.

Parameters:
pbEnable - true to enable timestamping

getLogDirection

public int getLogDirection()
Returns:
returns the log direction.

setLogDirection

public void setLogDirection(int piLogDirection)
Sets new log direction.

Parameters:
piLogDirection - The iLogDirection to set.
Throws:
java.lang.IllegalArgumentException - if the direction parameter is out of range

getLogPrintStream

public Logger.LogPrintStream getLogPrintStream()
Returns references to the internal log stream.

Returns:
LogPrintStream reference

setLogPrintStream

public void setLogPrintStream(Logger.LogPrintStream poLogPrintStream)
Allows to set new log stream.

Parameters:
poLogPrintStream - the new stream to set.

getLogFilename

public java.lang.String getLogFilename()
Returns:
returns the log filename.

setLogFilename

public void setLogFilename(java.lang.String pstrFilename)
Parameters:
pstrFilename - the log filename to set.

getMARFSourceCodeRevision

public static java.lang.String getMARFSourceCodeRevision()
Returns source code revision information.

Returns:
revision string


SourceForge Logo