Custom Log File Missing on production
Hi team 👋
I'm using opcodesio/log-viewer and it's working perfectly in my local environment. I've added a custom log file (caddy.log) which shows up correctly locally, but on the production server, it doesn't appear in the Log Viewer UI — even though the file exists. ✅ Setup Laravel version: 12 Log Viewer version:3.15 PHP version: 8.2 Hosted on EC2+docker container my file is located on same as located on larvel.log (storage/logs/caddy.log)
My server permission
-rw------- 1 root root 0 Jul 29 13:48 caddy.log
❌ Problem The custom log file (caddy.log) does not show up in the Log Viewer UI on the server, while it does locally and even on local docker container.
Any idea what might be causing this? Is there additional caching or indexing that might differ between environments?
Thanks in advance! 🙏
`
My Custom Caddy service File
public static string $name = 'Caddy';
public static string $levelClass = HttpStatusCodeLevel::class;
public static array $columns = [
['label' => 'Datetime', 'data_path' => 'datetime'],
['label' => 'Status', 'data_path' => 'level'],
['label' => 'Request', 'data_path' => 'message'],
];
public static string $regex = '/^\{"level":"[^"]+","ts":[0-9.]+,"logger":"[^"]+","msg":"[^"]+",'
. '"request":\{"remote_ip":"[^"]+","remote_port":"[^"]+","client_ip":"[^"]+",'
. '"proto":"[^"]+","method":"[^"]+","host":"[^"]+","uri":"[^"]+",'
. '"headers":\{(?:[^{}]|(?R))*\}\},'
. '"bytes_read":[0-9]+,"user_id":"[^"]*",'
. '"duration":[0-9.]+,"size":[0-9]+,"status":[0-9]+,'
. '"resp_headers":\{(?:[^{}]|(?R))*\}\}$/s';
public function fillMatches(array $matches = []): void
{
$matches=$this->decodeCaddyLog($matches);
$this->datetime = Carbon::createFromTimestamp($matches['ts'])?->setTimezone(LogViewer::timezone());
$this->level =$matches['status'];
$this->message =strtoupper($matches['request']['method']??'unknown').' '.$matches['request']['uri']??'';
$this->context=$matches;
}
static function decodeCaddyLog(array $matches)
{
try {
return $matches=json_decode($matches[0],true);
} catch (\Throwable) {
return [];
}
}
public static function matches(string $text, ?int &$timestamp = null, ?string &$level = null): bool
{
$matches = [];
$result = preg_match(static::$regex, trim($text), $matches) === 1;
$matches=self::decodeCaddyLog($matches);
$levelClass=self::$levelClass::from($matches['status']??'');
$level=$levelClass->getName();
return $result;
}
}`
Hey @yudhees ,
From the looks of it, it's likely the permission on the caddy.log file. Only the root user can read it, and if your web server (that processes Laravel requests) is running as a different user (e.g. www-data or apache or something other than root), it will not have access to read this file. Log Viewer ignores any files it cannot read.
To fix this, make sure the caddy.log file can be accessed by the user that runs your web server.