mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
namespace App\Logging;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Monolog\Handler\AbstractProcessingHandler;
|
|
use Monolog\Logger;
|
|
use App\Models\Log as LogModel;
|
|
|
|
class MysqlLoggerHandler extends AbstractProcessingHandler
|
|
{
|
|
public function __construct($level = Logger::DEBUG, bool $bubble = true)
|
|
{
|
|
parent::__construct($level, $bubble);
|
|
}
|
|
|
|
protected function write(array $record): void
|
|
{
|
|
try{
|
|
if(isset($record['context']['exception']) && is_object($record['context']['exception'])){
|
|
$record['context']['exception'] = (array)$record['context']['exception'];
|
|
}
|
|
$record['request_data'] = request()->all() ??[];
|
|
$log = [
|
|
'title' => $record['message'],
|
|
'level' => $record['level_name'],
|
|
'host' => $record['request_host'] ?? request()->getSchemeAndHttpHost(),
|
|
'uri' => $record['request_uri'] ?? request()->getRequestUri(),
|
|
'method' => $record['request_method'] ?? request()->getMethod(),
|
|
'ip' => request()->getClientIp(),
|
|
'data' => json_encode($record['request_data']) ,
|
|
'context' => isset($record['context']) ? json_encode($record['context']) : '',
|
|
'created_at' => strtotime($record['datetime']),
|
|
'updated_at' => strtotime($record['datetime']),
|
|
];
|
|
|
|
LogModel::insert(
|
|
$log
|
|
);
|
|
}catch (\Exception $e){
|
|
Log::channel('daily')->error($e->getMessage().$e->getFile().$e->getTraceAsString());
|
|
}
|
|
}
|
|
}
|