Class to log SYSTEM MESSAGES (such as alerts or diagnostics) into a text file or an HTML file
DEPENDENCIES: None
EXAMPLE OF USAGE:
public $logFile; // Name of file where to store the log messages. If file already exists, the message gets appended; otherwise, the file gets created
public $htmlLogging = true; // Flag indicating whether the log file is meant to be an HTML file; if false, it will be regarded as a text file
public $style = ""; // Optional HTML styling to apply to the message; if present, a <span> tag is used
public $indentAmount = 0; // 0 indicates no indentation; higher integers represent progressively-increasing indentation (in points for HTML messages, or number of blanks for text ones)
public $indentIncrementHTML = 15; // Indent amount , relative to the previous message "level", in points (for HTML messages only)
public $indentIncrementText = 3; // Indent amount , relative to the previous message "level", in characters (for text messages only)
public $timeStamp = true; // Whether to timestamp the message
public $extraPrefix = ""; // Optional extra prefix (at the very beginning)
public $separator = "_____________________________________________________________________________________________________________________";
function __construct($logFilename)
// Specify a filename to use for logging; it will generally be a .txt for or .htm filed depending on the "htmlLogging" property
public function logMessage($level, $msg, $style = "")
/* HIGH-level function to log the given text message to the designated log file (whose name is stored in the class property "logFile"). If the log file doesn't exist, it gets created.
A new line is added after each entry.
ARGUMENTS:
level An integer indicating the "importance": 0 (most important), 1, 2, ...
msg The message to log
style Optional HTML styling to apply to the message, using a <span> tag. Do NOT include the <span> tag
RETURN VALUE: true if successful, or false if not.
*/
public function logErrorMessage($msg)
/* Log an error message. Same as regular logging, but with more emphasis, and the backtrace of the call stack
*/
public function insertSeparator()
// Append the standard separator (and a new line) to the log file
public function fileLogging($msg)
/* LOW-level function to append the given message to the log file (or to create a log file, if not present.)
A newline is automatically added.
If htmlLogging is enabled, then any HTML in the message (which could mess up the log file's viewing) is protected with htmlentities
The message is optionally modified by:
- the string: "date time", where date is mm/dd/yy
- an indentation
- a user-specified prefix
- a user-specifief HTML style
RETURN VALUE: true if successful, or false if not.
*/