首页 >php教程 >php手册 >SVN之后不提交Runtime目录 造成日志不记录

SVN之后不提交Runtime目录 造成日志不记录

WBOY
WBOY原创
2016-06-07 11:41:251132浏览

使用svn后 不想提交 runtime里的大量缓存和日志 所以把这个目录忽略了,却造成换了环境后目录不全导致,日志无法自动写入,修改了log的日志存储器
还是治标不治本 望能改进 Build::checkDir 附上治标不治本的代码

// +----------------------------------------------------------------------
// | TOPThink [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st
// +----------------------------------------------------------------------

namespace Think\Log\Driver;

class File {

protected $config = array(
'log_time_format' => ' c ',
'log_file_size' => 2097152,
'log_path' => '',
);

// 实例化并传入参数
public function __construct($config=array()){
$this->config = array_merge($this->config,$config);
}

/**
* 日志写入接口
* @access public
* @param string $log 日志信息
* @param string $destination 写入目标
* @return void
*/
public function write($log,$destination='') {
$now = date($this->config['log_time_format']);
if(empty($destination))
{
$destination = $this->config['log_path'].date('y_m_d').'.log';
}
else
{
$pathinfo = pathinfo($destination);
$this->config['log_path'] = $pathinfo['dirname'];
}
if(!is_dir($this->config['log_path'])) {
mkdir($this->config['log_path'],0755,true);
defined('DIR_SECURE_FILENAME') or define('DIR_SECURE_FILENAME', 'index.html');
defined('DIR_SECURE_CONTENT') or define('DIR_SECURE_CONTENT', ' ');
$content = DIR_SECURE_CONTENT;
$files = explode(',', DIR_SECURE_FILENAME);
foreach($files as $filename)
{
file_put_contents($this->config['log_path'].'/'.$filename,$content);
}
}
//检测日志文件大小,超过配置大小则备份日志文件重新生成
if(is_file($destination) && floor($this->config['log_file_size']) rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
}
}

AD:真正免费,域名+虚机+企业邮箱=0元

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn