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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?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='' )
    {
        if( bNewStyleLogging )
        {
            $this->m_strDirRoot=strLogBaseDir."\\ServerLog\\".\CommFunc\GetMonth()."\\";
        }
        else
        {
            $this->m_strDirRoot=$strRootDir;
        }
        
        #¹¹ÔìÈÕÖ¾¶ÔÏóºÍÊý×é
        
        $this->m_arrayLog=array();        
        $this->AddLogObj( $strFileDir, $strFileName, $strExtraInfo );
        
    }
    
    #Ôö¼Ólog¶ÔÏó
    public function AddLogObj( $strFileDir, $strFileName, $strExtraInfo='' )
    {
        #»ñµÃÈÎÒâÒ»¸öÈÕÖ¾¶ÔÏó£¬È¡µÃËüµÄÀ©Õ¹Êä³öÄÚÈÝ
        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 );
        $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 );
        }
    }
}
 
?>