Class Log

java.lang.Object
edu.uky.cs.nil.tt.Log
All Implemented Interfaces:
AutoCloseable

public class Log extends Object implements AutoCloseable
A log is used to record system messages and session data.

A server log has two basic functions:

  • Write system message to standard output and (optionally) a file.
  • Record completed storytelling sessions, each in its own file in a directory.
Author:
Stephen G. Ware
  • Constructor Details

    • Log

      public Log(File log, File sessions) throws IOException
      Constructs a new server log.
      Parameters:
      log - the file to which system message will be written, or null if system message should only be written to standard output
      sessions - the directory to which completed session files should be written, or null if sessions should not be recorded
      Throws:
      IOException - if a problem occurs when creating or opening the log file or session directory
  • Method Details

    • append

      public static void append(String message, Log log)
      Writes a system message to standard output and to the given server log, if it exists.
      Parameters:
      message - the message to write
      log - the server log to which the message will be written, or null if the message should only be written to standard output
    • append

      public static void append(String message, Throwable throwable, Log log)
      Writes a system message and the details of a throwable to standard error output and to the given server log, if it exists.
      Parameters:
      message - the message explaining the context of the throwable
      throwable - the throwable whose details and stack trace will be written
      log - the server log to which the message and details will be written, or null if they should only be written to standard error output
    • append

      public void append(String message)
      Writes a system message to standard output and to the log file (if a log file is being used).
      Parameters:
      message - the message to write
    • append

      public void append(String message, Throwable throwable)
      Writes a system message and the details of a throwable to standard error output and to the log file (if a log file is being used)
      Parameters:
      message - the message that gives context for the throwable
      throwable - the throwable whose details and stack trace will be written
    • append

      public String append(Session session) throws IOException
      Generates a random name and writes the details of a completed storytelling session to a file with that name in the session file directory (if session are being recorded). If sessions are not being recorded, this method does nothing and returns null.
      Parameters:
      session - a completed session
      Returns:
      the randomly generated session name
      Throws:
      IOException - if a problem occurs while writing the session to file
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Throws:
      IOException