Skip to content

Commit

Permalink
忽略错误
Browse files Browse the repository at this point in the history
  • Loading branch information
林文弟 committed Aug 9, 2021
1 parent 1b1e558 commit 26ec97a
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/Logger/Monolog/Handler/AliyunLogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,32 @@ public function __construct($level = Logger::DEBUG, $bubble = true)
*/
protected function write(array $record):void
{
//这里如果是error错误,阿里云日志的topic统一是error,其他都是自定义(即调用laravel自带的Log工具类时给的标识)
if ($record['level'] == Logger::ERROR) {
$topic = strtolower($record['level_name']);
} else {
$topic = $record['message'];
try {
//这里如果是error错误,阿里云日志的topic统一是error,其他都是自定义(即调用laravel自带的Log工具类时给的标识)
if ($record['level'] == Logger::ERROR) {
$topic = strtolower($record['level_name']);
} else {
$topic = $record['message'];
}
$data = [
'level' => $record['level_name'],
'method' => request()->getMethod(),
'requestUri' => request()->getPathInfo(),
'requestData' => $this->getRequestData(),
'time' => date('Y-m-d H:i:s', time()),
'topic' => $topic,
'context' => json_encode($record, JSON_UNESCAPED_UNICODE),
'ip' => request()->getClientIp(),
'header' => $this->getHeader(),
'contentType' => request()->getContentType() ?? '',
];
$logs = [new LogItem($data)];
$client = new Client($this->endpoint, $this->accessKeyId, $this->accessKeySecret);
$putLogsRequest = new PutLogsRequest($this->project, $this->logStore, $topic, $data['ip'], $logs);
$client->putLogs($putLogsRequest);
} catch (\Exception $exception) {

}
$data = [
'level' => $record['level_name'],
'method' => request()->getMethod(),
'requestUri' => request()->getPathInfo(),
'requestData' => $this->getRequestData(),
'time' => date('Y-m-d H:i:s', time()),
'topic' => $topic,
'context' => json_encode($record, JSON_UNESCAPED_UNICODE),
'ip' => request()->getClientIp(),
'header' => $this->getHeader(),
'contentType' => request()->getContentType() ?? '',
];
$logs = [new LogItem($data)];
$client = new Client($this->endpoint, $this->accessKeyId, $this->accessKeySecret);
$putLogsRequest = new PutLogsRequest($this->project, $this->logStore, $topic, $data['ip'], $logs);
$client->putLogs($putLogsRequest);
}

/**
Expand Down

0 comments on commit 26ec97a

Please sign in to comment.