Exemple #1
0
 /**
  * 书写Log日志
  * 当项目部署在BAE上时使用扩展服务LOG
  * 
  * @access private
  * @param string $file
  * @param string $content
  */
 private function write_log($file, $content)
 {
     if (in_array('baidu', $this->_config)) {
         require_once dirname(__FILE__) . '/LogSdk/BaeLog.class.php';
         $secret = array('user' => $this->_config['user'], 'passwd' => $this->_config['pass']);
         $logger = BaeLog::getInstance($secret);
         $logger->setLogLevel(16);
         $logger->Debug($content);
     } else {
         file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
     }
 }
Exemple #2
0
 /**
  * @brief 获取日志对象实例
  *
  * @return  BaeLog or null
  * @retval  成功的话是BaeLog对象,失败返回null 
  * @see 
  * @note 
  * @author duxi
  * @date 2011/04/01 14:30:40
  **/
 public static function getInstance($secret)
 {
     // secret can't be null
     if ($secret === null || !isset($secret['user']) || !isset($secret['passwd'])) {
         return null;
     }
     if (self::$instance === null) {
         self::$instance = new BaeLog($secret);
     }
     if (self::$instance !== null) {
         $retrytimes = 0;
         while ($retrytimes < 3 && !self::$instance->openServer()) {
             $retrytimes++;
         }
     }
     return self::$instance;
 }
Exemple #3
0
function logger2($log_content)
{
    if (isset($_SERVER['HTTP_BAE_ENV_APPID'])) {
        //BAE
        require_once "BaeLog.class.php";
        $logger = BaeLog::getInstance();
        $logger->logDebug($log_content);
    } else {
        if (isset($_SERVER['HTTP_APPNAME'])) {
            //SAE
            sae_set_display_errors(false);
            sae_debug($log_content);
            sae_set_display_errors(true);
        } else {
            $max_size = 100000;
            $log_filename = "log.xml";
            if (file_exists($log_filename) and abs(filesize($log_filename)) > $max_size) {
                unlink($log_filename);
            }
            file_put_contents($log_filename, date('H:i:s') . " " . $log_content . "\r\n", FILE_APPEND);
        }
    }
}
function log_write($log)
{
    BaeLog::getInstance()->logDebug($log);
}
Exemple #5
0
 /**
  * 获取基础服务
  * @param string $servername  调用的服务名称
  * @param string $config  映射名称,默认为default
  * @return class
  */
 public function server($servername, &$config)
 {
     switch ($servername) {
         case 'cache':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/cache
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeMemcache.class.php';
             return new BaeMemcache();
         case 'count':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/counter
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeCounter.class.php';
             return new BaeCounter();
         case 'rank':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/rank
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeRankManager.class.php';
             return BaeRankManager::getInstance();
         case 'database':
             if (!$this->isCloudSelf()) {
                 return false;
             }
             switch ($config['drive']) {
                 case 'mysql':
                     //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/mysql
                     $config['host'] = getenv('HTTP_BAE_ENV_ADDR_SQL_IP');
                     $config['port'] = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT');
                     $config['user'] = $this->accesskey;
                     $config['pass'] = $this->securekey;
                     break;
                 case 'mongodb':
                     //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/mongodb
                     $config['host'] = getenv('HTTP_BAE_ENV_ADDR_MONGO_IP');
                     $config['port'] = getenv('HTTP_BAE_ENV_ADDR_MONGO_PORT');
                     $config['user'] = $this->accesskey;
                     $config['pass'] = $this->securekey;
                     break;
                 case 'redis':
                     //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/redis
                     $config['host'] = getenv('HTTP_BAE_ENV_ADDR_REDIS_IP');
                     $config['port'] = getenv('HTTP_BAE_ENV_ADDR_REDIS_PORT');
                     $config['pass'] = $this->accesskey . '-' . $this->securekey . '' . $config['dbname'];
                     break;
             }
             break;
         case 'template':
             if (!$this->isCloudSelf()) {
                 return false;
             }
             switch ($config['drive']) {
                 case 'smarty':
                     $config['compile_dir'] = '%template/';
                     $config['cache_dir'] = '%cache/';
                     unset($config['platform']);
                     break;
             }
             break;
         case 'log':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/log
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeLog.class.php';
             /*
             //打印一条警告日志,包括日志级别和日志内容
             $logger ->logWrite(2, "this is for warning log print ");
             //打印一条轨迹日志
             $logger ->logTrace("this is for trace log print ");
             //打印一条通知日志
             $logger ->logNotice("this is for notice log print ");
             //打印一条调试日志
             $logger ->logDebug("this is for debug log print ");
             //打印一条警告日志
             $logger ->logWarning("this is for warning log print ");
             //打印一条致命日志
             $logger ->logFatal("this is for fatal log print ");
             */
             return BaeLog::getInstance();
         case 'image':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/image
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeImageService.class.php';
             return new FN_platform_baeimage();
         case 'vcode':
             //是image服务中的一款,但操作方式所以独立出来
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/image#.E9.AA.8C.E8.AF.81.E7.A0.81.E5.8A.9F.E8.83.BD.EF.BC.88.E5.8F.AA.E6.94.AF.E6.8C.81.E5.8F.82.E6.95.B0.E6.95.B0.E7.BB.84.E6.96.B9.E5.BC.8F.EF.BC.89
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeImageService.class.php';
             return new FN_platform_baeVCode();
         case 'taskqueue':
             //异步操作,一对一
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/rt/php/taskqueue
             if (!$this->isCloudSelf()) {
                 return false;
             }
             require_once 'BaeTaskQueueManager.class.php';
             return BaeTaskQueueManager::getInstance();
         case 'storage':
             //BCS云存储
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/stor/api
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeStorage($config);
         case 'queue':
             //云消息,异步操作,多对多
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/mq/api
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeQueue($config);
         case 'mail':
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/mq/api#mail
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeMail($config);
         case 'channel':
             //云推送
             //http://developer.baidu.com/wiki/index.php?title=docs/cplat/push/api
             $config['accesskey'] = $this->accesskey;
             $config['securekey'] = $this->securekey;
             return new FN_platform_baeChannel($config);
         case 'map':
             //LBS地图
             //http://lbsyun.baidu.com/
             return false;
     }
 }
Exemple #6
0
 protected function write($message, $level, $time)
 {
     BaeLog::getInstance()->logWrite($this->getBaeLogLevel($level), $message);
 }
Exemple #7
0
 static function BaeWrite($message, $level = self::ERR, $type = '', $destination = '', $extra = '')
 {
     $baeLog = BaeLog::getInstance();
     $now = date(self::$format);
     $bae_level = isset(self::$level_map[$level]) ? self::$level_map[$level] : 2;
     $msg = "{$now} " . $_SERVER['REQUEST_URI'] . " | {$level}: {$message}\r\n";
     $type = $type ? $type : C('LOG_TYPE');
     if (self::MAIL != $type) {
         // 非邮件
         $baeLog->logWrite($bae_level, $alog);
     } else {
         self::SendByBaeMail($msg, $destination, $extra);
     }
 }
Exemple #8
0
<?php

require_once dirname(__FILE__) . '/BaeLog.class.php';
$secret = array("user" => "YuguhtbbyzK2Xyi7mn5dFIaB", "passwd" => "axUoGuc5GVi6j3cDnliXB3vfFEDuZr2XD");
$log = BaeLog::getInstance($secret);
if (NULL != $log) {
    $log->setLogLevel(16);
    for ($i = 0; $i < 3; $i++) {
        $ret = $log->Fatal("lelllllllllllllll");
        if (false === $ret) {
            $code = $log->getResultCode();
            echo "{$code}<br/>";
        } else {
            echo "Success<br/>";
        }
    }
}