Skip to content

Instantly share code, notes, and snippets.

@MortenDHansen
Created June 9, 2017 09:23
Show Gist options
  • Save MortenDHansen/7aa0b034e89b4db232f34e636ef0b231 to your computer and use it in GitHub Desktop.
Save MortenDHansen/7aa0b034e89b4db232f34e636ef0b231 to your computer and use it in GitHub Desktop.
Simple method for writing info to log
/**
* @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