/** * Created by PhpStorm. * User: lenovo * Date: 2015/1/8 * Time: 0:09 */ function logFinish($in) { //这里由于没有做ob_start,如果输出的数据太大超出缓冲区被自动flush出去的话, ob_get_contents拿到的数据就是空的 //日志里的out就是空 global $__uid; $in['__uid'] = $__uid; \Xiaoju\Beatles\Utils\Logger::notice('', 0, array('in' => json_encode($in), 'out' => ob_get_contents())); }
public function reserve($tube) { try { $t1 = microtime(true); self::$pool[self::$key]->watch($tube); $job = self::$pool[self::$key]->reserve(0); $t2 = microtime(true); $duration = $t2 - $t1; if (is_object($job) && method_exists($job, 'getData')) { self::logOperation('reserve', array('reserve', $tube), $duration, $job->getData()); } else { self::logOperation('reserve', array('reserve', $tube), $duration, ''); } } catch (\Exception $e) { Utils\Logger::fatal($e->getMessage(), $e->getCode(), array('location' => __CLASS__ . '_' . __METHOD__ . '_' . __LINE__)); throw new \Exception(self::$messages[self::PHEANTALK_RESERVE_ERROR], self::PHEANTALK_RESERVE_ERROR); } return $job; }
/** * @param $method * @param $arguments * @param $duration * @param $return */ private function logOperation($method, $arguments, $duration, $return) { $params['cost'] = $duration; $operValue = json_encode($arguments); $length = strlen($operValue); if ($length > self::LOG_TRUNCATION_LEN) { $operValue = substr($operValue, 0, self::LOG_TRUNCATION_LEN) . '...'; } $params['operName'] = $method; $params['operValue'] = $operValue; $params['operLength'] = $length; if (!empty($return)) { $returnValue = json_encode($return); $length = strlen($returnValue); if ($length > self::LOG_TRUNCATION_LEN) { $returnValue = substr($returnValue, 0, self::LOG_TRUNCATION_LEN) . '...'; } $params['resultValue'] = $returnValue; $params['resultLength'] = $length; } Logger::warning('thrift_operation_' . $this->tag . '_trace', 0, $params); }
private static function log($type, $msg, $errorNo, $params) { if (class_exists('Xiaoju\\Beatles\\Utils\\Logger')) { switch ($type) { case 'debug': Logger::debug($msg, $errorNo, $params); break; case 'trace': Logger::trace($msg, $errorNo, $params); break; case 'notice': Logger::notice($msg, $errorNo, $params); break; case 'warning': Logger::warning($msg, $errorNo, $params); break; case 'fatal': Logger::fatal($msg, $errorNo, $params); break; } } }
public function testNoArg() { $fileName = self::LOG_DIR . 'didi.log.wf'; $logMsg = 'Test no argument'; $logId = Utils\Logger::getLogId(); $logErrorNo = 120; $expectedResult = array('[WARNING]' => null, 'logId' => $logId, 'errno' => $logErrorNo, 'msg' => $logMsg, 'ip' => '127.0.0.1', 'uri' => ''); @unlink($fileName); Utils\Logger::setLogId($logId); Utils\Logger::warning($logMsg, $logErrorNo); $logContents = file_get_contents($fileName); $actualResult = $this->parseLog(str_replace(PHP_EOL, '', $logContents)); unset($actualResult['time']); unset($actualResult['line']); $diff = array_diff_assoc($actualResult, $expectedResult); $this->assertEquals(count($diff), 0, 'actual result differs from expected: ' . var_export($diff, true)); }
private static function logOperation($method, $arguments, $duration, $return) { $params['cost'] = $duration; $operValue = implode(' ', $arguments); $length = strlen($operValue); if ($length > self::LOG_TRUNCATION_LEN) { $operValue = substr($operValue, 0, self::LOG_TRUNCATION_LEN) . '...'; } $params['operName'] = $method; $params['operValue'] = $operValue; $params['operLength'] = $length; if (!empty($return)) { $returnValue = strval($return); $length = strlen($returnValue); if ($length > self::LOG_TRUNCATION_LEN) { $returnValue = substr($returnValue, 0, self::LOG_TRUNCATION_LEN) . '...'; } $params['resultValue'] = $returnValue; $params['resultLength'] = $length; } if (class_exists('Xiaoju\\Beatles\\Utils\\Logger')) { Logger::warning('pheanstalk operation', 0, $params); } }