Download the PHP package aurorawebsoftware/logiaudit without Composer
On this page you can find all versions of the php package aurorawebsoftware/logiaudit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aurorawebsoftware/logiaudit
More information about aurorawebsoftware/logiaudit
Files in aurorawebsoftware/logiaudit
Package logiaudit
Short Description For this package there is no description available.
License
Informations about the package logiaudit
LogiAudit
LogiAudit is a Laravel package designed for structured logging with support for job-based log storage, pruning, and customizable log levels.
Features
- Queue-Based Logging: Logs are stored asynchronously using Laravel jobs.
- Contextual Logging: Supports logging with model associations, trace IDs, and additional metadata.
- Automatic Pruning: Logs marked as deletable can be automatically removed.
- Monolog Integration: Works seamlessly with Laravel's logging system.
- IP Tracking: Logs IP addresses for traceability.
- Configurable Cleanup: Define log retention periods.
Installation
You can install the package via Composer:
Running Migrations
After installation, run the migration command to create the necessary database table:
Log Usage
Logging Events
You can log messages using the provided addLog
helper function:
addLog
Helper Function Details
The addLog
function allows for flexible logging with optional parameters:
level
(string, required): Log level (e.g.,info
,error
,warning
).message
(string, required): The log message.options
(array, optional): Additional context for the log entry.model_id
(int, nullable): The ID of the related model (if applicable).model_type
(string, nullable): The model's class name.trace_id
(string, nullable): A unique identifier for tracing logs across multiple services.context
(array, nullable): Any extra contextual data.ip_address
(string, nullable): The IP address of the request.deletable
(bool, default:true
): Determines if the log can be pruned.delete_after_days
(int, nullable): Number of days before the log should be automatically deleted (ifdeletable
istrue
).
Using LogiAudit with Laravel's Logging System
You can also log messages using Laravel's built-in logging channels:
To configure Laravel to use this handler, update config/logging.php
:
Running the Log Pruning Command
To remove logs marked as deletable
, run the following command:
Alternatively, you can schedule this command in your app/Console/Kernel.php
:
History Usage
History Log is simple to use. When you call HistoryableTrait into your model classes whose history you want to monitor, History Log will start to keep history for your model.
If you want to exclude some columns from this, add this variable to your model class globally and write the column names as an array.
If you don't want to keep history in some model events, add the following variable. Currently, this version only keeps the history of create, update and delete events.
Id | action | table | model | model_id | column | old_value | new_value | user_id | ip_address |
---|---|---|---|---|---|---|---|---|---|
1 | created | orders | App\Models\Order | 5 | [["order_code"],["price"],["total_price"]] | [{"order_code":"ABC"},{"price":"20"},{"total_price":"20"}] | [{"order_code":"ABCD"},{"price":"30"},{"total_price":"60"}] | 2 | 177.77.0.1 |
Running the History Pruning Command
To delete old history records based on their created_at
timestamp, you can run the following Artisan command:
Replace {days} with the number of days you want to retain. For example, to delete all history records older than 30 days:
Customizing Queue Names
By default, log and history jobs are queued using the logiaudit
queue.
You can customize the queue names by editing your config or .env
file:
Configuration File Setup
If there is no config you can publish
Environment File Setup
For example, to change the queue name for logs and history, add the following to your .env
file:
Important Note
If you change the queue names, make sure to run dedicated workers for the new queue names:
You can keep the workers running in the background using supervisor or systemd.
License
The LogiAudit package is open-sourced software licensed under the MIT License.