public function set($key, $value, $expire = '') { $freeSpace = disk_free_space($this->config['path']); $freeSpaceMB = $freeSpace ? floor($freeSpace / 1024 / 1024) : 0; if ($freeSpaceMB < 10) { Axion_log::getinstance()->newMessage('磁盘容量过小,无法存储数据缓存文件', AXION_LOG::WARNING); return false; } $hash = md5($key); $expire = $expire ? $expire : $this->config['expire']; $expire = sprintf('%09d', $expire); $data = serialize($value); self::$_data[$hash] = $data; if (!is_dir($this->config['path'])) { if (!AXION_UTIL_FILE::mkdir($this->config['path'])) { throw new AXION_EXCEPTION('无法创建Cache文件目录:' . $this->config['path']); } } $fileName = $this->genFileName($key); if (IS_SHM && function_exists('gzcompress')) { $data = gzcompress($data, 4); } $data = $expire . $data; $result = file_put_contents($fileName, $data); if ($result) { clearstatcache(); return true; } else { return false; } }
/** * Log varible to Firebug * * @see http://www.firephp.org/Wiki/Reference/Fb * @param mixed $Object The variable to be logged * @return true Return TRUE if message was added to headers, FALSE otherwise * @throws Exception */ public function fb($Object) { if (!$this->enabled) { return false; } if (headers_sent($filename, $linenum)) { Axion_log::log("HEADER已经在{$filename的第}{$linenum行输出,无法再次输出HEADER}", Axion_log::ERROR); } $Type = null; $Label = null; if (func_num_args() == 1) { } else { if (func_num_args() == 2) { switch (func_get_arg(1)) { case self::LOG: case self::INFO: case self::WARN: case self::ERROR: case self::DUMP: case self::TRACE: case self::EXCEPTION: case self::TABLE: case self::GROUP_START: case self::GROUP_END: $Type = func_get_arg(1); break; default: $Label = func_get_arg(1); break; } } else { if (func_num_args() == 3) { $Type = func_get_arg(2); $Label = func_get_arg(1); } else { Axion_log::log("FB函数的参数数量错误!", Axion_log::ERROR); } } } if (!$this->detectClientExtension()) { return false; } $meta = array(); $skipFinalObjectEncode = false; if ($Object instanceof Exception) { $meta['file'] = $this->_escapeTraceFile($Object->getFile()); $meta['line'] = $Object->getLine(); $trace = $Object->getTrace(); if ($Object instanceof ErrorException && isset($trace[0]['function']) && $trace[0]['function'] == 'errorHandler' && isset($trace[0]['class']) && $trace[0]['class'] == 'FirePHP') { $severity = false; switch ($Object->getSeverity()) { case E_WARNING: $severity = 'E_WARNING'; break; case E_NOTICE: $severity = 'E_NOTICE'; break; case E_USER_ERROR: $severity = 'E_USER_ERROR'; break; case E_USER_WARNING: $severity = 'E_USER_WARNING'; break; case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break; case E_STRICT: $severity = 'E_STRICT'; break; case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break; case E_DEPRECATED: $severity = 'E_DEPRECATED'; break; case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break; } $Object = array('Class' => get_class($Object), 'Message' => $severity . ': ' . $Object->getMessage(), 'File' => $this->_escapeTraceFile($Object->getFile()), 'Line' => $Object->getLine(), 'Type' => 'trigger', 'Trace' => $this->_escapeTrace(array_splice($trace, 2))); $skipFinalObjectEncode = true; } else { $Object = array('Class' => get_class($Object), 'Message' => $Object->getMessage(), 'File' => $this->_escapeTraceFile($Object->getFile()), 'Line' => $Object->getLine(), 'Type' => 'throw', 'Trace' => $this->_escapeTrace($trace)); $skipFinalObjectEncode = true; } $Type = self::EXCEPTION; } else { if ($Type == self::TRACE) { $trace = debug_backtrace(); if (!$trace) { return false; } for ($i = 0; $i < sizeof($trace); $i++) { if (isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class'] == 'FirePHP' || $trace[$i]['class'] == 'FB') && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ } else { if (isset($trace[$i]['class']) && isset($trace[$i + 1]['file']) && $trace[$i]['class'] == 'FirePHP' && substr($this->_standardizePath($trace[$i + 1]['file']), -18, 18) == 'FirePHPCore/fb.php') { /* Skip fb() */ } else { if ($trace[$i]['function'] == 'fb' || $trace[$i]['function'] == 'trace' || $trace[$i]['function'] == 'send') { $Object = array('Class' => isset($trace[$i]['class']) ? $trace[$i]['class'] : '', 'Type' => isset($trace[$i]['type']) ? $trace[$i]['type'] : '', 'Function' => isset($trace[$i]['function']) ? $trace[$i]['function'] : '', 'Message' => $trace[$i]['args'][0], 'File' => isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : '', 'Line' => isset($trace[$i]['line']) ? $trace[$i]['line'] : '', 'Args' => isset($trace[$i]['args']) ? $this->encodeObject($trace[$i]['args']) : '', 'Trace' => $this->_escapeTrace(array_splice($trace, $i + 1))); $skipFinalObjectEncode = true; $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } } } } } else { if ($Type == self::TABLE) { if (isset($Object[0]) && is_string($Object[0])) { $Object[1] = $this->encodeTable($Object[1]); } else { $Object = $this->encodeTable($Object); } $skipFinalObjectEncode = true; } else { if ($Type === null) { $Type = self::LOG; } } } } if ($this->options['includeLineNumbers']) { if (!isset($meta['file']) || !isset($meta['line'])) { $trace = debug_backtrace(); for ($i = 0; $trace && $i < sizeof($trace); $i++) { if (isset($trace[$i]['class']) && isset($trace[$i]['file']) && ($trace[$i]['class'] == 'FirePHP' || $trace[$i]['class'] == 'FB') && (substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php' || substr($this->_standardizePath($trace[$i]['file']), -29, 29) == 'FirePHPCore/FirePHP.class.php')) { /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ } else { if (isset($trace[$i]['class']) && isset($trace[$i + 1]['file']) && $trace[$i]['class'] == 'FirePHP' && substr($this->_standardizePath($trace[$i + 1]['file']), -18, 18) == 'FirePHPCore/fb.php') { /* Skip fb() */ } else { if (isset($trace[$i]['file']) && substr($this->_standardizePath($trace[$i]['file']), -18, 18) == 'FirePHPCore/fb.php') { /* Skip FB::fb() */ } else { $meta['file'] = isset($trace[$i]['file']) ? $this->_escapeTraceFile($trace[$i]['file']) : ''; $meta['line'] = isset($trace[$i]['line']) ? $trace[$i]['line'] : ''; break; } } } } } } else { unset($meta['file']); unset($meta['line']); } $this->setHeader('X-Wf-Protocol-1', 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); $this->setHeader('X-Wf-1-Plugin-1', 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/' . self::VERSION); $structure_index = 1; if ($Type == self::DUMP) { $structure_index = 2; $this->setHeader('X-Wf-1-Structure-2', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); } else { $this->setHeader('X-Wf-1-Structure-1', 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); } if ($Type == self::DUMP) { $msg = '{"' . $Label . '":' . $this->jsonEncode($Object, $skipFinalObjectEncode) . '}'; } else { $msg_meta = array('Type' => $Type); if ($Label !== null) { $msg_meta['Label'] = $Label; } if (isset($meta['file'])) { $msg_meta['File'] = $meta['file']; } if (isset($meta['line'])) { $msg_meta['Line'] = $meta['line']; } $msg = '[' . $this->jsonEncode($msg_meta) . ',' . $this->jsonEncode($Object, $skipFinalObjectEncode) . ']'; } $parts = explode("\n", chunk_split($msg, 5000, "\n")); for ($i = 0; $i < count($parts); $i++) { $part = $parts[$i]; if ($part) { if (count($parts) > 2) { // Message needs to be split into multiple parts $this->setHeader('X-Wf-1-' . $structure_index . '-' . '1-' . $this->messageIndex, ($i == 0 ? strlen($msg) : '') . '|' . $part . '|' . ($i < count($parts) - 2 ? '\\' : '')); } else { $this->setHeader('X-Wf-1-' . $structure_index . '-' . '1-' . $this->messageIndex, strlen($part) . '|' . $part . '|'); } $this->messageIndex++; if ($this->messageIndex > 99999) { Axion_log::log('Maximum number (99,999) of messages reached!', Axion_log::ERROR); } } } $this->setHeader('X-Wf-1-Index', $this->messageIndex - 1); return true; }
public function failure($host, $port) { Axion_log::getinstance()->newMessage("MEMCACHED服务器{$host}:{$port发生故障}", Axion_log::WARNING); }
public static function changeMessagePollSize($num) { self::$poolLimit = $num; }
public function applicationTeminated() { $runtime = AXION_UTIL::excuteTime(); $memUseage = number_format(memory_get_usage() / 1024) . 'k'; Axion_log::log('程序执行时间:' . $runtime); Axion_log::log('本次内存使用:' . $memUseage); $logs = Axion_log::getLogPool(); if (Axion_log::isOverLimit()) { array_shift($logs); $warningMessage = "超过日志容量限制(" . axion_log::getPoolLimit() . "),日志系统将自头删除数据保障程序工作"; $warning = array('int_lv' => axion_log::WARNING, 'str_msg' => $warningMessage); array_unshift($logs, $warning); } if (IS_FIREPHP && AXION_CONFIG::get('axion.debug.usefirephp')) { $fb = AXION_UTIL_FIREPHP::getInstance(true); foreach ($logs as $v) { switch ($v['int_lv']) { case Axion_log::WARNING: $fb->warn($v['str_msg']); break; case Axion_log::NOTICE: $fb->info($v['str_msg']); break; case Axion_log::ERROR: $fb->error($v['str_msg']); break; case Axion_log::INFO: $fb->log($v['str_msg']); break; } } } else { P($logs); } }