PHP code example of iamjohndev / audit-logger

1. Go to this page and download the library: Download iamjohndev/audit-logger 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/ */

    

iamjohndev / audit-logger example snippets


use iamjohndev\AuditLogger;

// Set the log storage driver
AuditLogger::setLogDriver('database');

// Set the database connection
$dbConnection = new mysqli('localhost', 'username', 'password', 'database_name');
AuditLogger::setDbConnection($dbConnection);

AuditLogger::setLogFormatter(function($userId, $action) {
    // Custom log formatting logic
    return "User ID: $userId | Action: $action";
});


// Log user interaction
$userId = 123;
$action = 'edit';
AuditLogger::log($userId, $action);


// Get all logs
$logs = AuditLogger::getAllLogs();
print_r($logs);


// Clear all logs
AuditLogger::clearLogs();


$dbConnection = new mysqli('localhost', 'username', 'password', 'database_name');


AuditLogger::setLogsTableName('custom_logs_table');