Giter VIP home page Giter VIP logo

audit's Introduction

Utopia Audit

Build Status Total Downloads Discord

Utopia framework audit library is simple and lite library for managing application user logs. This library is aiming to be as simple and easy to learn and use. This library is maintained by the Appwrite team.

Although this library is part of the Utopia Framework project it is dependency free, and can be used as standalone with any other PHP project or framework.

Getting Started

Install using composer:

composer require utopia-php/audit

Init the audit object:

<?php

require_once __DIR__ . '/../../vendor/autoload.php';

use PDO;
use PDO;
use Utopia\Audit\Audit;
use Utopia\Cache\Cache;
use Utopia\Cache\Adapter\None as NoCache;
use Utopia\Database\Adapter\MySQL;
use Utopia\Database\Database;

$dbHost = '127.0.0.1';
$dbUser = 'travis';
$dbPass = '';
$dbPort = '3306';

$pdo = new PDO("mysql:host={$dbHost};port={$dbPort};charset=utf8mb4", $dbUser, $dbPass, [
    PDO::ATTR_TIMEOUT => 3, // Seconds
    PDO::ATTR_PERSISTENT => true,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_EMULATE_PREPARES => true,
    PDO::ATTR_STRINGIFY_FETCHES => true,
]);
        
$cache = new Cache(new NoCache());

$database = new Database(new MySQL($pdo),$cache);
$database->setNamespace('namespace');

$audit = new Audit($database);
$audit->setup();

Create Log

A simple example for logging a user action in the audit DB.

$userId = 'user-unique-id';
$event = 'deleted'; // Log specific action name
$resource = 'database/document-1'; // Resource unique ID (great for filtering specific logs)
$userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36'; // Set user-agent
$ip = '127.0.0.1'; // User IP
$location = 'US'; // Country name or code
$data = ['key1' => 'value1','key2' => 'value2']; // Any key-value pair you need to log

$audit->log($userId, $event, $resource, $userAgent, $ip, $location, $data);

Get Logs By User

Fetch all logs by given user ID

$logs = $audit->getLogsByUser(
    'userId' // User unique ID
); // Returns an array of all logs for specific user

Get Logs By User and Action

Fetch all logs by given user ID and a specific event name

$logs = $audit->getLogsByUserAndEvents( 
    'userId', // User unique ID
    ['update', 'delete'] // List of selected event to fetch
); // Returns an array of all logs for specific user filtered by given actions

Get Logs By Resource

Fetch all logs by a given resource name

$logs = $audit->getLogsByResource(
    'resource-name', // Resource Name
); // Returns an array of all logs for the specific resource

System Requirements

Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.

Copyright and license

The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php

audit's People

Contributors

abnegate avatar aishubalaji avatar christyjacob4 avatar drph4nt0m avatar eldadfux avatar fanatic75 avatar fogelito avatar hard-coder05 avatar kodumbeats avatar lohanidamodar avatar meldiron avatar mohakgupt avatar princeton21 avatar rutam21 avatar shimonewman avatar stnguyen90 avatar torstendittmann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audit's Issues

asterisk

asterisks to be controlled: a few are placed nearby the text, a few are placed with a space in between the text and the asterisk. LET'S KEEP IT COHERENT - > allways with ONE SPACE between the text and the asterisk, like: * asterisk

Table name question

Hi,

Cool, simple little lib, and easy to use and extend ๐Ÿ‘ Just wondering why the table name is "namespace.audit.audit", I get the namespace part but why is "audit" repeated? I know it's a pretty inane question but just wondering in case I am missing something?

Thanks for sharing ๐Ÿ˜Š

Connecting Membership Sub-Packages (textes)

Membership details (Sub-Packages) view for Funeral Companies: texts not interlaced yet with database -> this issue avoids to see the correct translation into the chosen language. Pls interlace all languages.

Upgrade our issue templates to use GitHub issue forms โœ๏ธ

Introduction

GitHub has recently rolled out a public beta for their issue forms feature. This would allow you to create interactive issue templates and validate them ๐Ÿคฏ.

Appwrite currently uses the older issue template format. Your task is to create GitHub issue forms for this repository. Please use Appwrite's issue templates as a reference for this PR.

Tasks summary:

  • Fork & clone this repository
  • Prepare bug report issue form in .github/ISSUE_TEMPLATE/bug.yaml
  • Prepare documentation issue form in .github/ISSUE_TEMPLATE/documentation.yaml
  • Prepare feature request issue form in .github/ISSUE_TEMPLATE/feature.yaml
  • Push changes to master and test issue forms on your fork
  • Submit pull request

If you need any help, reach out to us on our Discord server.

Are you ready to work on this issue? ๐Ÿค” Let us know, and we will assign it to you ๐Ÿ˜Š

Happy Appwriting!

Announcements / Tab 2

Substitution of Icon related to "Save image/s" -> from "Cloud upload" to "Save Icon" (Cloud icon being confusing)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.