This commit is contained in:
Saeed Vaziry
2024-03-24 09:56:34 +01:00
committed by GitHub
parent 884f18db63
commit 4d051330d6
1055 changed files with 14493 additions and 20278 deletions

View File

@ -4,6 +4,7 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
@ -15,7 +16,6 @@
* @property string $disk
* @property Server $server
* @property ?Site $site
* @property string $content
*/
class ServerLog extends AbstractModel
{
@ -39,8 +39,12 @@ public static function boot(): void
parent::boot();
static::deleting(function (ServerLog $log) {
if (Storage::disk($log->disk)->exists($log->name)) {
Storage::disk($log->disk)->delete($log->name);
try {
if (Storage::disk($log->disk)->exists($log->name)) {
Storage::disk($log->disk)->delete($log->name);
}
} catch (\Exception $e) {
Log::error($e->getMessage(), ['exception' => $e]);
}
});
}
@ -72,7 +76,7 @@ public function write($buf): void
}
}
public function getContentAttribute(): ?string
public function getContent(): ?string
{
if (Storage::disk($this->disk)->exists($this->name)) {
return Storage::disk($this->disk)->get($this->name);
@ -80,4 +84,17 @@ public function getContentAttribute(): ?string
return '';
}
public static function log(Server $server, string $type, string $content, ?Site $site = null): void
{
$log = new static([
'server_id' => $server->id,
'site_id' => $site?->id,
'name' => $server->id.'-'.strtotime('now').'-'.$type.'.log',
'type' => $type,
'disk' => config('core.logs_disk'),
]);
$log->save();
$log->write($content);
}
}