org.almendra.commons.util.logging
Class Logger

java.lang.Object
  extended by org.almendra.commons.util.logging.Logger
All Implemented Interfaces:
ILogPrinter
Direct Known Subclasses:
Logger, NullLogger

public class Logger
extends java.lang.Object
implements ILogPrinter

Author:
Oliver Plohmann

Field Summary
protected  boolean bufferUnwrittenMsgs
           
protected  java.util.List children
           
static int DEBUG
           
static int ERROR
           
static int EXCEPTION
           
static int FATAL
           
static int FREE_TEXT
           
static int INFO
           
protected  java.lang.String[] levelLabels
           
protected  java.util.List listeners
           
protected  long localLogFileMaxSize
           
protected  boolean localLogFileMaxSizeChecked
           
protected  java.lang.String localLogFileName
           
protected  java.io.FileWriter localLogWriter
           
protected  EDU.oswego.cs.dl.util.concurrent.ReentrantLock lock
          Lock access to log writer when it is being changed since there are several threads that write to the log which could cause race conditions.
protected  java.util.List logBuffer
           
protected  ILogPrinter logPrinter
           
static java.lang.String NewSession
           
protected  Logger parent
           
protected  java.util.HashSet registeredEvents
           
protected  java.util.HashSet subscribedEvents
           
static int WARNING
           
 
Constructor Summary
Logger()
           
Logger(boolean bufferUnwrittenMsgs, long localLogFileMaxSize)
           
Logger(ILogPrinter logPrinter)
           
Logger(ILogPrinter logPrinter, boolean bufferUnwrittenMsgs)
           
 
Method Summary
 void addListener(ILogListener listener)
           
 boolean changeLocalLogFileName(java.lang.String newFilePathName)
           
protected  void checkLocalLogMaxSize(java.lang.String filePathName)
           
 void close()
           
protected  boolean closeLocalLogWriter()
           
 void debug(LogEntry entry)
           
 void debug(java.lang.String logEntryLabel)
           
 void deregisterForEvents(java.util.List stringsOfEventNames)
           
 void error(LogEntry entry)
           
 void error(java.lang.String logEntryLabel)
           
 void exception(LogEntry entry)
           
 void fatal(LogEntry entry)
           
 void fatal(java.lang.String logEntryLabel)
           
 void fatalText(java.lang.String text)
           
 void freeText(LogEntry entry)
           
 void freeText(java.lang.String freeText)
           
static Logger getChildLogger(Logger logger)
          Returns a child logger.
protected static Logger getChildLogger(Logger parentLogger, Logger childLogger)
          Helper method to allow for logger to be filled from subclass with values defined in this class.
protected  LogEntry getLogEntry(java.lang.String entryString)
           
 LogEntry getNewLogEntry()
           
 LoggerAccessor getPublicAccessor()
           
 void info(LogEntry entry)
           
 void info(java.lang.String logEntryLabel)
           
protected  void init()
           
 boolean isRegistered(java.lang.String eventName)
           
 boolean isSubscribed(java.lang.String eventName)
           
protected  void log(LogEntry entry)
           
 void log(java.lang.String msg)
          Write the log string msg to the output device.
protected  void logLocalWriter(java.lang.String msg)
           
protected  void openLocalLogWriter()
           
protected  void primLog(LogEntry entry)
           
protected  java.lang.String[] primReadBuffer()
           
protected  java.lang.String primReadNextLogEntry(java.io.FileReader reader)
           
protected  java.lang.String[] readBuffer()
           
 void registerForEvents(java.util.List stringsOfEventNames)
           
 boolean removeListener(ILogListener listener)
           
 boolean removeSubscription(java.lang.String eventName)
           
protected  void sendToListeners(LogEntry entry)
           
 void setLocalLogFileName(java.lang.String filePathName)
           
 void subscribeForEvents(java.util.List stringsOfEventNames)
           
 void unsubscribeForEvents(java.util.List stringsOfEventNames)
           
 void warn(LogEntry entry)
           
 void warn(java.lang.String logEntryLabel)
           
protected  void writeBuffer()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

public static final int DEBUG
See Also:
Constant Field Values

ERROR

public static final int ERROR
See Also:
Constant Field Values

FATAL

public static final int FATAL
See Also:
Constant Field Values

INFO

public static final int INFO
See Also:
Constant Field Values

WARNING

public static final int WARNING
See Also:
Constant Field Values

EXCEPTION

public static final int EXCEPTION
See Also:
Constant Field Values

FREE_TEXT

public static final int FREE_TEXT
See Also:
Constant Field Values

NewSession

public static final java.lang.String NewSession
See Also:
Constant Field Values

parent

protected Logger parent

localLogFileMaxSize

protected long localLogFileMaxSize

localLogFileMaxSizeChecked

protected boolean localLogFileMaxSizeChecked

logPrinter

protected ILogPrinter logPrinter

levelLabels

protected java.lang.String[] levelLabels

registeredEvents

protected java.util.HashSet registeredEvents

subscribedEvents

protected java.util.HashSet subscribedEvents

children

protected java.util.List children

localLogFileName

protected java.lang.String localLogFileName

localLogWriter

protected java.io.FileWriter localLogWriter

bufferUnwrittenMsgs

protected boolean bufferUnwrittenMsgs

logBuffer

protected java.util.List logBuffer

listeners

protected java.util.List listeners

lock

protected EDU.oswego.cs.dl.util.concurrent.ReentrantLock lock
Lock access to log writer when it is being changed since there are several threads that write to the log which could cause race conditions.

Constructor Detail

Logger

public Logger()

Logger

public Logger(boolean bufferUnwrittenMsgs,
              long localLogFileMaxSize)

Logger

public Logger(ILogPrinter logPrinter)

Logger

public Logger(ILogPrinter logPrinter,
              boolean bufferUnwrittenMsgs)
Method Detail

debug

public void debug(LogEntry entry)

debug

public void debug(java.lang.String logEntryLabel)

exception

public void exception(LogEntry entry)

freeText

public void freeText(LogEntry entry)

freeText

public void freeText(java.lang.String freeText)

info

public void info(LogEntry entry)

info

public void info(java.lang.String logEntryLabel)

warn

public void warn(java.lang.String logEntryLabel)

warn

public void warn(LogEntry entry)

error

public void error(java.lang.String logEntryLabel)

error

public void error(LogEntry entry)

fatal

public void fatal(java.lang.String logEntryLabel)

fatalText

public void fatalText(java.lang.String text)

fatal

public void fatal(LogEntry entry)

init

protected void init()

log

protected void log(LogEntry entry)

sendToListeners

protected void sendToListeners(LogEntry entry)
Parameters:
entry -

primLog

protected void primLog(LogEntry entry)

isRegistered

public boolean isRegistered(java.lang.String eventName)

isSubscribed

public boolean isSubscribed(java.lang.String eventName)

subscribeForEvents

public void subscribeForEvents(java.util.List stringsOfEventNames)

unsubscribeForEvents

public void unsubscribeForEvents(java.util.List stringsOfEventNames)

registerForEvents

public void registerForEvents(java.util.List stringsOfEventNames)

deregisterForEvents

public void deregisterForEvents(java.util.List stringsOfEventNames)

getPublicAccessor

public LoggerAccessor getPublicAccessor()

log

public void log(java.lang.String msg)
Description copied from interface: ILogPrinter
Write the log string msg to the output device.

Specified by:
log in interface ILogPrinter

logLocalWriter

protected void logLocalWriter(java.lang.String msg)

getNewLogEntry

public LogEntry getNewLogEntry()
Returns:
Return a new LogEntry object.

getChildLogger

public static Logger getChildLogger(Logger logger)
Returns a child logger. A child logger inherits all the attribute values of the parent logger, but new events can be registered without affecting the parent logger.

Parameters:
logger - the parent logger
Returns:
the child logger

getChildLogger

protected static Logger getChildLogger(Logger parentLogger,
                                       Logger childLogger)
Helper method to allow for logger to be filled from subclass with values defined in this class.

Parameters:
parentLogger -
childLogger -
Returns:

setLocalLogFileName

public void setLocalLogFileName(java.lang.String filePathName)
                         throws java.io.IOException
Throws:
java.io.IOException

checkLocalLogMaxSize

protected void checkLocalLogMaxSize(java.lang.String filePathName)
Parameters:
filePathName -

writeBuffer

protected void writeBuffer()
                    throws java.io.IOException
Throws:
java.io.IOException

addListener

public void addListener(ILogListener listener)

getLogEntry

protected LogEntry getLogEntry(java.lang.String entryString)
Parameters:
entry -
Returns:

readBuffer

protected java.lang.String[] readBuffer()
Returns:

primReadBuffer

protected java.lang.String[] primReadBuffer()

primReadNextLogEntry

protected java.lang.String primReadNextLogEntry(java.io.FileReader reader)
                                         throws java.io.IOException
Throws:
java.io.IOException

closeLocalLogWriter

protected boolean closeLocalLogWriter()

openLocalLogWriter

protected void openLocalLogWriter()
                           throws java.io.IOException
Throws:
java.io.IOException

removeListener

public boolean removeListener(ILogListener listener)

removeSubscription

public boolean removeSubscription(java.lang.String eventName)

changeLocalLogFileName

public boolean changeLocalLogFileName(java.lang.String newFilePathName)
                               throws java.io.IOException
Throws:
java.io.IOException

close

public void close()