1、内核更新

2、模板管理优化
This commit is contained in:
2016-12-04 16:15:43 +08:00
parent e2910d287a
commit e28383f667
10 changed files with 371 additions and 78 deletions

View File

@@ -11,6 +11,8 @@
namespace think\log\driver;
use think\App;
/**
* 本地化调试输出到文件
*/
@@ -35,9 +37,10 @@ class File
* 日志写入接口
* @access public
* @param array $log 日志信息
* @param bool $depr 是否写入分割线
* @return bool
*/
public function save(array $log = [])
public function save(array $log = [], $depr = true)
{
$now = date($this->config['time_format']);
$destination = $this->config['path'] . date('Ym') . DS . date('d') . '.log';
@@ -50,25 +53,29 @@ class File
rename($destination, dirname($destination) . DS . $_SERVER['REQUEST_TIME'] . '-' . basename($destination));
}
// 获取基本信息
if (isset($_SERVER['HTTP_HOST'])) {
$current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
$depr = $depr ? "---------------------------------------------------------------\r\n" : '';
if (App::$debug) {
// 获取基本信息
if (isset($_SERVER['HTTP_HOST'])) {
$current_uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
} else {
$current_uri = "cmd:" . implode(' ', $_SERVER['argv']);
}
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
$time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]';
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = ' [内存消耗:' . $memory_use . 'kb]';
$file_load = ' [文件加载:' . count(get_included_files()) . ']';
$info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n";
$server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0';
$remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'CLI';
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
}
$runtime = number_format(microtime(true) - THINK_START_TIME, 10);
$reqs = $runtime > 0 ? number_format(1 / $runtime, 2) : '∞';
$time_str = ' [运行时间:' . number_format($runtime, 6) . 's][吞吐率:' . $reqs . 'req/s]';
$memory_use = number_format((memory_get_usage() - THINK_START_MEM) / 1024, 2);
$memory_str = ' [内存消耗:' . $memory_use . 'kb]';
$file_load = ' [文件加载:' . count(get_included_files()) . ']';
$info = '[ log ] ' . $current_uri . $time_str . $memory_str . $file_load . "\r\n";
$server = isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '0.0.0.0';
$remote = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '0.0.0.0';
$method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'CLI';
$uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
foreach ($log as $type => $val) {
$level = '';
foreach ($val as $msg) {
@@ -80,12 +87,15 @@ class File
if (in_array($type, $this->config['apart_level'])) {
// 独立记录的日志级别
$filename = $path . DS . date('d') . '_' . $type . '.log';
error_log("[{$now}] {$server} {$remote} {$method} {$uri}\r\n{$level}\r\n---------------------------------------------------------------\r\n", 3, $filename);
error_log("[{$now}] {$level}\r\n{$depr}", 3, $filename);
} else {
$info .= $level;
}
}
return error_log("[{$now}] {$server} {$remote} {$method} {$uri}\r\n{$info}\r\n---------------------------------------------------------------\r\n", 3, $destination);
if (App::$debug) {
$info = "{$server} {$remote} {$method} {$uri}\r\n" . $info;
}
return error_log("[{$now}] {$info}\r\n{$depr}", 3, $destination);
}
}