Skip to content

Instantly share code, notes, and snippets.

@whatsrtos
Last active September 23, 2018 03:21
Show Gist options
  • Save whatsrtos/d210cbff40a97f99b50e933edc60495c to your computer and use it in GitHub Desktop.
Save whatsrtos/d210cbff40a97f99b50e933edc60495c to your computer and use it in GitHub Desktop.
PHP
// Windows
error_log(__FILE__.':'.__LINE__.':['.date("Y-m-d G:i:s",time())."] msg: xxx\n", 3, 'c:/cy'.date("Y-m-d").'.log');
// Linux
file_put_contents('/tmp/cy'.date("Y-m-d").'.log', __FILE__.':'.__LINE__.':'."msg: xxx\n", FILE_APPEND);
// usage: outputTrace2Html(sprintf("post IDs = %s", print_r(array_keys($postIDArray),true)));
function outputTrace2Html($msg,$new=false)
{
if(!$this->isDebugEnable) return;
$backtrace = debug_backtrace();
$lasttrace = $backtrace[0];
$file = $lasttrace ['file'];
$line = $lasttrace['line'];
$time = date('Y-m-d H-i-s', time());
$os = (DIRECTORY_SEPARATOR=='\\')?"windows":'linux';
if($os == 'windows') {
$debug_html = dirname( dirname(__FILE__) ) .'\\'.'debug.html';
} else if($os == 'linux') {
$debug_html = dirname( dirname(__FILE__) ) .'//'.'debug.html';
}
if($new == true) {
file_put_contents($debug_html,"$file:$line:$time: $msg<br><br>");
} else {
file_put_contents($debug_html,"$file:$line:$time: $msg<br><br>",FILE_APPEND);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment