承接 iamjohndev/audit-logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

iamjohndev/audit-logger

最新稳定版本:v1.1

Composer 安装命令:

composer require iamjohndev/audit-logger

包简介

Audit Logger is a simple PHP class that allows you to log user interactions in your application.

README 文档

README

Audit Logger is a simple PHP class that allows you to log user interactions in your application. You can configure the logging driver (file or database), database connection, and log formatter according to your needs.

Installation

You can install Audit Logger using Composer by running the following command:

composer require iamjohndev/audit-logger

Replace your-vendor-name with your desired vendor name and your-package-name with the desired package name.

Usage

Include the Composer autoloader in your PHP files where you want to use the AuditLogger class:

require_once 'vendor/autoload.php';

Set the log storage driver and the database connection (if using the database driver) before using the AuditLogger:

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);

Set the log formatter (optional) if you want to customize the log entry format:

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

Start logging user interactions by calling the log method:

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

Retrieve all logs using the getAllLogs method:

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

Clear all logs using the clearLogs method:

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

Database Configuration

If you're using the database log storage driver, make sure to configure the database connection by setting the appropriate values for the host, username, password, and database name in the database connection code:

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

Replace 'localhost', 'username', 'password', and 'database_name' with the actual values for your database configuration.

Custom Logs Table (Optional)

If you want to use a custom table name for storing logs in the database, you can set it using the setLogsTableName method:

AuditLogger::setLogsTableName('custom_logs_table');
CREATE TABLE custom_logs_table (
    id INT AUTO_INCREMENT PRIMARY KEY,
    timestamp DATETIME,
    user_id INT,
    action VARCHAR(255),
    module VARCHAR(255),
    log_entry TEXT
);

Replace 'custom_logs_table' with the desired name for your custom logs table.

License

This project is licensed under the MIT License. See the LICENSE file for details.

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-21