com.tenduke.diagnostics
Class Logger

java.lang.Object
  extended by com.tenduke.diagnostics.Logger

public final class Logger
extends java.lang.Object

Class that works as a hub, taking in log entries and publishing them to subscribers.

Logger is used throughout 10Duke SDK libraries to write log events. By default the logger uses an instance of ConsoleLogWriter for writing log entries to console. This behaviour can be changed by setting JVM system property 10duke.logger.logentrysubscriber.

Example Logger usage:

 
 Logger.instance().addEntry(new LogEntry(
      LogEntry.EventType.Info,
      LogEntry.DebugLevel.VeryVerbose,
      "This is an example log message"));
 
 

JVM system properties used in this class are described in the following table:

System propertyDescriptionDefault value
10duke.logger.logentrysubscriber Fully qualified class name of class that implements com.tenduke.diagnostics.LogEntrySubscriber and that is used for writing log entries. Use empty String to disable default logging. com.tenduke.diagnostics.ConsoleLogWriter

See Also:
LogEntry

Field Summary
static java.lang.String DEFAULT_LOG_WRITER_KEY_NAME
          Name of JVM system property key that is used to read name of class that is used as default log writer.
 
Method Summary
 void addEntry(LogEntry logEntry)
          Giving the logger a new log entry that needs to distributed to subscribers of this logger.
static Logger createChainedLogger()
          Creates new instance of logger.
 LogEntrySubscriber getDefaultLogWriter()
          Get the default log writer.
 void initializeDefaultLogWriter(java.lang.String defaultLogWriterClassName)
          Initializes default log writer to instance of class that implements LogEntrySubscriber.
static Logger instance()
          Returning handle to Logger singleton instance.
 void setDefaultLogWriter(LogEntrySubscriber logWriter)
          Set the default log writer.
 void subscribe(LogEntrySubscriber subscriber)
          Subscribe to log entries distributed by this logger.
 void unsubscribe(LogEntrySubscriber subscriber)
          Unsubscribe from log entries distributed by this logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LOG_WRITER_KEY_NAME

public static final java.lang.String DEFAULT_LOG_WRITER_KEY_NAME
Name of JVM system property key that is used to read name of class that is used as default log writer.

See Also:
Constant Field Values
Method Detail

addEntry

public void addEntry(LogEntry logEntry)
Giving the logger a new log entry that needs to distributed to subscribers of this logger.

Parameters:
logEntry - The log entry to be distributed to the subscribers.

createChainedLogger

public static Logger createChainedLogger()
Creates new instance of logger. The singleton logger instance is registered as subscriber of events of this logger.

Returns:
A chained logger instance.

getDefaultLogWriter

public LogEntrySubscriber getDefaultLogWriter()
Get the default log writer.

Returns:
Default log writer.

initializeDefaultLogWriter

public void initializeDefaultLogWriter(java.lang.String defaultLogWriterClassName)
Initializes default log writer to instance of class that implements LogEntrySubscriber. If default log writer has been earlier initialized, initialized it again replacing the earlier initialized default log writer.

Parameters:
defaultLogWriterClassName - Fully qualified class name for the default log writer. If null is given, default log writer class name is read from 10duke.logger.logentrysubscriber JVM system property, or ConsoleLogWriter will be used if the property is not defined. If empty String is given or defined by the JVM system property, no default log writer will be used.

instance

public static Logger instance()
Returning handle to Logger singleton instance.

Returns:
Singleton instance of Logger.

setDefaultLogWriter

public void setDefaultLogWriter(LogEntrySubscriber logWriter)
Set the default log writer. Unsubcribes the previous log writer from the Logger and subscribes the new logWriter.

Parameters:
logWriter - Default log writer.

subscribe

public void subscribe(LogEntrySubscriber subscriber)
Subscribe to log entries distributed by this logger.

Parameters:
subscriber - The subscriber

unsubscribe

public void unsubscribe(LogEntrySubscriber subscriber)
Unsubscribe from log entries distributed by this logger.

Parameters:
subscriber - The subscriber.