50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Entities\MyLogEntity as Entity;
|
|
use App\Models\MyLogModel as Model;
|
|
use App\Services\Auth\AuthService;
|
|
|
|
class MyLogService
|
|
{
|
|
private static ?Model $_model = null;
|
|
private static $_logBuffers = [];
|
|
public function __construct() {}
|
|
final public function getClassName(): string
|
|
{
|
|
return "MyLog";
|
|
}
|
|
final public function getClassPath(): string
|
|
{
|
|
return $this->getClassName();
|
|
}
|
|
static public function getModel(): Model
|
|
{
|
|
if (self::$_model === null) {
|
|
self::$_model = new Model();
|
|
}
|
|
return self::$_model;
|
|
}
|
|
static public function add(string $level, string $message): void
|
|
{
|
|
self::$_logBuffers[] = sprintf("%s[%s]: %s", date("H:i:s"), $level, $message);
|
|
log_message($level, $message);
|
|
}
|
|
|
|
static public function save($service, string $method, AuthService $myauth, string $title, string $status = "unuse"): Entity
|
|
{
|
|
$formDatas = [
|
|
'user_uid' => $myauth->getUIDByAuthInfo(),
|
|
'class_name' => $service->getClassName(),
|
|
'method_name' => $method,
|
|
'title' => $title,
|
|
'content' => implode("\n", self::$_logBuffers),
|
|
'status' => $status,
|
|
];
|
|
self::$_logBuffers = [];
|
|
// dd($formDatas);
|
|
return self::getModel()->create($formDatas, new Entity());
|
|
}
|
|
}
|