TwilightMinds.Log
Class LogManager

java.lang.Object
  |
  +--TwilightMinds.Log.LogManager

public abstract class LogManager
extends java.lang.Object

The LogManager class keeps track of any aribitrary Log objects and allows easily formatted and synchronized recording of LogEntry objects of various EntryTypes to any of the Logs. All objects of a given EntryType are sent to a single Log of choice.

The LogManager class can also enable and disable logging for individual Logs or EntryTypes.

Use the static LogManager methods to set up your Logs and EntryTypes when your application initializes, and then you can use the static writeEntry() methods throughout your application.

Author: Reason
Last Modified: 11/23/00

------------------------------------------------

Copyright (C) 2000 Twilight Minds. All rights reserved.

This Java package is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this package; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Alternatively, a copy can be obtained from the Twilight Minds web site: http://www.twilightminds.com/GNU-LGPL.html

Twilight Minds Design Group http://www.twilightminds.com/


Method Summary
static void addLog(Log log)
          Add a new Log to those managed by the LogManager.
static void addLogAndEntryTypes(Log log, java.lang.String[] entrytypenames)
          Add a new Log to those managed by the LogManager.
static java.lang.String[] getEntryTypeNames()
          Return an array of all EntryType names currently used in the LogManager.
static Log getLog(java.lang.String logname)
          Return the Log with this name, or null if no such Log exists.
static java.lang.String[] getLogNames()
          Return an array of the Log names currently in use in the LogManager.
static Log[] getLogs()
          Return an array of the Logs currently in use in the LogManager.
static void removeEntryType(java.lang.String entrytypename)
          Remove the EntryType with this name.
static java.lang.String[] removeLog(Log log)
          Remove this Log from those managed by the LogManager.
static java.lang.String sentToLog(java.lang.String entrytypename)
          Return the name of the Log that LogEntries of this EntryType are sent to.
static void setEntryType(java.lang.String entrytypename, java.lang.String logname)
          Add an EntryType that writes to the Log with the given logname.
static void setEntryType(java.lang.String entrytypename, java.lang.String logname, boolean islogging)
          Add an EntryType that writes to the Log with the given logname.
static void startAllEntryTypesLogging()
          Set LogEntries of all EntryTypes to be logged.
static void startAllLogs()
          Start all Logs accepting and recording log entries.
static void startEntryTypeLogging(java.lang.String entrytypename)
          Stop LogEntries with this EntryType from being logged.
static void startLog(java.lang.String logname)
          Start this Log accepting LogEntries.
static void stopAllEntryTypesLogging()
          Stop LogEntries of all EntryTypes from being logged.
static void stopAllLogs()
          Stop all Logs from accepting log entries.
static void stopEntryTypeLogging(java.lang.String entrytypename)
          Stop logging LogEntries of this EntryType.
static void stopLog(java.lang.String logname)
          Stop this Log from accepting LogEntries.
static boolean writeEntry(java.lang.String entrytypename, java.lang.String entry)
          Write an event string as a given EntryType.
static boolean writeEntry(java.lang.String entrytypename, java.lang.String entry, java.lang.Exception exception)
          Write an event string and exception as a given EntryType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addLog

public static void addLog(Log log)
                   throws LogException
Add a new Log to those managed by the LogManager. All Logs must have unique names; an exception is thrown if a Log by this name already exists.

addLogAndEntryTypes

public static void addLogAndEntryTypes(Log log,
                                       java.lang.String[] entrytypenames)
                                throws LogException
Add a new Log to those managed by the LogManager. Also add new EntryTypes that are associated with this Log. All Logs and EntryTypes must have unique names; an exception is thrown if a Log by this name already exists or if any of the EntryType names already exist. Any duplications mean that neither the Log nor the EntryTypes will be entered.

The new EntryTypes will be set to log.

removeLog

public static java.lang.String[] removeLog(Log log)
Remove this Log from those managed by the LogManager. This also removes the EntryTypes that wrote to this Log. The names of these removed EntryType objects are returned as an array. The array will be zero-length if no EntryTypes wrote to this Log.

getLogNames

public static java.lang.String[] getLogNames()
Return an array of the Log names currently in use in the LogManager.

getLogs

public static Log[] getLogs()
Return an array of the Logs currently in use in the LogManager.

getLog

public static Log getLog(java.lang.String logname)
Return the Log with this name, or null if no such Log exists.

setEntryType

public static void setEntryType(java.lang.String entrytypename,
                                java.lang.String logname)
                         throws LogException
Add an EntryType that writes to the Log with the given logname. An exception is thrown if no Log by this name exists. If an EntryType with this name already exists, it will be replaced with a new EntryType that writes to this Log.

The new or reset EntryType will have logging set on.

setEntryType

public static void setEntryType(java.lang.String entrytypename,
                                java.lang.String logname,
                                boolean islogging)
                         throws LogException
Add an EntryType that writes to the Log with the given logname. An exception is thrown if no Log by this name exists. If an EntryType with this name already exists, it will be replaced with a new EntryType that writes to this Log.

removeEntryType

public static void removeEntryType(java.lang.String entrytypename)
Remove the EntryType with this name.

getEntryTypeNames

public static java.lang.String[] getEntryTypeNames()
Return an array of all EntryType names currently used in the LogManager. A zero-length array is returned if there are no EntryTypes.

sentToLog

public static java.lang.String sentToLog(java.lang.String entrytypename)
                                  throws LogException
Return the name of the Log that LogEntries of this EntryType are sent to. Throw an exception if no such EntryType exists.

startAllEntryTypesLogging

public static void startAllEntryTypesLogging()
Set LogEntries of all EntryTypes to be logged.

stopAllEntryTypesLogging

public static void stopAllEntryTypesLogging()
Stop LogEntries of all EntryTypes from being logged.

startEntryTypeLogging

public static void startEntryTypeLogging(java.lang.String entrytypename)
                                  throws LogException
Stop LogEntries with this EntryType from being logged. An exception is thrown if no EntryType by this name exists.

stopEntryTypeLogging

public static void stopEntryTypeLogging(java.lang.String entrytypename)
                                 throws LogException
Stop logging LogEntries of this EntryType. An exception is thrown if no EntryType by this name exists.

startAllLogs

public static void startAllLogs()
Start all Logs accepting and recording log entries.

stopAllLogs

public static void stopAllLogs()
Stop all Logs from accepting log entries. Existing entries in the Log queues will still be recorded.

startLog

public static void startLog(java.lang.String logname)
                     throws LogException
Start this Log accepting LogEntries. An exception is thrown if no Log by this name exists.

stopLog

public static void stopLog(java.lang.String logname)
                    throws LogException
Stop this Log from accepting LogEntries. Existing entries in the Log queues will still be recorded. An exception is thrown if no Log by this name exists.

writeEntry

public static boolean writeEntry(java.lang.String entrytypename,
                                 java.lang.String entry,
                                 java.lang.Exception exception)
Write an event string and exception as a given EntryType. This method will write to System.err if a bad EntryType is selected or if creating a new LogEntry otherwise fails.

This method will return true if this entry was accepted by a Log, or false if the destination Log is not currently accepting entries or if the LogEntry is of an EntryType that is not currently being logged.

writeEntry

public static boolean writeEntry(java.lang.String entrytypename,
                                 java.lang.String entry)
Write an event string as a given EntryType. This method will write to System.err if a bad EntryType is selected.

This method will return true if this entry was accepted by a Log, or false if the destination Log is not currently accepting entries or if the LogEntry is of an EntryType that is not currently being logged.