예제 #1
0
파일: Log.php 프로젝트: drehere/shenmegui
 private function writeLog($intLevel, $str, $errno = 0, $arrArgs = null, $depth = 0, $filename_suffix = '', $log_format = null)
 {
     if ($intLevel > $this->intLevel || !isset(self::$arrLogLevels[$intLevel])) {
         return;
     }
     //log file name
     $strLogFile = $this->strLogFile;
     if ($intLevel & self::LOG_LEVEL_WARNING || $intLevel & self::LOG_LEVEL_FATAL) {
         $strLogFile .= '.wf';
     }
     $strLogFile .= $filename_suffix;
     //assign data required
     $this->current_log_level = self::$arrLogLevels[$intLevel];
     //build array for use as strargs
     $_arr_args = false;
     $_add_notice = false;
     if (is_array($arrArgs) && count($arrArgs) > 0) {
         $_arr_args = true;
     }
     if (!empty($this->addNotice)) {
         $_add_notice = true;
     }
     if ($_arr_args && $_add_notice) {
         //both are defined, merge
         $this->current_args = $arrArgs + $this->addNotice;
     } else {
         if (!$_arr_args && $_add_notice) {
             //only add notice
             $this->current_args = $this->addNotice;
         } else {
             if ($_arr_args && !$_add_notice) {
                 //only arr args
                 $this->current_args = $arrArgs;
             } else {
                 //empty
                 $this->current_args = array();
             }
         }
     }
     $this->current_err_no = $errno;
     $this->current_err_msg = $str;
     $trace = debug_backtrace();
     $depth2 = $depth + 1;
     if ($depth >= count($trace)) {
         $depth = count($trace) - 1;
         $depth2 = $depth;
     }
     $this->current_file = isset($trace[$depth]['file']) ? $trace[$depth]['file'] : "";
     $this->current_line = isset($trace[$depth]['line']) ? $trace[$depth]['line'] : "";
     $this->current_function = isset($trace[$depth2]['function']) ? $trace[$depth2]['function'] : "";
     $this->current_class = isset($trace[$depth2]['class']) ? $trace[$depth2]['class'] : "";
     $this->current_function_param = isset($trace[$depth2]['args']) ? $trace[$depth2]['args'] : "";
     self::$current_instance = $this;
     //get the format
     if ($log_format == null) {
         $format = $this->getFormat($intLevel);
     } else {
         $format = $log_format;
     }
     $str = $this->getLogString($format);
     if ($this->bolAutoRotate) {
         $strLogFile .= '.' . date('YmdH');
     }
     return file_put_contents($strLogFile, $str, FILE_APPEND);
 }