标签:sage idt none ted 存储 lib app init highlight
目录结构:
日志类 core\lib\log.php
<?php
namespace core\lib;
class log
{
static $class;
/*
* 1.确定日志存储方式
* 2.写日志
*/
static public function init()
{
//确定存储方式
$drive = conf::get(‘DRIVE‘,‘log‘);
$class = ‘\core\lib\drive\log\\‘.$drive;
self::$class = new $class;
}
static public function log($message,$file = ‘log‘)
{
self::$class->log($message,$file);
}
}
文件日志类 \core\lib\drive\log\file.php
<?php
namespace core\lib\drive\log;
use core\lib\conf;
class file
{
protected $path;
public function __construct()
{
$conf = conf::get(‘OPTION‘,‘log‘);
$this->path = $conf[‘PATH‘];
}
public function log($message,$file = ‘log‘)
{
/*
* 1.确定文件存储位置是否存在
* 新建目录
* 2.写入日志
*/
if(!is_dir($this->path))
{
mkdir($this->path,‘0777‘,true);
}
file_put_contents($this->path.$file.‘.php‘,date(‘Y-m-d H:i:s‘).$message.PHP_EOL,FILE_APPEND);
}
}
日志配置文件 core\config\log.php
<?php
return array(
‘DRIVE‘=>‘file‘,
‘OPTION‘=>array(
‘PATH‘=>MYFRAME.‘/log/‘
)
);
写入日志
\core\lib\log::init();
\core\lib\log::log(‘test‘);
标签:sage idt none ted 存储 lib app init highlight
原文地址:https://www.cnblogs.com/xiaobingch/p/12464653.html