48 lines
786 B
PHP
48 lines
786 B
PHP
<?php
|
|
|
|
class FileLog
|
|
{
|
|
private $filepath;
|
|
|
|
private $filename;
|
|
|
|
private $handle = null;
|
|
|
|
private $time;
|
|
|
|
public function __construct($filepath, $filename)
|
|
{
|
|
$this->time = date('Y-m-d H:i:s');
|
|
$this->filepath = $filepath;
|
|
$this->filename = $filename;
|
|
$this->init();
|
|
}
|
|
|
|
public function init()
|
|
{
|
|
if (!is_dir($this->filepath))
|
|
{
|
|
mkdir($this->filepath, 0777, true);
|
|
}
|
|
}
|
|
|
|
public function write($content, $type='err')
|
|
{
|
|
$str = $type . '=====';
|
|
$str .= '当前时间为: ' . $this->time;
|
|
$str .= '=====';
|
|
$str .= $content . PHP_EOL;
|
|
|
|
if (substr($this->filepath, -1) == '/')
|
|
{
|
|
$file = $this->filepath . $this->filename;
|
|
}
|
|
else
|
|
{
|
|
$file = $this->filepath . '/' . $this->filename;
|
|
}
|
|
|
|
return file_put_contents($file, $str, FILE_APPEND);
|
|
}
|
|
|
|
} |