Skip to content

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.


A small routine that:

  1. Fetches your custom log entries (DB rows, API results, files, etc.)
  2. Converts each entry into Laritor’s custom log format
  3. Sends them in a batch to Laritor

You’ll typically run this via a scheduled task so Laritor stays up to date.


Each custom log you send to Laritor supports:

FieldRequiredDescription
typeA category/group name. Use this to filter easily (ex: db-audit, activity, stripe-webhooks).
levelSeverity level (see list below).
messageThe main log message. Keep it human-readable.
contextExtra structured data (array).
written_atWhen the log actually happened (not when you’re sending it).

DEBUG, NOTICE, INFO, WARNING, ERROR, ALERT, CRITICAL, EMERGENCY

Tip: Prefer INFO for normal events, WARNING for suspicious but non-breaking events, ERROR for failures.


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();