org.openptk.logging
Class Logger

java.lang.Object
  extended by org.openptk.logging.Logger

public class Logger
extends java.lang.Object

Singleton class which will hold objects that are available globally to the OpenPTK Framework.

The objects that are managed include:

The usage of the Logger is intended to be extremely simple to use. At any place withing some Java code, the developer should not be required to set anything up. The only thing they need to do is simply call the log....() message on the Logger. See example below:

 import org.openptk.logging.Logger;

  ...
 Logger.logInfo("HelloWorld!");
 ...
 

By default, the logger is initialized with an OpenPTK SysoutLogger() which simply emits messages to the standard SYSOUT for that platform. Other optional Loggers available with OpenPTK include:

An example of setting up a new CustomLogger is shown below:

 import org.openptk.logging.Logger;
 import org.openptk.logging.LoggingIF;
 import ....CustomLogger;             // Written by developer (must implement LoggingIF)

 ...
 {
    ...
    LoggingIF  myLogger = new CustomLogger(...);
 
    Logger.setLogger(myLogger);
 
    Logger.logInfo("HelloWorld! Using the new CustomLogger()");
 }
 

Author:
Terry Sigle

Field Summary
static java.lang.String DEFAULT
           
 
Method Summary
 java.lang.Object clone()
          Since this is a singleton class, ensure that it cannot be cloned by overridding the Object.clone() method, instead throwing a CloneNotSupportedException.
static LoggingIF getLogger()
          Getter for the Logger instance
static LoggingIF getLogger(java.lang.String logId)
          Getter for the logger instance
static void log(LoggingLevel logLevel, java.lang.String msg)
          Log a message to DEFAULT Logger at a given LoggingLevel.
static void log(java.lang.String msg)
          Log a message to DEFAULT Logger.
static void log(java.lang.String logId, LoggingLevel logLevel, java.lang.String msg)
          Log a message to a particular Logger at a given LoggingLevel.
static void log(java.lang.String logId, java.lang.String msg)
          Log a message to a particular Logger.
static void logError(java.lang.String msg)
          Log an ERROR message to DEFAULT Logger.
static void logError(java.lang.String logId, java.lang.String msg)
          Log an ERROR message to a particular Logger.
static void logInfo(java.lang.String msg)
          Log an INFO message to DEFAULT Logger.
static void logInfo(java.lang.String logId, java.lang.String msg)
          Log an INFO message to a particular Logger.
static void logWarning(java.lang.String msg)
          Log an WARNING message to DEFAULT Logger.
static void logWarning(java.lang.String logId, java.lang.String msg)
          Log an WARNING message to a particular Logger.
static void setLogger(LoggingIF log)
          Add the logging instance to the Logger using a particular name to refer to it, and subsequently get or log messages to later.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final java.lang.String DEFAULT
See Also:
Constant Field Values
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Since this is a singleton class, ensure that it cannot be cloned by overridding the Object.clone() method, instead throwing a CloneNotSupportedException.

Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

getLogger

public static LoggingIF getLogger()
Getter for the Logger instance


getLogger

public static LoggingIF getLogger(java.lang.String logId)
Getter for the logger instance


log

public static void log(LoggingLevel logLevel,
                       java.lang.String msg)
Log a message to DEFAULT Logger at a given LoggingLevel.

Parameters:
logLevel - LoggingLevel to log the message to
msg - String message to be logged

log

public static void log(java.lang.String msg)
Log a message to DEFAULT Logger.

Parameters:
msg - String message to be logged

log

public static void log(java.lang.String logId,
                       LoggingLevel logLevel,
                       java.lang.String msg)
Log a message to a particular Logger at a given LoggingLevel.

Parameters:
logId - Name of the Logger to log message to
logLevel - LoggingLevel to log the message to
msg - String message to be logged

log

public static void log(java.lang.String logId,
                       java.lang.String msg)
Log a message to a particular Logger. This is a helper method to call logIfo().

Parameters:
logId - Name of the Logger to log message to
msg - String message to be logged

logError

public static void logError(java.lang.String msg)
Log an ERROR message to DEFAULT Logger.

Parameters:
msg - String message to be logged

logError

public static void logError(java.lang.String logId,
                            java.lang.String msg)
Log an ERROR message to a particular Logger.

Parameters:
logId - Name of the Logger to log message to
msg - String message to be logged

logInfo

public static void logInfo(java.lang.String msg)
Log an INFO message to DEFAULT Logger.

Parameters:
msg - String message to be logged

logInfo

public static void logInfo(java.lang.String logId,
                           java.lang.String msg)
Log an INFO message to a particular Logger.

Parameters:
logId - Name of the Logger to log message to
msg - String message to be logged

logWarning

public static void logWarning(java.lang.String msg)
Log an WARNING message to DEFAULT Logger.

Parameters:
msg - String message to be logged

logWarning

public static void logWarning(java.lang.String logId,
                              java.lang.String msg)
Log an WARNING message to a particular Logger.

Parameters:
logId - Name of the Logger to log message to
msg - String message to be logged

setLogger

public static void setLogger(LoggingIF log)
Add the logging instance to the Logger using a particular name to refer to it, and subsequently get or log messages to later. If the logId is null, or the logging instance is null, then return doing nothing.

Parameters:
log - Log instance (i.e. SimpleLogger, AtomicLogger)


View/submit a bug or feature

For further API reference and developer documentation, see www.openptk.org. That documentation contains more detailed, developer-targeted descriptions, definitions of terms, workarounds, and working code examples.

Copyright (C) 2008-2012, Project OpenPTK. All Rights Reserved