thinkphp关闭日志记录

没怎么去研究tp的框架底层,虽然说有个静态成员public static $debug = true;来设置调试,但后来发现根本不是

不知道TP框架开发者就不能考虑考虑如果是不懂框架只懂用接口的可要怎么让网站长时间生存,别人一个AB命令过来不得日志好几个G?

框架就不研究了,浪费时间,其实大概看了一下,有一通用调用LOG的地方

文件位置:

站点根目录/thinkphp/library/think/log/driver/File.php

/**
* 日志写入接口
* @access public
* @param array $log 日志信息
* @param bool $depr 是否写入分割线
* @return bool
*/
public function save(array $log = [], $depr = true)
{
return false; //直接取消日志写入,干脆明了
$now = date($this->config[‘time_format’]);
$destination = $this->config[‘path’] . date(‘Ym’) . DS . date(‘d’) . ‘.log’;

$path = dirname($destination);
!is_dir($path) && mkdir($path, 0755, true);

//检测日志文件大小,超过配置大小则备份日志文件重新生成
if (is_file($destination) && floor($this->config[‘file_size’]) <= filesize($destination)) {
rename($destination, dirname($destination) . DS . $_SERVER[‘REQUEST_TIME’] . ‘-‘ . basename($destination));
}

$depr = $depr ? “—————————————————————\r\n” : ”;
$info = ”;
if (App::$debug) {
// 获取基本信息
if (isset($_SERVER[‘HTTP_HOST’])) {
$current_uri = $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’];
} else {
$current_uri = “cmd:” . implode(‘ ‘, $_SERVER[‘argv’]);
}

$runtime = round(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) {
if (!is_string($msg)) {
$msg = var_export($msg, true);
}
$level .= ‘[ ‘ . $type . ‘ ] ‘ . $msg . “\r\n”;
}
if (in_array($type, $this->config[‘apart_level’])) {
// 独立记录的日志级别
$filename = $path . DS . date(‘d’) . ‘_’ . $type . ‘.log’;
error_log(“[{$now}] {$level}\r\n{$depr}”, 3, $filename);
} else {
$info .= $level;
}
}
if (App::$debug) {
$info = “{$server} {$remote} {$method} {$uri}\r\n” . $info;
}
return error_log(“[{$now}] {$info}\r\n{$depr}”, 3, $destination);
}

 

在public function save()方法里直接一个return false; 问题搞定!

发表评论

电子邮件地址不会被公开。 必填项已用*标注