Module hw06

Class Logger

java.lang.Object
provided.logger.impl.Logger
All Implemented Interfaces:
ILogger

public class Logger extends Object implements ILogger
DEVELOPER CODE SHOULD NOT INSTANTIATE THIS CLASS DIRECTLY! USE ILoggerControl TO INSTANTIATE A BASIC ILogger INSTANCE. A basic utility ILogger implementation that should work in most scenarios.
Author:
swong
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private LogLevel
    The current minimum logging level
    The current set of log entry processors to use
    private ILogger
    The next logger in the chain.
    static Logger
    The ILogger implementation to be shared on an application-wide level.

    Fields inherited from interface provided.logger.ILogger

    NULL
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate this logger with a single log entry processor = ILogEntryProcessor.DEFAULT and a minimum logging level of LogLevel.INFO
    Logger​(ILogEntryProcessor logDisplayFn)
    Instantiate this logger with the given log entry processor and a minimum logging level of LogLevel.INFO
    Logger​(ILogEntryProcessor logDisplayFn, LogLevel logLevel)
    Instantiate this logger with the given log entry processor and given minimum logging level
    Logger​(LogLevel level)
    Instantiate this logger with a single log entry processor = ILogEntryProcessor.DEFAULT and a minimum logging level of LogLevel.INFO
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Add the given log entry processor to the set of processors being used.
    append​(ILogger logger)
    Appends the chain represented by the given logger into this logger chain.
    boolean
    find​(ILogger logger)
    TYPICAL DEVELOPER CODE NEVER CALLS THIS METHOD! Searches the this logger chain to find any occurrence of the given ILogger.
    void
    log​(ILogEntry logEntry)
    TYPICAL DEVELOPER CODE NEVER CALLS THIS METHOD! Log the given log entry using a completed ILogEntry object where the code location is being explicitly specified.
    void
    log​(LogLevel level, String msg)
    Log the given log entry where the code location is being automatically calculate.
    remove​(ILogger logger)
    Remove the given logger from anywhere in the logger chain that begins with this logger.
    boolean
    Remove the given log entry processor from the set of processors being used.
    void
    setLogLevel​(LogLevel logLevel)
    Sets the minimum log level to be displayed.
    void
    Set the log entry processor being used.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • SHARED

      public static final Logger SHARED
      The ILogger implementation to be shared on an application-wide level.
    • nextLogger

      private ILogger nextLogger
      The next logger in the chain.
    • leProcessors

      private Set<ILogEntryProcessor> leProcessors
      The current set of log entry processors to use
    • currentLogLevel

      private LogLevel currentLogLevel
      The current minimum logging level
  • Constructor Details

    • Logger

      public Logger()
      Instantiate this logger with a single log entry processor = ILogEntryProcessor.DEFAULT and a minimum logging level of LogLevel.INFO
    • Logger

      public Logger(LogLevel level)
      Instantiate this logger with a single log entry processor = ILogEntryProcessor.DEFAULT and a minimum logging level of LogLevel.INFO
      Parameters:
      level - The minimum log level to use.
    • Logger

      public Logger(ILogEntryProcessor logDisplayFn)
      Instantiate this logger with the given log entry processor and a minimum logging level of LogLevel.INFO
      Parameters:
      logDisplayFn - The log entry processor to use.
    • Logger

      public Logger(ILogEntryProcessor logDisplayFn, LogLevel logLevel)
      Instantiate this logger with the given log entry processor and given minimum logging level
      Parameters:
      logDisplayFn - The log entry processor to use.
      logLevel - The minimum logging level to process.
  • Method Details

    • log

      public void log(LogLevel level, String msg)
      Description copied from interface: ILogger
      Log the given log entry where the code location is being automatically calculate.
      Specified by:
      log in interface ILogger
      Parameters:
      level - The log level of the entry
      msg - The message of the entry
    • log

      public void log(ILogEntry logEntry)
      Description copied from interface: ILogger
      TYPICAL DEVELOPER CODE NEVER CALLS THIS METHOD! Log the given log entry using a completed ILogEntry object where the code location is being explicitly specified. This method is used by ILoggers during a chained log.
      Specified by:
      log in interface ILogger
      Parameters:
      logEntry - The log entry to process
    • setLogProcessor

      public void setLogProcessor(ILogEntryProcessor logProcFn)
      Description copied from interface: ILogger
      Set the log entry processor being used. This processor will replace ALL processors currently in use.
      Specified by:
      setLogProcessor in interface ILogger
      Parameters:
      logProcFn - The new log processor function.
    • addLogProcessor

      public boolean addLogProcessor(ILogEntryProcessor logProcFn)
      Description copied from interface: ILogger
      Add the given log entry processor to the set of processors being used. Duplicate processors will not be added and will return a False value.
      Specified by:
      addLogProcessor in interface ILogger
      Parameters:
      logProcFn - The new log processor function to add.
      Returns:
      true if the processor was successfully added, false if the processor was already in the current set of processors or could not be added.
    • removeLogProcessor

      public boolean removeLogProcessor(ILogEntryProcessor logProcFn)
      Description copied from interface: ILogger
      Remove the given log entry processor from the set of processors being used. The last processor cannot be removed (returns false).
      Specified by:
      removeLogProcessor in interface ILogger
      Parameters:
      logProcFn - The new log processor function to remove.
      Returns:
      true if the processor was found and removed, false otherwise.
    • setLogLevel

      public void setLogLevel(LogLevel logLevel)
      Description copied from interface: ILogger
      Sets the minimum log level to be displayed.
      Specified by:
      setLogLevel in interface ILogger
      Parameters:
      logLevel - The minimum log level to be displayed.
    • append

      public ILogger append(ILogger logger)
      Description copied from interface: ILogger
      Appends the chain represented by the given logger into this logger chain.
      Specified by:
      append in interface ILogger
      Parameters:
      logger - The logger and the rest of its chain to append to the end of this logger's chain.
      Returns:
      The logger at the head of the new chain. A non-empty chain returns itself while an empty chain returns the given logger.
    • remove

      public ILogger remove(ILogger logger)
      Description copied from interface: ILogger
      Remove the given logger from anywhere in the logger chain that begins with this logger.
      Specified by:
      remove in interface ILogger
      Parameters:
      logger - The logger to remove from the chain.
      Returns:
      Returns the head of the new logger chain, typically this ILogger unless this logger is the one being removed, when ILogger.NULL is returned.
    • find

      public boolean find(ILogger logger)
      Description copied from interface: ILogger
      TYPICAL DEVELOPER CODE NEVER CALLS THIS METHOD! Searches the this logger chain to find any occurrence of the given ILogger. This method is used between ILoggers to check for potential loops in chains.
      Specified by:
      find in interface ILogger
      Parameters:
      logger - The logger chain to search for
      Returns:
      true if found, false otherwise