What is an audit log system
An audit log system lets you record user actions and system changes over time. It helps you track who did what and when.
For example, recording when a user updates their profile or an admin changes permissions can simplify debugging and compliance.
You can set this up in your Laravel, Symphony or raw PHP backend.
Using Operational to track audit events
Operational is an open-source event tracking solution. It lets you capture and view events from any application. You can use it to log audit events in a simple and structured way.
Setting up Operational
- Go to https://app.operational.co and sign up.
- Create a new project in your dashboard.
- Copy the API key from the project settings.
- Install the PHP SDK with composer:
composer require operational/sdk-php
- Save the API key in your environment variables.
Implementation in PHP
<?php
require 'vendor/autoload.php';
use Operational\\Operational;
$ops = new Operational('YOUR_API_KEY');
$payload = [
'name' => 'user_updated_profile',
'avatar' => '📝',
'content' => 'User John Smith updated their profile'
];
$ops->events->ingest($payload);
<?php
// Example: Admin changes user permissions
$payload = [
'name' => 'admin_changed_permissions',
'avatar' => '🔒',
'type' => 'json',
'content' => [
'admin_id' => 789,
'user_id' => 456,
'new_role' => 'editor'
]
];
$ops->events->ingest($payload);
<?php
// Example: Record data deletion
$payload = [
'name' => 'record_deleted',
'avatar' => '🗑️',
'type' => 'json',
'content' => [
'description' => 'User John Smith deleted record 321',
'user_id' => 123,
'record_id' => 321
]
];
$ops->events->ingest($payload);
These examples show how to send different audit events from your PHP app to Operational.
Conclusion
Building an audit log system in your PHP app helps track changes and user actions. Operational makes it easy to capture and view these events without extra setup.
Learn more at https://operational.co. Try the playground for ready-to-paste code snippets at https://operational.co/playground.