dmstr/doctrine-audit-log-bundle
Install via Composer:
composer require vendor/package-name
Ensure your project meets the minimum PHP 8.4 requirement (check via php -v). Register the package in config/app.php under providers and publish its config with:
php artisan vendor:publish --provider="Vendor\PackageName\PackageServiceProvider"
Start by leveraging the LogEntry model for structured logging. Example:
use Vendor\PackageName\Models\LogEntry;
// Log a system event
LogEntry::create([
'tag' => 'System', // Updated from 'OpenAPI' (breaking change)
'level' => 'info',
'message' => 'User authenticated',
'context' => ['user_id' => 123],
]);
Structured Logging
Use LogEntry for audit trails or system events. Tag entries with 'System' (replaces deprecated 'OpenAPI').
LogEntry::query()
->where('tag', 'System')
->where('level', '>', 'warning')
->get();
Middleware Integration Attach logging to middleware for request tracking:
namespace App\Http\Middleware;
use Vendor\PackageName\Models\LogEntry;
class LogRequests
{
public function handle($request, Closure $next)
{
$response = $next($request);
LogEntry::create([
'tag' => 'System',
'level' => 'debug',
'message' => 'Request processed',
'context' => ['path' => $request->path()],
]);
return $response;
}
}
Event Listeners
Trigger logs via Laravel events (e.g., Illuminate\Auth\Events\Authenticated):
namespace App\Listeners;
use Vendor\PackageName\Models\LogEntry;
class LogAuthentication
{
public function handle($event)
{
LogEntry::create([
'tag' => 'System',
'level' => 'info',
'message' => 'User logged in',
'context' => ['email' => $event->user->email],
]);
}
}
Unit tests for LogEntry are now included. Extend them in your test suite:
use Vendor\PackageName\Tests\Unit\LogEntryTest;
class CustomLogEntryTest extends LogEntryTest
{
public function testCustomScenario()
{
// Override or extend existing tests
}
}
phpbrew) to avoid runtime errors. Check compatibility with other packages.'OpenAPI' with 'System' in all existing logs/configurations. Run a database search for 'OpenAPI' to catch missed instances.LogEntry table exists (run migrations if needed). Check config/package-name.php for storage paths.LogEntry::insert([
['tag' => 'System', 'level' => 'info', 'message' => 'Batch log 1'],
['tag' => 'System', 'level' => 'info', 'message' => 'Batch log 2'],
]);
tag field for domain-specific logging (e.g., 'Payment', 'Inventory').LogEntry events to trigger external actions (e.g., Slack alerts for 'error' logs):
LogEntry::created(function ($log) {
if ($log->level === 'error') {
// Send alert
}
});
CLAUDE.md (likely a contributor license agreement) may require updates to your workflow. Review if you accept external contributions.'System' tag change.LogEntry for reusable queries:
namespace Vendor\PackageName\Models;
class LogEntry extends Model
{
public function scopeForUser($query, $userId)
{
return $query->where('context->user_id', $userId);
}
}
LogEntry::where('created_at', '<=', now()->subDays(30))->delete()).How can I help you explore Laravel packages today?