Skip to content

Support JSON-formatted log entries in log reading tools#650

Merged
pushpak1300 merged 1 commit intolaravel:mainfrom
HeathNaylor:fix/json-log-format-support
Mar 11, 2026
Merged

Support JSON-formatted log entries in log reading tools#650
pushpak1300 merged 1 commit intolaravel:mainfrom
HeathNaylor:fix/json-log-format-support

Conversation

@HeathNaylor
Copy link
Contributor

This PR does the following:

  • Auto-detect JSON log format in the ReadsLogs trait and split entries by newlines instead of PSR-3 timestamps
  • Handle JSON error detection in LastError tool, supporting both numeric level (level >= 400) and string level (level_name = "ERROR") fields
  • No behavior change for PSR-3 formatted logs
  • Tested against LogstashFormatter and LogglyFormatter in addition to JsonFormatter since these are the other Monolog formatters that write JSON to log files and would hit the same issue

Fixes #275

Test plan

  • 7 new tests across ReadLogEntriesTest and LastErrorTest covering JsonFormatter, LogstashFormatter, and LogglyFormatter output formats
  • Tests verify correct entry count, error detection, and exclusion of non-error entries for each format

Auto-detect JSON log format (JsonFormatter, LogstashFormatter,
LogglyFormatter) and split by newlines instead of PSR-3 timestamps.
Also handle JSON error detection in LastError tool.

Fixes laravel#275
@pushpak1300 pushpak1300 merged commit ce36c4d into laravel:main Mar 11, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants