Last active
December 29, 2015 11:19
-
-
Save jgraup/7662910 to your computer and use it in GitHub Desktop.
PHP - Debug class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Debug::Test("Testing... 1", ",2", ",3"); | |
/* | |
[12:11:13] Testing... 1,2,3 | |
[12:11:13] Testing Log | |
[12:11:13 WARNING] Testing Warn | |
[12:11:13 ERROR] Testing Error | |
[12:11:13 DUMP | array | Testing var_dump] | |
array(1) { | |
["foo"]=> | |
string(3) "bar" | |
} | |
****************************************** | |
****************************************** | |
[12:11:13] Some special stuff! | |
****************************************** | |
****************************************** | |
*/ | |
class Debug | |
{ | |
/** | |
* @var $debug bool | |
* @var $dateFormat string | |
*/ | |
public static $debug = true; | |
public static $dateFormat = "H:m:s"; | |
/** | |
* DATE | |
* @return string Current date based on format | |
*/ | |
public static function now () | |
{ | |
return date(Debug::$dateFormat); | |
} | |
/** | |
* DUMP | |
* @param $obj mixed | |
* @param $message string (optional) | |
*/ | |
public static function Dump ($obj, $message='') | |
{ | |
if (!Debug::$debug) return; | |
$type = gettype($obj); | |
if (isset($message) && $message !== '') $message = " | " . $message; | |
echo "\n[", Debug::now(), " DUMP | {$type}{$message}]\n"; | |
var_dump($obj); | |
} | |
/** | |
* LOG | |
* @param $content mixed | |
*/ | |
public static function Log ($content) | |
{ | |
if (!Debug::$debug) return; | |
if (isset($content)) { | |
$content = implode('', (is_array($content) && sizeof(func_get_args())<=1) ? $content : func_get_args()); | |
} | |
echo "\n[", Debug::now(), "]\t", $content, "\n"; | |
} | |
/** | |
* WARN | |
* @param $content mixed | |
*/ | |
public static function Warn ($content) | |
{ | |
if (!Debug::$debug) return; | |
if (isset($content)) { | |
$content = implode('', (is_array($content) && sizeof(func_get_args())<=1) ? $content : func_get_args()); | |
} | |
echo "\n[", Debug::now(), " WARNING]\t", $content, "\n"; | |
} | |
/** | |
* ERROR | |
* @param $content mixed | |
*/ | |
public static function Error ($content) | |
{ | |
if (!Debug::$debug) return; | |
if (isset($content)) { | |
$content = implode('', (is_array($content) && sizeof(func_get_args())<=1) ? $content : func_get_args()); | |
} | |
echo "\n[", Debug::now(), " ERROR]\t", $content, "\n"; | |
} | |
/** | |
* HIGHLIGHT | |
* @param $content mixed | |
*/ | |
public static function Highlight ($content) | |
{ | |
if (!Debug::$debug) return; | |
if (isset($content)) { | |
$content = implode('', (is_array($content) && sizeof(func_get_args())<=1) ? $content : func_get_args()); | |
} | |
echo "\n******************************************\n"; | |
echo "******************************************\n"; | |
echo "[", Debug::now(), "]\t", $content, "\n"; | |
echo "******************************************\n"; | |
echo "******************************************\n"; | |
} | |
/** | |
* TESTING | |
* @param $content mixed | |
*/ | |
public static function Test ($content) | |
{ | |
if (!Debug::$debug) return; | |
date_default_timezone_set('America/New_York'); | |
if (isset($content)) { | |
$content = implode('', (is_array($content) && sizeof(func_get_args())<=1) ? $content : func_get_args()); | |
Debug::Log($content); | |
} | |
Debug::Log("Testing Log"); | |
Debug::Warn("Testing Warn"); | |
Debug::Error("Testing Error"); | |
Debug::Dump(["foo"=>"bar"], "Testing var_dump");\ | |
Debug::Highlight("Some special stuff!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment