Logger is a small class which you can use for logging data in a TXT file.
Use your CLI and enter the following to clone:
git clone https://github.com/thielicious/Logger.git
Create an object :
$log = new Logger("log.txt");
$log->setTimestamp("D M d 'y h.i A");
For example, when a user logs in, use it like this to store:
if (isset($_POST["logged_in"])) {
$log->putLog("Successful Login: ".$_SESSION["user_name"]);
}
if (isset($_GET["logout"])) {
$log->putLog("Logout: ".$_SESSION["user_name"]);
}
If you want to see the log, use this:
$log->getLog();
It will render like this:
Sun Jul 02 '17 05.45 PM » Successful Login: JohnDoe
Sun Jul 02 '17 05.46 PM » Logout: JohnDoe
Logger::__construct(string $filename)
- Choose a filename to store the log.
Logger::setTimestamp(string $format)
- Use a format for the timestamp eg.
d-m-y h:i:s
.
Logger::putLog(string $content)
- This will store the log in the file.
Logger::getLog()
- To display the content of a log file, simply use this method.
Logger::clear()
- Deletes the log file.