php 一个安全的快速写日志的函数
一个安全的快速写日志的函数 [代码片段(24行)]
<?php
/**
* 直接记录日志
* @param <type> $lvevel
* @param string $level
* http://www.phpqee.com
*/
function Write($msg, $level) {
$arr_level = explode(',', YUC_LOG_TYPE);
if (in_array($level, $arr_level)) {
$record = date('Y-m-d H:m:s') . " >>> " . number_format(microtime(TRUE), 5, ".", "") . ' ' . " : " . $level . "\\t" . $msg;
$base = M_PRO_DIR . "/Log";
$dest = $base . "/" . date("YmdH", time()) . 'log.php';
if (!file_exists($dest)) {
@mkdir($base, 0777, TRUE);
@file_put_contents($dest, "<?php die('Access Defined!');?>\\r\\n", FILE_APPEND);
}
if (file_exists($dest)) {
@file_put_contents($dest, $record . "\\r\\n", FILE_APPEND);
}
}
}
//该片段来自于http://outofmemory.cn
- 上一篇:php 统计代码行数和过滤注释
- 下一篇:php str_replace 只匹配一次
精彩图集
精彩文章






