Skip to content

Instantly share code, notes, and snippets.

@Chengings
Last active August 29, 2015 14:15
Show Gist options
  • Save Chengings/c7a4d4cae5abeb01b782 to your computer and use it in GitHub Desktop.
Save Chengings/c7a4d4cae5abeb01b782 to your computer and use it in GitHub Desktop.
Insert the string output to log file
<?php
private function _logfile($logName, $str2log)
{
$file= sys_get_temp_dir() . '/mydebug-' . date('Y-m-d') . '.log';
if (!$handle = fopen($file, 'a')) {
throw new Exception('Could not open file!');
}
$str2log = print_r($str2log, true);
$olog = print_r("{$logName}: {$str2log}", true) . PHP_EOL;
if(fwrite ($handle, $olog)===false){
throw new Exception('Could not write file!');
}
fclose($handle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment