Last active
December 20, 2015 19:38
-
-
Save CaporalDead/6184180 to your computer and use it in GitHub Desktop.
Simple Static Logger
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 | |
namespace Utils; | |
class Logger | |
{ | |
const DEBUG = 1; | |
const INFO = 2; | |
const ERROR = 3; | |
const WARNING = 4; | |
private static $_startTime = -1; | |
private static $_stopTime = -1; | |
public static function log($message, $priority) | |
{ | |
print(sprintf("%s [%s] : %s", date("Y-m-d H:i:s"), $priority, $message)); | |
} | |
public static function debug($message) | |
{ | |
self::log($message, DEBUG); | |
} | |
public static function info($message) | |
{ | |
self::log($message, INFO); | |
} | |
public static function warning($message) | |
{ | |
self::log($message, WARNING); | |
} | |
public static function error($message) | |
{ | |
self::log($message, ERROR); | |
} | |
public static function startCounter() | |
{ | |
if (-1 == self::$_startTime) { | |
self::$_startTime = microtime(true); | |
} else { | |
throw new Exception("Trying to start the counter again !"); | |
} | |
} | |
public static function getCounter() | |
{ | |
if (-1 == self::$_startTime) { | |
throw new Exception("Trying to get current exec time without starting the counter !"); | |
} | |
return (microtime(true) - self::$_startTime); | |
} | |
public static function stopCounter() | |
{ | |
if (-1 == self::$_stopTime) { | |
self::$_stopTime = microtime(true); | |
return (self::$_stopTime - self::$_startTime); | |
} else { | |
throw new Exception("Trying to stop the counter again !"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment