Ejemplo n.º 1
0
 /**
  * @param string|\Exception $msg
  * @param array $context
  * @throws \RuntimeException
  */
 public static function fatal($msg, array $context = array())
 {
     if (empty(static::$instance)) {
         throw new \RuntimeException('Logger instance not added to proxy yet');
     }
     static::$instance->fatal($msg, $context);
 }
 /**
  * Add an image
  *
  * @access public
  * @param array $dats Image to add and paramaters to use
  * @deprecated
  */
 public function fAddImage($dats = '')
 {
     try {
         if (isset($dats['name']) && file_exists($dats['name']) == 'true') {
             $attrImage = getimagesize($dats['name']);
             try {
                 if ($attrImage['mime'] == 'image/jpg' || $attrImage['mime'] == 'image/jpeg' || $attrImage['mime'] == 'image/png' || $attrImage['mime'] == 'image/gif') {
                     self::$intIdWord++;
                     $image = CreateImage::getInstance();
                     $dats['rId'] = self::$intIdWord;
                     $image->createImage($dats);
                     $this->_wordDocumentC .= (string) $image;
                     $dir = $this->parsePath($dats['name']);
                     $this->_zipDocx->addFile($dats['name'], 'word/media/image' . self::$intIdWord . '.' . $dir['extension']);
                     $this->generateDEFAULT($dir['extension'], $attrImage['mime']);
                     if ((string) $image != '') {
                         $this->_wordRelsDocumentRelsC .= $this->generateRELATIONSHIP('rId' . self::$intIdWord, 'image', 'media/image' . self::$intIdWord . '.' . $dir['extension']);
                     }
                 } else {
                     throw new Exception('Image format is not supported.');
                 }
             } catch (Exception $e) {
                 self::$log->fatal($e->getMessage());
                 exit;
             }
         } else {
             throw new Exception('Image does not exist.');
         }
     } catch (Exception $e) {
         self::$log->fatal($e->getMessage());
         exit;
     }
 }
Ejemplo n.º 3
0
 private static function logConnectionError($args)
 {
     if (class_exists('Xiaoju\\Beatles\\Utils\\Logger')) {
         $msg = 'redis connection failed';
         $errorNo = -1;
         Logger::fatal($msg, $errorNo, $args);
     }
 }
Ejemplo n.º 4
0
 function execute($pipe)
 {
     if (!isset($this->arr_pipe[$pipe])) {
         Logger::fatal('pipe.err not run the pipe: %s', var_export($pipe, true));
         return false;
     }
     $pipe_obj = $this->arr_pipe[$pipe];
     if ($pipe_obj->execute($this->app) === false) {
         Logger::fatal('pipe.err execute error for the pipe: %s', var_export($pipe, true));
         return false;
     }
     return true;
 }
 public function testLogLevel()
 {
     $rootAppender = new LoggerAppenderTest();
     $root = new Logger('root');
     $root->addAppender($rootAppender);
     $logger = new Logger('logger', $root);
     $logger->trace('trace');
     $logger->debug('debug');
     $logger->info('info');
     $logger->warn('warn');
     $logger->error('error');
     $logger->fatal('fatal');
     $this->assertEquals(array(array(Logger::TRACE, 'trace'), array(Logger::DEBUG, 'debug'), array(Logger::INFO, 'info'), array(Logger::WARN, 'warn'), array(Logger::ERROR, 'error'), array(Logger::FATAL, 'fatal')), $rootAppender->logs);
 }
Ejemplo n.º 6
0
 private static function createMysqli($server)
 {
     // 创建mysqli对象
     $mysqli = @new \mysqli($server['host'], $server['username'], $server['password'], '', $server['port']);
     for ($i = 1; $i < 3 && $mysqli->connect_error; $i++) {
         usleep(50000);
         $mysqli = @new \mysqli($server['host'], $server['username'], $server['password'], '', $server['port']);
     }
     // 连接失败,记录日志
     if ($mysqli->connect_error) {
         Logger::fatal('mysql', $mysqli->connect_error);
         throw new LibraryException($mysqli->connect_error);
     }
     return $mysqli;
 }
Ejemplo n.º 7
0
 /**
  * Get queue manager
  *
  * @param string $monitorPath
  * @param string $dataPath
  * @return object
  */
 public static function getQueueManager($monitorPath, $dataPath)
 {
     $monitor = new Queue_Monitor($monitorPath);
     $implement = new QueueImpl_File($dataPath);
     if ($implement->error()) {
         Logger::fatal('Get queue impl failure,error: ' . $implement->error());
         return false;
     }
     $manager = new Queue_Manager($monitor, $implement);
     if ($manager->error()) {
         Logger::fatal('Get queue manager failure,error: ' . $manager->error());
         return false;
     }
     return $manager;
 }
Ejemplo n.º 8
0
 public function rollback()
 {
     if (!$this->inTrans) {
         throw new LibraryException('当前连接没有开启事务,无法回滚!');
     }
     // 回滚失败可能造成mysql锁死
     $ret = $this->mysqli->rollback();
     if (false === $ret) {
         $msg = '回滚事务失败!' . $this->mysqli->error;
         Logger::fatal('mysql', $msg);
         throw new LibraryException($msg);
     }
     $this->inTrans = false;
     return $ret;
 }
Ejemplo n.º 9
0
Archivo: Api.php Proyecto: hihus/pi
 function exceptionHandler($ex)
 {
     restore_exception_handler();
     $errcode = $ex->getMessage();
     $code = $ex->getCode();
     if ($this->needToLog($code)) {
         $errmsg = sprintf('<<  exception:%s, errcode:%s, trace: %s >>', $code, $errcode, $ex->__toString());
         if ($pos = strpos($errcode, ' ')) {
             $errcode = substr($errcode, 0, $pos);
         }
         $this->status = $errcode;
         Logger::fatal($errmsg);
     }
     //内部export调用不需要做异常输出处理. 和ApiRouter.php的output错误输出格式一致
     if (!defined('USE_INNER_API')) {
         echo json_encode(array('msg' => $errcode, PI_INNER_ERR => $code), true);
     }
 }
Ejemplo n.º 10
0
 public static function logError($type, $msg, $file, $line)
 {
     $str = LogVars::$friendlyErrorType[$type] . ': ' . $msg . ' ' . $file . ':' . $line;
     if (in_array($type, LogVars::$warnType)) {
         Logger::warn('handle', $str);
     } else {
         if (in_array($type, LogVars::$errorType)) {
             Logger::error('handle', $str);
             Url::redirect404();
         } else {
             if (in_array($type, LogVars::$noticeType)) {
                 Logger::notice('handle', $str);
             } else {
                 Logger::fatal('handle', $str);
                 Url::redirect404();
             }
         }
     }
     return true;
 }
Ejemplo n.º 11
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;
         }
     }
 }
Ejemplo n.º 12
0
 public static function makeResetTicket($loginName)
 {
     $memcached = MemcachedPool::getMemcached(MemcachedConfig::$SERVER_COMMON);
     // 生成唯一的md5,最多执行3次
     $i = 0;
     do {
         $resetTicket = md5(uniqid($loginName, true));
         $key = MemcachedKeys::UC_RESET_TICKET_ . $resetTicket;
         $ret = $memcached->get($key);
         if (false === $ret) {
             $memcached->set($key, $loginName, 1800);
             // resetTicket半小时有效
             break;
         }
         $i++;
     } while (true);
     // 发生碰撞
     if ($i >= 3) {
         Logger::fatal('interface.error.uc', "设置resetTicket次数为{$i}!");
     }
     return $resetTicket;
 }
Ejemplo n.º 13
0
 /**
  * Stops recording through shell scripts
  * 
  * @return int
  */
 function stopRecording()
 {
     if (!$this->isRecording()) {
         return self::ERR_ALREADY;
     }
     $cmd = "sudo " . APP_ROOT . "/sh/stop_recording";
     // Attempt to run bash stop command
     exec("sudo " . WEB_ROOT . "/sh/stop_recording", $output, $return_var);
     // Failed ?
     if (0 !== $return_var) {
         $this->logger->fatal("errcode:" . $return_var . " cmd: {$cmd} output:" . print_r($output, 1));
         return self::ERR_FATAL;
     }
     // Wait for capture to stop
     sleep(1);
     // Failed ?
     if (!$this->isRecording()) {
         return self::ERR_OK;
     } else {
         $this->logger->fatal("errcode:" . $return_var . " cmd: {$cmd} output:" . print_r($output, 1));
         return self::ERR_FATAL;
     }
 }
Ejemplo n.º 14
0
 /**
  * Scans order by to ensure that any field being ordered by is.
  *
  * It will throw a warning error to the log file - fatal if slow query logging is enabled
  *
  * @param  string $sql         query to be run
  * @param  bool   $object_name optional, object to look up indices in
  * @return bool   true if an index is found false otherwise
  */
 protected function checkQuery($sql, $object_name = false)
 {
     $match = array();
     preg_match_all("'.* FROM ([^ ]*).* ORDER BY (.*)'is", $sql, $match);
     $indices = false;
     if (!empty($match[1][0])) {
         $table = $match[1][0];
     } else {
         return false;
     }
     if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) {
         $indices = $GLOBALS['dictionary'][$object_name]['indices'];
     }
     if (empty($indices)) {
         foreach ($GLOBALS['dictionary'] as $current) {
             if ($current['table'] == $table) {
                 $indices = $current['indices'];
                 break;
             }
         }
     }
     if (empty($indices)) {
         $this->log->warn('CHECK QUERY: Could not find index definitions for table ' . $table);
         return false;
     }
     if (!empty($match[2][0])) {
         $orderBys = explode(' ', $match[2][0]);
         foreach ($orderBys as $orderBy) {
             $orderBy = trim($orderBy);
             if (empty($orderBy)) {
                 continue;
             }
             $orderBy = strtolower($orderBy);
             if ($orderBy == 'asc' || $orderBy == 'desc') {
                 continue;
             }
             $orderBy = str_replace(array($table . '.', ','), '', $orderBy);
             foreach ($indices as $index) {
                 if (empty($index['db']) || $index['db'] == $this->dbType) {
                     foreach ($index['fields'] as $field) {
                         if ($field == $orderBy) {
                             return true;
                         }
                     }
                 }
             }
             $warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy;
             if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) {
                 $this->log->fatal('CHECK QUERY:' . $warning);
             } else {
                 $this->log->warn('CHECK QUERY:' . $warning);
             }
         }
     }
     return false;
 }
Ejemplo n.º 15
0
Archivo: App.php Proyecto: xtzlyp/newpi
 function exceptionHandler($ex)
 {
     restore_exception_handler();
     $errcode = $ex->getMessage();
     $code = $ex->getCode();
     if ($this->needToLog($code)) {
         $errmsg = sprintf('<< exception:%s, errcode:%s, trace: %s >>', $code, $errcode, $ex->__toString());
         if ($pos = strpos($errcode, ' ')) {
             $errcode = substr($errcode, 0, $pos);
         }
         $this->status = $errcode;
         Logger::fatal($errmsg);
     }
 }
 /**
  * checkObjectClassTypeCorrect checks that the object at the head of the stack is an instance
  * of the correct type (class). It's s quick and dirty way to ensure that the xml file / stack
  * are being processed properly. It is possible that a subclass of this class repositions the
  * stack incorrectly. An exception is thrown if the stack isn't in sync as the code becomes
  * unpredicatable if this occurs.
  *
  * @param Noark5object $className
  * @return true if the object at the head of the stack is an instance of the class specified in $className
  */
 protected function checkObjectClassTypeCorrect($className)
 {
     if (strcmp($className, get_class(end($this->stack))) != 0) {
         $this->logger->fatal('Error processing arkivstruktur.xml. Unsafe to continue Expected (' . $className . ') found (' . get_class(end($this->stack)) . '). Unsafe processing.');
         throw new Exception('Error processing arkivstruktur.xml. Unsafe to continue Expected (' . $className . ') found (' . get_class(end($this->stack)) . '). Unsafe processing.');
     }
     return true;
 }
Ejemplo n.º 17
0
 /**
  * Condições críticas.
  *
  * @param string $message
  * @param array $context
  * @return null
  */
 public function critical($message, array $context = array())
 {
     $this->logger->fatal($this->interpolate($message, $context));
 }
Ejemplo n.º 18
0
 /**
  * Starts daemon
  *
  * @return bool
  */
 public function start()
 {
     if (!defined('SIGHUP')) {
         $this->error('PHP is compiled without --enable-pcntl directive');
         Logger::fatal($this->error());
         return false;
     }
     // Check for CLI
     if (php_sapi_name() !== 'cli') {
         $this->error('You can only create daemon from the command line (CLI-mode)');
         Logger::fatal($this->error());
         return false;
     }
     // Check for POSIX
     if (!function_exists('posix_getpid')) {
         $this->error('PHP is compiled without --enable-posix directive');
         Logger::fatal($this->error());
         return false;
     }
     Logger::trace('Starting daemon');
     if (!$this->daemonize()) {
         Logger::error('Could not start daemon');
         return false;
     }
     Logger::trace('Running...');
     $this->isRunning = true;
     return true;
 }