Created
June 9, 2017 09:23
-
-
Save MortenDHansen/7aa0b034e89b4db232f34e636ef0b231 to your computer and use it in GitHub Desktop.
Simple method for writing info to log
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
/** | |
* @param string $type | |
* @param $msg | |
*/ | |
public function localLog($msg, $type = 'performance') | |
{ | |
switch ($type) { | |
case 'performance': | |
$logMsg = date("Y-m-d H:i:s") . " | " . $msg . " | " . PHP_EOL; | |
break; | |
default: | |
break; | |
} | |
if (!empty($logMsg)) { | |
if (file_put_contents('./' . $type . '_' . date("Y-m-d") . '.log', $logMsg, FILE_APPEND) === false) { | |
die("No log written dude"); | |
} | |
}; | |
} | |
/* | |
Example usage: | |
use logger; | |
$privateLog = new logger(); | |
$start = microtime(true); | |
// ... Something happens ... | |
$time_elapsed = microtime(true) - $start; | |
$privateLog->localLog("Elapsed: " . $time_elapsed . " ms"); | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment