-
Notifications
You must be signed in to change notification settings - Fork 56
php sdk更新 #8
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
base: master
Are you sure you want to change the base?
php sdk更新 #8
Changes from 1 commit
8b0a8cb
3c28da2
91d5975
28a4487
45cedf2
cab78ce
b5b3546
cd00f2a
3535684
6c0e7ff
ef4f26d
ec57d5f
67f88e2
30ac7b1
faa0341
4215f3f
9232ddb
27208ab
c950d80
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,33 +71,50 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = | |
| * @param $logLevel | ||
| */ | ||
| public function log($logMessage, $logLevel){ | ||
| $prevoisCallTime = $this->previousLogTime; | ||
| if(NULL === $prevoisCallTime){ | ||
| $prevoisCallTime = 0; | ||
| $previousCallTime = $this->previousLogTime; | ||
|
||
| if(NULL === $previousCallTime){ | ||
| $previousCallTime = 0; | ||
|
||
| } | ||
| $this->previousLogTime = time(); | ||
| $contents = array( // key-value pair | ||
| 'time'=>date('m/d/Y h:i:s a', time()), | ||
| 'message'=> $logMessage, | ||
| 'loglevel'=> $logLevel | ||
| ); | ||
| $logItem = new Aliyun_Log_Models_LogItem(); | ||
| $logItem->setTime(time()); | ||
| $logItem->setContents($contents); | ||
| printf($logMessage.'<br>'); | ||
| if(shm_has_var($this->shm_id, 1)){ | ||
| $logItems = shm_get_var($this->shm_id, 1); | ||
| array_push($logItems, $logItem); | ||
| if(is_array($logMessage)){ | ||
| $logItemTemps = array(); | ||
| foreach ($logMessage as &$logElement){ | ||
|
||
| $contents = array( // key-value pair | ||
| 'time'=>date('m/d/Y h:i:s a', time()), | ||
|
||
| 'message'=> $logElement, | ||
| 'loglevel'=> $logLevel | ||
| ); | ||
| $logItem = new Aliyun_Log_Models_LogItem(); | ||
| $logItem->setTime(time()); | ||
| $logItem->setContents($contents); | ||
| array_push($logItemTemps, $logItem); | ||
|
|
||
| if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $prevoisCallTime > 5000) | ||
| && $prevoisCallTime > 0){ | ||
| $this->logger->logBatch($logItems, $this->topic); | ||
| $logItems = []; | ||
| } | ||
|
|
||
| shm_remove_var($this->shm_id, 1); | ||
| shm_put_var($this->shm_id, 1, $logItems); | ||
| $this->logItems = $logItems; | ||
| } | ||
| $this->logger->logBatch($logItemTemps, $this->topic); | ||
| }else{ | ||
| $contents = array( // key-value pair | ||
| 'time'=>date('m/d/Y h:i:s a', time()), | ||
| 'message'=> $logMessage, | ||
| 'loglevel'=> $logLevel | ||
| ); | ||
| $logItem = new Aliyun_Log_Models_LogItem(); | ||
| $logItem->setTime(time()); | ||
| $logItem->setContents($contents); | ||
| if(shm_has_var($this->shm_id, 1)){ | ||
| $logItems = shm_get_var($this->shm_id, 1); | ||
| array_push($logItems, $logItem); | ||
|
|
||
| if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $previousCallTime > 5000) | ||
| && $previousCallTime > 0){ | ||
| $this->logger->logBatch($logItems, $this->topic); | ||
| $logItems = []; | ||
| } | ||
|
|
||
| shm_remove_var($this->shm_id, 1); | ||
| shm_put_var($this->shm_id, 1, $logItems); | ||
| $this->logItems = $logItems; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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));