Skip to content

Instantly share code, notes, and snippets.

@clinyong
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clinyong/9762473936fe9c83232a to your computer and use it in GitHub Desktop.
Save clinyong/9762473936fe9c83232a to your computer and use it in GitHub Desktop.
/**
*
* 打印调试日志
* @param string $errmsg
*/
function new_debug($msg) {
$info = debug_backtrace ();
$file = $info [0] ['file'];
$line = $info [0] ['line'];
if (is_array ( $msg ) || is_object ( $msg )) {
new_log ( $file, $line, json_encode ( $msg ), 'DEBUG' );
} else {
new_log ( $file, $line, $msg, 'DEBUG' );
}
}
/**
* 记录日志,要确保路径是存在
* @param $mess
* @param $path
*/
function new_log($file, $line, $mess, $level = 'LOG') {
$today = date ( "Y/m/d H:i:s" );
$path = APP_PATH.'/logs/debug.log';
$trans_tbl = get_html_translation_table ( HTML_ENTITIES );
$trans_tbl = array_flip ( $trans_tbl );
$mess = strtr ( $mess, $trans_tbl );
$fp = fopen ( $path, "a+" );
if ($fp) {
fwrite ( $fp, $today . " [" . $file . ' ' . $line . "][" . $level . "] " . $mess . " from " . $_SERVER ['REMOTE_ADDR'] . "\r\n" );
fclose ( $fp );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment