hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
 
namespace MultiLogging;
#创建日期:2012-4-13 下午4:10:48
#作者:zhouliang
include_once 'Log4Me.php';
include_once 'BaseConfig.php';
 
class MultiLogging
{
    #一些指定目录时常用的定义
    const strLogDir = "\\InterfaceLog";
 
    #每次记录LOG同时写入到这三个log
    private $m_arrayLog = null;
 
    #根目录
    private $m_strDirRoot = '';
 
    #参数$strRootDir为根目录,指定后,以后每次新加的日志对象都会以此为根目录
    #$strFileDir,根目录的下级目录(主要是为了便于分类)
    #$strFileName,指定日志的标识符文件名
    function __construct($strRootDir, $strFileDir, $strFileName, $strExtraInfo = '', $writeMode = \Log4Me\DEF_WRITE_MODE)
    {
        if (bNewStyleLogging) {
            $this->m_strDirRoot = strLogBaseDir . "\\ServerLog\\" . \CommFunc\GetMonth() . "\\";
        } else {
            $this->m_strDirRoot = $strRootDir;
        }
 
        #构造日志对象和数组
 
        $this->m_arrayLog = array();
        $this->AddLogObj($strFileDir, $strFileName, $strExtraInfo, $writeMode);
    }
 
    #增加log对象
    public function AddLogObj($strFileDir, $strFileName, $strExtraInfo = '', $writeMode = \Log4Me\DEF_WRITE_MODE)
    {
        #获得任意一个日志对象,取得它的扩展输出内容
        if (count($this->m_arrayLog)) {
            foreach ($this->m_arrayLog as $log) {
                $strExtraInfo = $log->GetAffixStr() . " " . $strExtraInfo;
                break;
            }
        }
 
        foreach ($this->m_arrayLog as $log) {
            $log->SetAffixStr($strExtraInfo);
        }
 
        if (bNewStyleLogging) {
            $strPhpDir = $this->m_strDirRoot . self::strLogDir . "\\" . date("d", time()) . '\\' . $strFileDir;
        } else {
            $strPhpDir = $this->m_strDirRoot . self::strLogDir . '\\' . $strFileDir;
        }
        $logPhpFile = new \Log4Me\Log4Me($strPhpDir, $strFileName, \Log4Me\DEF_LOG_LEVEL, $writeMode);
        $logPhpFile->SetAffixStr($strExtraInfo);
        $this->m_arrayLog[$strFileName] = $logPhpFile;
    }
 
    #移除log对象,如果存在的话
    private function RemoveLogObj($logName)
    {
        $logObj = GetLogObj($logName);
        unset($logObj);
    }
 
    #根据log名,获得Log对象
    public function &GetLogObj($logName)
    {
        if (!array_key_exists($logName, $this->m_arrayLog)) {
            return null;
        }
        return $this->m_arrayLog[$logName];
    }
 
    public function Debug($info)
    {
        foreach ($this->m_arrayLog as $log) {
            $log->Debug($info);
        }
    }
 
    public function Info($info)
    {
        foreach ($this->m_arrayLog as $log) {
            $log->Info($info);
        }
    }
 
    public function Warn($info)
    {
        foreach ($this->m_arrayLog as $log) {
            $log->Warn($info);
        }
    }
 
    public function Error($info)
    {
        foreach ($this->m_arrayLog as $log) {
            $log->Error($info);
        }
    }
 
    public function Fatal($info)
    {
        foreach ($this->m_arrayLog as $log) {
            $log->Fatal($info);
        }
    }
}