Пример #1
0
 public function testFatal()
 {
     $fileName = self::LOG_DIR . 'didi.log.wf';
     $logMsg = 'Test fatal';
     $logArgs = array('a' => 'a', 'b' => 1);
     $logId = Utils\Logger::getLogId();
     $logErrorNo = 101;
     $expectedResult = array('[FATAL]' => null, 'logId' => $logId, 'errno' => $logErrorNo, 'msg' => $logMsg, 'ip' => '127.0.0.1', 'uri' => '');
     $expectedResult = array_merge($expectedResult, $logArgs);
     @unlink($fileName);
     Utils\Logger::setLogId($logId);
     Utils\Logger::fatal($logMsg, $logErrorNo, $logArgs);
     $logMsg2 = 'Test fatal1';
     $logArgs2 = array('h' => 'e', 'aaab' => 1);
     $logId = Utils\Logger::getLogId();
     $logErrorNo2 = 102;
     $expectedResult2 = array('[FATAL]' => null, 'logId' => $logId, 'errno' => $logErrorNo2, 'msg' => $logMsg2, 'ip' => '127.0.0.1', 'uri' => '');
     $expectedResult2 = array_merge($expectedResult2, $logArgs2);
     Utils\Logger::setLogId($logId);
     Utils\Logger::fatal($logMsg2, $logErrorNo2, $logArgs2);
     $logContents = file_get_contents($fileName);
     $logLines = explode(PHP_EOL, $logContents);
     $this->assertEquals(count($logLines), 3, 'log line count not equal to 3');
     $actualResult = $this->parseLog(str_replace(PHP_EOL, '', $logLines[0]));
     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));
     $actualResult2 = $this->parseLog(str_replace(PHP_EOL, '', $logLines[1]));
     unset($actualResult2['time']);
     unset($actualResult2['line']);
     $diff2 = array_diff_assoc($actualResult2, $expectedResult2);
     $this->assertEquals(count($diff2), 0, 'actual result differs from expected: ' . var_export($diff2, true));
     $this->assertTrue(empty($logLines[2]), 'line 3 in log file not empty');
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
         }
     }
 }
Пример #4
0
$loader->addPsr4('Xiaoju\\Beatles\\Utils\\', FRAMEPATH . 'libraries');
$loader->addPsr4('Xiaoju\\Beatles\\Utils\\', FRAMEPATH . 'config');
$errNo = 0;
$errMsg = '';
$__uid = 0;
try {
    //生成全局的logid
    \Xiaoju\Beatles\Utils\Logger::create($logConfig['intLevel'], $logConfig['strLogFile'], $logConfig['intMaxFileSize']);
    \Xiaoju\Beatles\Utils\Logger::setLogId(Xiaoju\Beatles\Utils\Logger::getLogId());
    $params = array('get' => $_GET, 'post' => $_POST);
    register_shutdown_function('logFinish', $params);
    $routerConfig = $appNameSpace . '\\Config\\Route';
    if (class_exists($routerConfig) && is_array($routerConfig::$routes)) {
        $routerConfig = $routerConfig::$routes;
    } else {
        $routerConfig = array();
    }
    $router = new \Xiaoju\Beatles\Framework\Base\Router($_SERVER['REQUEST_URI'], $routerConfig);
    $router->setRoute();
    $router->run($params);
} catch (\InvalidArgumentException $ex) {
    $errNo = -1;
    $errMsg = strlen($ex->getMessage()) ? $ex->getMessage() : 'system error';
    \Xiaoju\Beatles\Utils\Logger::fatal($errMsg, $errNo, array('in' => json_encode($params), 'out' => ob_get_contents()));
    echo \Xiaoju\Beatles\Utils\Formatter::format(array('errno' => $errNo, 'errmsg' => $errMsg));
} catch (\Exception $ex) {
    $errNo = $ex->getCode();
    $errMsg = $ex->getMessage();
    \Xiaoju\Beatles\Utils\Logger::warning($errMsg, $errNo, array('in' => json_encode($params), 'out' => ob_get_contents()));
    echo \Xiaoju\Beatles\Utils\Formatter::format(array('errno' => $errNo, 'errmsg' => $errMsg));
}