HEX
Server: nginx/1.28.3
System: Linux lightweb-s1 5.15.0-173-generic #183-Ubuntu SMP Fri Mar 6 13:29:34 UTC 2026 x86_64
User: drdrivek-71 (1047)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: /home/dnlightw-124/dn.lightweb.kr/app/Services/Logger.php
<?php

namespace App\Services;

use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;

class Logger
{
    public string $sectionTitle;
    public Carbon $startTime;
    public bool $doLogging;

    public string $logChannel;

    public function __construct($sectionTitle, $channel = 'load_timer', $doLogging = null)
    {
        $this->sectionTitle = $sectionTitle;
        $this->startTime = Carbon::now();
        $this->doLogging = $doLogging ?? config('app.debug');
        $this->logChannel = $channel;
        Config::set('logging.channels.'.$channel,[
            'driver' => 'daily',
            'path' => storage_path('logs/'.$channel.'.log'),
            'level' => 'debug',
            'days' => 2,
            'replace_placeholders' => true,
        ]);

        if($this->doLogging) Log::channel($this->logChannel)->alert("Starting $sectionTitle");
    }

    public function getPrefix(): string
    {
        return "LOG ID : " .$this->startTime->timestamp . " | " . $this->sectionTitle . " |";
    }

    public function log($message = ''): void
    {
        if($this->doLogging) Log::channel($this->logChannel)->info($this->getPrefix() . " +" . $this->startTime->diffInSeconds(Carbon::now()) . " seconds" . ($message ? " | $message" : ''));
    }

    public function json($object): void
    {

        if ($this->doLogging) {
            $jsonObject = json_encode($object, JSON_PRETTY_PRINT);
            Log::channel($this->logChannel)->debug($this->getPrefix() . " JSON Object: " . $jsonObject);
        }
    }

}