Skip to content

Log tools like read-log-entries does not handle custom log format and fills context #275

@cyppe

Description

@cyppe

Laravel Package Version

1.2.1

Laravel Version

12.30.1

PHP Version

8.3.25

System Info

Linux omarchy 6.16.8-arch2-1 #1 SMP PREEMPT_DYNAMIC Sun, 21 Sep 2025 23:19:08 +0000 x86_64 GNU/Linux

Description

I run JsonFormatter for logs.

   'fluentd' => [
            'driver'  => 'monolog',
            'handler' => Monolog\Handler\StreamHandler::class,
            'with'    => [
                'stream'         => storage_path('logs/laravel.log'),
                'filePermission' => 0664,
            ],
            'level'     => 'debug',
            'formatter' => Monolog\Formatter\JsonFormatter::class,
            // Optionally, specify any formatter constructor parameters here
            'formatter_with' => [],
        ],

And it seems like tools like read-log-entries only expects default format. So a call to this tool fills context as it fetches the maximum allowed size (1MB) so claude context is filled in one request.

I see the method specified PSR-3 that Json obviously does not comply with.

 /**
     * Retrieve the last $count complete PSR-3 log entries from the log file using
     * chunked reading instead of character-by-character reverse scanning.
     *
     * @return string[]
     */
    protected function readLastLogEntries(string $logFile, int $count): array
    {
        $chunkSize = $this->getChunkSizeStart();

        do {
            $entries = $this->scanLogChunkForEntries($logFile, $chunkSize);

            if (count($entries) >= $count || $chunkSize >= $this->getChunkSizeMax()) {
                break;
            }

            $chunkSize *= 2;
        } while (true);

        return array_slice($entries, -$count);
    }

I understand its probably not super common to change the log format. But I am probably not alone.

In my case the issue would be resolved if it could just treat one row in log file as one log. But probably needs some kind of configuration for this.

I can probably attempt to do a PR, but want to know from maintainers what direction I should move in in that case.

Steps To Reproduce

Use the log format I specified. Log a lot. And then call read-log-entries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions