Skip to content

Instantly share code, notes, and snippets.

@samir64
Last active April 28, 2018 16:20
Show Gist options
  • Save samir64/99ea8f67ed7fcb06a7ead23c74da15bd to your computer and use it in GitHub Desktop.
Save samir64/99ea8f67ed7fcb06a7ead23c74da15bd to your computer and use it in GitHub Desktop.
PHP logger function
<?php
//NOTE: For use the Logger function copy these two lines to your code and fill $LOGGER_VARIABLES array by your variables
/*
$LOGGER_VARIABLES = [];
LOGGER(__FILE__, __METHOD__, __LINE__, function () use ($LOGGER_VARIABLES) {var_dump($LOGGER_VARIABLES);});
*/
//NOTE: PHP error reporter
//error_reporting(E_ALL);
error_reporting(E_ALL ^ E_STRICT);
ini_set('display_errors', 'On');
//NOTE: Logger Function
/**
* @param string $fileName
* @param string $methodName
* @param int $lineNo
* @param callable $message
*/
function LOGGER($fileName, $methodName, $lineNo, callable $message)
{
echo "<div style='margin: 20px 5px; padding: 5px; background-color: #dddddd; border: 1px solid black;'><div style='color: red;'>";
echo "LOG|" . pathinfo($fileName, PATHINFO_BASENAME) . "|" . $methodName . "|" . $lineNo . ":";
echo "</div>";
$message();
echo "<div style='color: red;'>:LOG</div></div>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment