Last active
August 29, 2015 14:04
-
-
Save clinyong/9762473936fe9c83232a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 $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