hxp
2025-02-10 23abd776c72445da3af125bcb26ec13c19341b39
Common/MultiLogging.php
@@ -1,132 +1,112 @@
<?php
namespace MultiLogging;
#创建日期:2012-4-13 下午4:10:48
#作者:zhouliang
#创建日期: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='' )
   #一些指定目录时常用的定义
   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()."\\";
      if (bNewStyleLogging) {
         $this->m_strDirRoot = strLogBaseDir . "\\ServerLog\\" . \CommFunc\GetMonth() . "\\";
      } else {
         $this->m_strDirRoot = $strRootDir;
      }
      else
      {
         $this->m_strDirRoot=$strRootDir;
      }
      #构造日志对象和数组
      $this->m_arrayLog=array();
      $this->AddLogObj( $strFileDir, $strFileName, $strExtraInfo );
      #构造日志对象和数组
      $this->m_arrayLog = array();
      $this->AddLogObj($strFileDir, $strFileName, $strExtraInfo, $writeMode);
   }
   #增加log对象
   public function AddLogObj( $strFileDir, $strFileName, $strExtraInfo='' )
   #增加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;
      #获得任意一个日志对象,取得它的扩展输出内容
      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 );
      foreach ($this->m_arrayLog as $log) {
         $log->SetAffixStr($strExtraInfo);
      }
      if( bNewStyleLogging )
      {
         $strPhpDir=$this->m_strDirRoot.self::strLogDir."\\".date("d",time()).'\\'.$strFileDir;
      if (bNewStyleLogging) {
         $strPhpDir = $this->m_strDirRoot . self::strLogDir . "\\" . date("d", time()) . '\\' . $strFileDir;
      } else {
         $strPhpDir = $this->m_strDirRoot . self::strLogDir . '\\' . $strFileDir;
      }
      else
      {
         $strPhpDir=$this->m_strDirRoot.self::strLogDir.'\\'.$strFileDir;
      }
      $logPhpFile=new \Log4Me\Log4Me( $strPhpDir, $strFileName );
      $logPhpFile->SetAffixStr( $strExtraInfo );
      $this->m_arrayLog[$strFileName]=$logPhpFile;
      $logPhpFile = new \Log4Me\Log4Me($strPhpDir, $strFileName, \Log4Me\DEF_LOG_LEVEL, $writeMode);
      $logPhpFile->SetAffixStr($strExtraInfo);
      $this->m_arrayLog[$strFileName] = $logPhpFile;
   }
   #移除log对象,如果存在的话
   private function RemoveLogObj( $logName )
   #移除log对象,如果存在的话
   private function RemoveLogObj($logName)
   {
      $logObj=GetLogObj($logName);
      unset( $logObj );
      $logObj = GetLogObj($logName);
      unset($logObj);
   }
   #根据log名,获得Log对象
   public function &GetLogObj( $logName )
   #根据log名,获得Log对象
   public function &GetLogObj($logName)
   {
      if( !array_key_exists( $logName, $this->m_arrayLog ) )
      {
      if (!array_key_exists($logName, $this->m_arrayLog)) {
         return null;
      }
      return $this->m_arrayLog[$logName];
   }
   public function Debug( $info )
   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 );
      foreach ($this->m_arrayLog as $log) {
         $log->Debug($info);
      }
   }
   public function Warn( $info )
   public function Info($info)
   {
      foreach( $this->m_arrayLog as $log )
      {
         $log->Warn( $info );
      foreach ($this->m_arrayLog as $log) {
         $log->Info($info);
      }
   }
   public function Error( $info )
   public function Warn($info)
   {
      foreach( $this->m_arrayLog as $log )
      {
         $log->Error( $info );
      foreach ($this->m_arrayLog as $log) {
         $log->Warn($info);
      }
   }
   public function Fatal( $info )
   public function Error($info)
   {
      foreach( $this->m_arrayLog as $log )
      {
         $log->Fatal( $info );
      foreach ($this->m_arrayLog as $log) {
         $log->Error($info);
      }
   }
   public function Fatal($info)
   {
      foreach ($this->m_arrayLog as $log) {
         $log->Fatal($info);
      }
   }
}
?>