Download the PHP package elstc/cakephp-activity-logger without Composer
On this page you can find all versions of the php package elstc/cakephp-activity-logger. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elstc/cakephp-activity-logger
More information about elstc/cakephp-activity-logger
Files in elstc/cakephp-activity-logger
Package cakephp-activity-logger
Short Description ActivityLogger plugin for CakePHP
License MIT
Informations about the package cakephp-activity-logger
ActivityLogger plugin for CakePHP 5.x
ActivityLogger plugin automatically logs database operations (create, update, delete) in CakePHP applications. It tracks who, when, and what was changed.
Requirements
- PHP 8.1 or higher
- CakePHP 5.0 or higher
- PDO extension
- JSON extension
Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
Load plugin
Load the plugin by adding the following statement in your project's src/Application.php
:
Create the activity_logs table
Run migration command:
Usage
Attach to Table
Attach the ActivityLogger plugin to your table to enable automatic logging:
Basic Activity Logging
Logging on create
Logging on update
Logging on delete
Activity Logging with Issuer
You can log information about the user who performed the operation:
AutoIssuerMiddleware (Recommended for CakePHP 4.x+)
AutoIssuerMiddleware
is a PSR-15 compliant middleware that provides automatic issuer setting for applications using the Authorization
plugin.
This middleware operates at the application level and processes authentication information early in the request lifecycle.
Installation and Configuration
Important Notes
- Middleware Order: Always place AutoIssuerMiddleware AFTER authentication middleware
AutoIssuerComponent (Legacy Approach)
If you're using Authorization
plugin or AuthComponent
, the AutoIssuerComponent
will automatically set the issuer to Tables:
Activity Logging with Scope
You can log operations related to multiple models:
Activity Logging with Custom Messages
You can use the setLogMessageBuilder
method to generate custom messages for each log action:
Alternatively, you can use setLogMessage
before save/delete operations to set a log message:
Save Custom Log
You can also record your own activity logs:
Find Activity Logs
You can search recorded activity logs:
Advanced Usage Examples
Conditional Logging
When you want to log only under certain conditions:
Batch Processing with Logging
During large data processing, you can temporarily disable logging:
Troubleshooting
Common Issues
Q: Logs are not being recorded
A: Please check the following:
- Whether migrations have been executed
- Whether the Behavior is properly attached
- Whether there are any database connection issues
Q: Issuer information is not being recorded
A: Please check the following:
- If using AutoIssuerMiddleware: Ensure it's placed AFTER authentication middleware in the middleware queue
- If using AutoIssuerComponent: Verify it's loaded in your controller's initialize() method
- Check if
setLogIssuer()
is manually set when needed - Verify the user model configuration matches your application's user table
Q: AutoIssuerMiddleware vs AutoIssuerComponent - Which should I use?
A:
-
Use AutoIssuerMiddleware (Recommended for CakePHP 4.x+):
- For new applications
- When you need application-wide issuer tracking
- For better performance and cleaner architecture
- When using PSR-15 middleware stack
- Use AutoIssuerComponent:
- For legacy applications or CakePHP 3.x
- When you need controller-specific issuer handling
- For backward compatibility
Q: Is there any performance impact?
A:
- AutoIssuerMiddleware has minimal performance impact as it processes once per request
- When handling large amounts of data, consider temporarily disabling logging as needed
Q: The issuer is not set for dynamically loaded Tables
A: The AutoIssuerMiddleware hooks into Model.initialize
events. Ensure:
- The middleware is loaded before any Table access
- Tables are loaded through the TableLocator (not manually instantiated)
- The LoggerBehavior is attached to the Table
License
MIT License. See LICENSE.txt for details.
Contributing
Bug reports and feature requests are welcome at GitHub Issues.
Pull requests are also welcome. We recommend discussing large changes in an Issue first.
All versions of cakephp-activity-logger with dependencies
ext-json Version *
ext-pdo Version *
cakephp/cakephp Version ^5.0
psr/log Version ^3.0