Skip to content
Small class that logs data in a text file
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
logger.class.php

README.md

Logger

Small logger class which lets you log data in a text file.


INTRODUCTION

Logger is a small class which you can use for logging data in a TXT file.


SETUP INFORMATION

Use your CLI and enter the following to clone:
git clone https://github.com/thielicious/Logger.git


USAGE

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

METHODS

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.


If you encounter any bugs, feel free to open up an issue, thank you.

thielicious.github.io

You can’t perform that action at this time.