Capture Custom Logs
Laritor automatically captures your Laravel application logs (anything written through Laravel’s logger / Monolog channels).
But sometimes you also have logs that never touch Laravel’s normal log channels, for example:
- Database audit logs (stored in a table)
- Activity logs (Spatie Activity Log or custom)
- Integration logs (Stripe webhooks, vendor callbacks, queue provider logs)
- Legacy system logs written in another place
- Any “events” you track in your database but want to analyze like logs
This guide shows how to collect those records and send them to Laritor as custom logs, so they appear in Laritor’s Logs section alongside your normal application logs.
What you’ll build
Section titled “What you’ll build”A small routine that:
- Fetches your custom log entries (DB rows, API results, files, etc.)
- Converts each entry into Laritor’s custom log format
- Sends them in a batch to Laritor
You’ll typically run this via a scheduled task so Laritor stays up to date.
Custom log fields
Section titled “Custom log fields”Each custom log you send to Laritor supports:
| Field | Required | Description |
|---|---|---|
type | ✅ | A category/group name. Use this to filter easily (ex: db-audit, activity, stripe-webhooks). |
level | ✅ | Severity level (see list below). |
message | ✅ | The main log message. Keep it human-readable. |
context | ✅ | Extra structured data (array). |
written_at | ✅ | When the log actually happened (not when you’re sending it). |
Allowed level values
Section titled “Allowed level values”DEBUG, NOTICE, INFO, WARNING, ERROR, ALERT, CRITICAL, EMERGENCY
Tip: Prefer
INFOfor normal events,WARNINGfor suspicious but non-breaking events,ERRORfor failures.
Basic example: sending an array of logs
Section titled “Basic example: sending an array of logs”This example sends two custom logs to Laritor and batches them using sendEvents().
use Carbon\Carbon;use BinaryBuilds\LaritorClient\Laritor;
$logs = [ [ 'level' => 'INFO', // DEBUG, NOTICE, INFO, WARNING, ERROR, ALERT, CRITICAL, EMERGENCY 'message' => 'custom log 1', 'type' => 'custom-logs', 'written_at' => Carbon::parse('2025-10-24 12:55:55'), 'context' => [ 'user_id' => 1, 'account_id' => 2, 'source' => 'db-audit', ], ], [ 'level' => 'WARNING', 'message' => 'custom log 2', 'type' => 'custom-logs', 'written_at' => Carbon::parse('2025-10-24 12:55:55'), 'context' => [ 'user_id' => 1, 'account_id' => 2, 'source' => 'activity', ], ],];
$laritor = new Laritor();
foreach ($logs as $log) { $laritor->addCustomLog( $log['type'], $log['level'], $log['message'], $log['context'], $log['written_at'] );}
// Sends everything added above in a single batch request.$laritor->sendEvents();