Created
August 28, 2017 02:38
-
-
Save extralam/5b9a09d52f56ad2658e91e57f6fb39a1 to your computer and use it in GitHub Desktop.
TimeLogger , a logger printout. Check running time.
This file contains hidden or 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
/** | |
* User: alan | |
* Date: 22/6/2017 | |
* Time: 6:34 PM | |
*/ | |
namespace TimeLogger; | |
class TimeLogger | |
{ | |
protected static $time_start; | |
protected static $last_time; | |
protected static $logger; | |
public static function start() | |
{ | |
self::$time_start = microtime(true); | |
self::$last_time = microtime(true); | |
} | |
public static function log($name = '', $isShowLog = false){ | |
$txt = (microtime(true) - self::$time_start) . " " . $name; | |
if($isShowLog){ | |
self::debug_r($txt , false); | |
} | |
self::$logger[] = $txt; | |
} | |
public static function lap($name = '', $isShowLog = false){ | |
$txt = ''; | |
if($isShowLog){ | |
$txt = (microtime(true) - self::$last_time) . " " . $name; | |
self::$last_time = microtime(true); | |
self::debug_r_b($txt , false); | |
} | |
self::$logger[] = $txt; | |
} | |
public static function show(){ | |
self::debug_r(self::$logger); | |
} | |
public static function get_log(){ | |
return self::$logger; | |
} | |
private static function debug_r($msg , $isDie = true){ | |
echo "<pre>" ; | |
print_r($msg); | |
echo "</pre>"; | |
if($isDie) | |
die(); | |
} | |
private static function debug_r_b($msg , $isDie = true){ | |
echo "<pre><b>" ; | |
print_r($msg); | |
echo "</pre></b>"; | |
if($isDie) | |
die(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment