colly_wyx
2018-05-09 d3534714ed8f07f19e0a648ab2d07c73d0bed156
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
class TopLogger
{
    public $conf = array(
        "separator" => "\t",
        "log_file" => ""
    );
 
    private $fileHandle;
 
    protected function getFileHandle()
    {
        if (null === $this->fileHandle)
        {
            if (empty($this->conf["log_file"]))
            {
                trigger_error("no log file spcified.");
            }
            $logDir = dirname($this->conf["log_file"]);
            if (!is_dir($logDir))
            {
                mkdir($logDir, 0777, true);
            }
            $this->fileHandle = fopen($this->conf["log_file"], "a");
        }
        return $this->fileHandle;
    }
 
    public function log($logData)
    {
        if ("" == $logData || array() == $logData)
        {
            return false;
        }
        if (is_array($logData))
        {
            $logData = implode($this->conf["separator"], $logData);
        }
        $logData = $logData. "\n";
        fwrite($this->getFileHandle(), $logData);
    }
}
?>