PHP code example of tihloh / prefab-logs
1. Go to this page and download the library: Download tihloh/prefab-logs library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tihloh / prefab-logs example snippets
use Tihloh\Prefab\Logs\DTOs\LogEntry;
use Tihloh\Prefab\Logs\Services\LogManager;
$logs = new LogManager();
$before = [
'office' => 'Accounting',
'active' => false,
'email' => '[email protected] ',
];
$now = [
'office' => 'Budget',
'active' => true,
'email' => '[email protected] ',
];
$logs->record([
'action' => 'user.updated',
'subject_type' => 'user',
'subject_id' => 25,
'actor_id' => 7,
'changes' => LogEntry::changes($before, $now),
]);
[
'office' => [
'before' => 'Accounting',
'now' => 'Budget',
],
'active' => [
'before' => false,
'now' => true,
],
]
$human = $logs->humanRecent(
50,
actorResolver: fn ($id) => $users->find($id)?->name,
subjectResolver: fn ($type, $id) => $type === 'user'
? $users->find($id)?->name
: null,
);
$log['event'];
$log['details'];
$log['created_at'];
$log['occurred_at'];
[
'field' => 'Office',
'before' => 'Accounting',
'now' => 'Budget',
]
$logs->record([
'action' => 'purchase_request.forwarded',
'subject_type' => 'purchase_request',
'subject_id' => 182,
'actor_id' => 7,
'message' => 'Christian forwarded Purchase Request PR-2026-00182 to Provincial Accounting Office',
]);
$changes = LogEntry::changes($before, $now);
$changes = LogEntry::changes(
$before,
$now,
['updated_at', 'last_seen_at'],
);
$logs->recent(50);
$logs->find(1001);
$logs->forSubject('user', 25);
$logs->forActor(7);
'metadata' => [
'source' => 'admin-ui',
'request_id' => 'abc123',
'module' => 'users',
],
$logs = new LogManager($customRepository);
$logs = new LogManager([
'database' => $logPdo,
]);
$logs->record($data);
prefab_trace();
prefab_trace_detailed();
$info = $logs->explain();
use Tihloh\Prefab\Background\BackgroundManager;
use Tihloh\Prefab\Logs\Services\LogManager;
$background = new BackgroundManager([
'path' => __DIR__ . '/../storage/prefab/background',
'max_workers' => 2,
]);
$logs = new LogManager([
'database' => $pdo,
'background' => true,
]);
$instructionId = $logs->record([
'action' => 'document.approved',
'subject_type' => 'document',
'subject_id' => 1001,
]);