-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
php sdk更新 #8
base: master
Are you sure you want to change the base?
php sdk更新 #8
Conversation
php 7.1.7测试通过 |
Aliyun/Log/Logger.php
Outdated
$request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, | ||
$topic, $ip, $logItems); | ||
$response = $this->client->putLogs($request); | ||
print($response ->getRequestId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉print
Aliyun/Log/Logger.php
Outdated
@@ -39,9 +39,23 @@ public function log($logLevel, $logMessage, $topic){ | |||
$response = $this->client->putLogs($request); | |||
print($response ->getRequestId()); | |||
} catch (Aliyun_Log_Exception $ex) { | |||
logVarDump($ex); | |||
var_dump($ex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所有的exception 都直接throw 出去,不要dump 下来
Aliyun/Log/Models/LogBatch.php
Outdated
|
||
public function log($logMessage, $logLevel){ | ||
$contents = array( // key-value pair | ||
'time'=>date('m/d/Y h:i:s a', time()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
时间不需要了,默认已经有了
Aliyun/Log/Models/LogBatch.php
Outdated
$logItem = new Aliyun_Log_Models_LogItem(); | ||
$logItem->setTime(time()); | ||
$logItem->setContents($contents); | ||
printf($logMessage.'<br>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉print
Aliyun/Log/Models/LogBatch.php
Outdated
$logItem = new Aliyun_Log_Models_LogItem(); | ||
$logItem->setTime(time()); | ||
$logItem->setContents($contents); | ||
printf($logMessage.'<br>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
去掉
Aliyun/Log/Models/LogBatch.php
Outdated
$this->arraySize = 5; | ||
} | ||
$this->logger = $logger; | ||
if($sem_id == null || $shm_id == null){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果sem_id , shm_id 等不为null的情况,会怎么样?
Aliyun/Log/Models/LogBatch.php
Outdated
} | ||
|
||
public function log($logMessage, $logLevel){ | ||
$prevoidCallTime = $this->previousLogTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个更新逻辑有问题, 只有发送的时候,才真正更新
Aliyun/Log/Models/LogBatch.php
Outdated
$SEMKEY = 22 + time(); | ||
$SHMKEY = 33 + time(); | ||
|
||
$this->sem_id = sem_get($SEMKEY, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这边是否会遇到都线程同时操作这个logger对象的问题(这个我不是和确定),如果没有多线程问题,可以不加锁
Aliyun/Log/Models/LogBatch.php
Outdated
} | ||
shm_put_var($this->shm_id, 1, $this->logItems); | ||
|
||
} | ||
|
||
public function log($logMessage, $logLevel){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于log的话,单个message 有点太简单了,也可以直接同时写入多个key:value的模式 , 单个message 是一种特例。
可以提供一个log(level, array)的接口 , log(level, message) => log (leve , array("msg"=>message));
|
Aliyun/Log/Models/LogBatch.php
Outdated
array_push($logItems, $logItem); | ||
if(is_array($logMessage)){ | ||
$logItemTemps = array(); | ||
foreach ($logMessage as &$logElement){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当这个作为一个array的时候, 是一条message, 而不是多条,一条message 可以有多个key,value。
传入的是array(其实是一个map)。
Aliyun/Log/Models/LogBatch.php
Outdated
$logItemTemps = array(); | ||
foreach ($logMessage as &$logElement){ | ||
$contents = array( // key-value pair | ||
'time'=>date('m/d/Y h:i:s a', time()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这边的time 字段不需要了,下面有
Aliyun/Log/Models/LogBatch.php
Outdated
$prevoisCallTime = 0; | ||
$previousCallTime = $this->previousLogTime; | ||
if(NULL === $previousCallTime){ | ||
$previousCallTime = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个时间的判断逻辑有问题,修改如下:
- previousCallTime = time() 初始的时候
- 每次调用一次log, 检查 time() - previousCallTime > xxx 是否满足
- 如果满足 send data, 并且更新previousCallTime = time()
- 如果第二不检查不满足, 则不send data, 也不更新 previousCallTime。
Aliyun/Log/Models/LogBatch.php
Outdated
$prevoisCallTime = $this->previousLogTime; | ||
if(NULL === $prevoisCallTime){ | ||
$prevoisCallTime = 0; | ||
$previousCallTime = $this->previousLogTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为了易用,这个log 接口,可以再加一个bool的参数, use_buffer (默认为true),如果设置为false, 这立刻flush出去
Aliyun/Log/LoggerFactory.php
Outdated
} | ||
if($logstore === null || $logstore == ''){ | ||
throw new Exception('logstore name is blank!'); | ||
} | ||
if($topic === null){ | ||
$topic = 'MainFlow'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if topic == NULL => topic = ""
Aliyun/Log/LoggerFactory.php
Outdated
} | ||
return static::$instanceSimpleLogger; | ||
return static::$loggerMap[$loggerKey]; | ||
} | ||
|
||
protected function __construct() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
析构的时候, 检查一下每个logger 中,是否还要没有发送出去的数据,如果有的话,需要发送出去
Aliyun/Log/SimpleLogger.php
Outdated
@@ -54,7 +63,7 @@ protected function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount | |||
* @param $logLevel | |||
* @param $topic should be null | |||
*/ | |||
public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage, $topic = null){ | |||
public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage){ | |||
$previousCallTime = $this->previousLogTime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
previousCallTime 只有每次发送之后,才更新,不是每次调用log 就更新
Aliyun/Log/SimpleLogger.php
Outdated
@@ -73,7 +82,7 @@ public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage, $ | |||
$logItem->setContents($contents); | |||
array_push($logItemTemps, $logItem); | |||
} | |||
$this->logger->logBatch($logItemTemps, $this->topic); | |||
$this->logBatch($logItemTemps, $this->topic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是每次都发送, 每次都是buffer 到cahce中。
Aliyun/Log/SimpleLogger.php
Outdated
$logItems = []; | ||
} | ||
$this->logItems = $logItems; | ||
} | ||
} | ||
|
||
public function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logSingleMessage 和 logArrayMessage 如果保留的话, 前面那个log 函数就删除掉。
这两个函数都是把数据保存到cache中
1、把request、response相关类移到对应文件夹,保持目录清爽
2、增加logger方式调用以及loglevel枚举
3、问题修复,自测通过