59 lines
1.6 KiB
PHP
59 lines
1.6 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 = null;
|
|
private static $_logBuffers = [];
|
|
public function __construct() {}
|
|
static public function getModel(): Model
|
|
{
|
|
if (self::$_model === null) {
|
|
self::$_model = new Model();
|
|
}
|
|
return self::$_model;
|
|
}
|
|
static public function log(string $message, string $level = "info"): void
|
|
{
|
|
self::$_logBuffers[] = sprintf("%s[%s]: %s", date("H:i:s"), $level, $message);
|
|
log_message($level, $message);
|
|
}
|
|
static public function info(string $message): void
|
|
{
|
|
self::log($message, 'info');
|
|
}
|
|
static public function error(string $message): void
|
|
{
|
|
self::log($message, 'error');
|
|
}
|
|
static public function warning(string $message): void
|
|
{
|
|
self::log($message, 'warning');
|
|
}
|
|
static public function debug(string $message): void
|
|
{
|
|
self::log($message, 'debug');
|
|
}
|
|
static public function dump()
|
|
{
|
|
return implode("\n", self::$_logBuffers);
|
|
}
|
|
static public function save($service, string $method, AuthService $myauth, string $title): Entity
|
|
{
|
|
$formDatas = [
|
|
'user_uid' => $myauth->getUIDByAuthInfo(),
|
|
'class_name' => $service->getClassName(),
|
|
'method_name' => $method,
|
|
'title' => $title,
|
|
'content' => implode("\n", self::$_logBuffers),
|
|
];
|
|
self::$_logBuffers = [];
|
|
return self::getModel()->create($formDatas, new Entity());
|
|
}
|
|
}
|