ddtraceweb/monolog-parser
Laravel-friendly Monolog parser that reads and normalizes Monolog log records/lines for easier searching, filtering, and display. Useful for building log viewers, dashboards, or importing Monolog output into your own storage or analysis pipeline.
storage/logs/laravel.log) into structured JSON/arrays for easier analysis in tools like Datadog, ELK, or custom dashboards.single channel logs may not capture all context (e.g., HTTP request data unless explicitly added).use DdTraceWeb\MonologParser\Parser;
$parser = new Parser();
$logs = $parser->parse(file_get_contents(storage_path('logs/laravel.log')));
Log::info('Event', ['request_id' => $request->id])).spatie/laravel-log-viewer).Log::stack() or monolog/handler extensions suffice?single, daily, syslog).laravel.log) and validate output structure.Log::debug('Test', ['user_id' => 123])).php artisan logs:parse) to output structured logs.// app/Console/Commands/ParseLogs.php
use DdTraceWeb\MonologParser\Parser;
public function handle() {
$logs = (new Parser())->parse(file_get_contents($this->getLogPath()));
$this->info(json_encode($logs, JSON_PRETTY_PRINT));
}
Log::flush() or rotate logs before parsing).| Step | Priority | Dependencies | Output |
|---|---|---|---|
| Validate log format | High | Existing Monolog configuration | Structured log sample |
| PoC implementation | High | Basic PHP/Artisan setup | Working CLI or middleware |
| Error handling | Medium | PoC results | Robust parsing (malformed logs) |
| Integration | Low | APM/ELK setup (if applicable) | Automated log pipeline |
| Monitoring | Low | Integration tests | Alerts on parsing failures |
dd() or Log::debug() to validate intermediate steps.// Good: Structured
Log::info('User logged in', ['user_id' => $user->id, 'ip' => $request->ip()]);
// Bad: Unstructured
Log::info('User ' . $user->id . ' logged in from ' . $request->ip());
Log::flush() or symlinks.| Scenario | Impact | Mitigation |
|---|---|---|
| Malformed log entries | Parsing errors/crashes | Add validation (e.g., JSON schema) |
| Log file rotation during parse | Incomplete/corrupted data | Lock files or use atomic reads |
| Monolog format changes | Parser breaks | Test against new Monolog versions |
| High log volume | Slow parsing | Optimize with streaming/batching |
| Dependency conflicts | PHP/Monolog version issues | Pin versions in composer.json |
README with:
Log Generation → Parsing → Analysis/Storage.How can I help you explore Laravel packages today?