mirror of
https://e.coding.net/circlecloud/MinecraftAccount.git
synced 2025-11-25 21:36:08 +00:00
50
ThinkPHP/Library/Think/Log/Driver/File.class.php
Normal file
50
ThinkPHP/Library/Think/Log/Driver/File.class.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 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 <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
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';
|
||||
}
|
||||
// 自动创建日志目录
|
||||
$log_dir = dirname($destination);
|
||||
if (!is_dir($log_dir)) {
|
||||
mkdir($log_dir, 0755, true);
|
||||
}
|
||||
//检测日志文件大小,超过配置大小则备份日志文件重新生成
|
||||
if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) ){
|
||||
rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
|
||||
}
|
||||
error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination);
|
||||
}
|
||||
}
|
||||
49
ThinkPHP/Library/Think/Log/Driver/Sae.class.php
Normal file
49
ThinkPHP/Library/Think/Log/Driver/Sae.class.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 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: luofei614 <weibo.com/luofei614>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace Think\Log\Driver;
|
||||
|
||||
class Sae {
|
||||
|
||||
protected $config = array(
|
||||
'log_time_format' => ' c ',
|
||||
);
|
||||
|
||||
// 实例化并传入参数
|
||||
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='') {
|
||||
static $is_debug=null;
|
||||
$now = date($this->config['log_time_format']);
|
||||
$logstr="[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n";
|
||||
if(is_null($is_debug)){
|
||||
preg_replace('@(\w+)\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']);
|
||||
$is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false;
|
||||
}
|
||||
if($is_debug){
|
||||
sae_set_display_errors(false);//记录日志不将日志打印出来
|
||||
}
|
||||
sae_debug($logstr);
|
||||
if($is_debug){
|
||||
sae_set_display_errors(true);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user