|
|
@@ -13,19 +13,21 @@ use App\Traits\ServiceAppAop;
|
|
|
class LogService
|
|
|
{
|
|
|
use ServiceAppAop;
|
|
|
- protected $modelClass=Log::class;
|
|
|
- static public function log($class, $method, $description, $id_user = null,$type='log')
|
|
|
+
|
|
|
+ protected $modelClass = Log::class;
|
|
|
+
|
|
|
+ static public function log($class, $method, $description, $id_user = null, $type = 'log')
|
|
|
{
|
|
|
- $passingMethods=config('logging.passing_methods');
|
|
|
- foreach ($passingMethods as $passingMethod){
|
|
|
- if($passingMethod==$method)return;
|
|
|
+ $passingMethods = config('logging.passing_methods');
|
|
|
+ foreach ($passingMethods as $passingMethod) {
|
|
|
+ if ($passingMethod == $method) return;
|
|
|
}
|
|
|
if (!$id_user) {
|
|
|
$id_user = '';
|
|
|
$user = auth()->user();
|
|
|
if ($user) $id_user = $user['id'];
|
|
|
}
|
|
|
- $log=new Log([
|
|
|
+ $log = new Log([
|
|
|
'class' => $class,
|
|
|
'method' => $method,
|
|
|
'description' => $description,
|
|
|
@@ -41,8 +43,8 @@ class LogService
|
|
|
return;
|
|
|
}
|
|
|
$date = date('Y-m-d H:i:s');
|
|
|
- $log['created_at']=$date;
|
|
|
- $log['updated_at']=$date;
|
|
|
+ $log['created_at'] = $date;
|
|
|
+ $log['updated_at'] = $date;
|
|
|
Redis::LPUSH('LOGS', $log);
|
|
|
}
|
|
|
|
|
|
@@ -60,7 +62,10 @@ class LogService
|
|
|
while (Redis::LLEN('LOGS') > 0) {
|
|
|
$log = Redis::LPOP('LOGS');
|
|
|
$arr = json_decode($log);
|
|
|
- $description = (is_string($arr->description)?$arr->description:json_encode($arr->description))??'';
|
|
|
+ if (empty($arr)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $description = (is_string($arr->description) ? $arr->description : json_encode($arr->description)) ?? '';
|
|
|
if ($length + strlen($description) > 1024 * 512) {
|
|
|
Log::query()->insert($data);
|
|
|
$length = 0;
|