php:log
<?php
/**
* 记录日志
* @param $message
* @param string $level
* @param int $type
* @param string $destination
* @param string $extra
*/
function log($message, $level = 'err', $type = 3, $destination = '', $extra = '') {
$dir = DT_ROOT . '/file/sqllog/'.date('Y-m');
if (empty($destination)) {
dir_create($dir);
$destination = $dir .'/'.date('Y-m-d') . '.log';
}
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if (is_file($destination) && floor(1024 * 1024) <= filesize($destination))
rename($destination, dirname($destination) . '/' . date('H_i_s') . '-' . basename($destination));
$now = date('[ c ]');
error_log("[" . (($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1') . "]{$now} {$level}: {$message}\r\n", $type, $destination, $extra);
}