Class Log
java.lang.Object
edu.uky.cs.nil.tt.Log
- All Implemented Interfaces:
AutoCloseable
A log is used to record system messages, server status, and session data.
A server log has three basic functions:
- Write system messages to standard output and (optionally) a file.
- Update a file reflecting the current server status.
- Record completed storytelling
sessions.
To avoid creating huge files, a new system log file is created for each day the server is running. The files are named according to the date they were created so they can be easily located, searched, and archived.
- Author:
- Stephen G. Ware
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerates arandom nameand writes the details of a completed storytellingsessionto a file with that name in the session file directory (if sessions are being recorded).voidWrites a system message tostandard outputand to the log file (if a log file is being used).static voidWrites a system message tostandard outputand to the given server log, if it exists.voidWrites a system message and the details of athrowabletostandard error outputand to the log file (if a log file is being used)static voidWrites a system message and the details of athrowabletostandard error outputand to the given server log, if it exists.voidclose()voidupdate(ServerStatus status) Updates the server status file with the server's current status, if a server status file is being maintained.
-
Constructor Details
-
Log
Constructs a new server log.- Parameters:
logs- the directory to which system log files should be written, or null if system log messages should not be recordedstatus- the file to which the current server status will be written, or null if the current server status should not be recordedsessions- 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 files or session directory
-
-
Method Details
-
append
Writes a system message tostandard outputand to the given server log, if it exists.- Parameters:
message- the message to writelog- the server log to which the message will be written, or null if the message should only be written to standard output
-
append
Writes a system message and the details of athrowabletostandard error outputand to the given server log, if it exists.- Parameters:
message- the message explaining the context of the throwablethrowable- the throwable whose details and stack trace will be writtenlog- 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
Writes a system message tostandard outputand to the log file (if a log file is being used).- Parameters:
message- the message to write
-
append
Writes a system message and the details of athrowabletostandard error outputand to the log file (if a log file is being used)- Parameters:
message- the message that gives context for the throwablethrowable- the throwable whose details and stack trace will be written
-
update
Updates the server status file with the server's current status, if a server status file is being maintained.- Parameters:
status- an object summarizing the current state of the server- Throws:
IOException- if a problem occurs while writing the status file
-
append
Generates arandom nameand writes the details of a completed storytellingsessionto a file with that name in the session file directory (if sessions 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
- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-