Easy PHP Audit Log Bundle: Log specific events according to configuration

Recommend this page to a friend!
  Info   View files Documentation   View files View files (118)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 104 All time: 9,344 This week: 270Up
Version License PHP version Categories
easyauditbundle 1.4Custom (specified...5.6PHP 5, Libraries, Logging
Description Author

This package can log specific events according to configuration.

It provides different components that can play different roles in the process of logging events that happen in an application.

There is a resolver component that takes an event and determines how to map its context to information to be logged.

There is also a channel component that can be used to select the level of severity of the events to be logged.

Innovation Award
PHP Programming Innovation award nominee
September 2018
Number 4
Every application should create logs of relevant actions that happen during its execution so it is possible later to be able to determine the possible reasons that caused something that went wrong.

This provides an alternative solution to the process of logging specific types of logging.

It takes the information about events to be logged in the form of object that provides all the action details, a resolver component that take the event information and passes it to a specific channel component that filters the interesting actions to generate the actual logs.

Manuel Lemos
Picture of Roni
  Performance   Level  
Innovation award
Innovation award
Nominee: 2x

Details

Easy Audit

Build Status HHVM Status Coverage Status Scrutinizer Code Quality Latest Stable Version Total Downloads SensioLabsInsight knpbundles.com

A Symfony2 Bundle To Log Selective Events. It is easy to configure and easy to customize for your need.

Note: If you are using Symfony version older then 2.4 you need to use EasyAuditBundle 1.2.x Note: If you are using Symfony version older then 2.6 you need to use EasyAuditBundle 1.3.x

Install

  1. Add EasyAuditBundle in your composer.json
  2. Enable the Bundle
  3. Create audit_log entity class
  4. Configure config.yml
  5. Update Database Schema

1. Add EasyAuditBundle in your composer.json

Add EasyAuditBundle in your composer.json:

{
    "require": {
        "xiidea/easy-audit": "^1.4"
    }
}

Now tell composer to download the bundle by running the command:

$ php composer.phar update xiidea/easy-audit

Composer will install the bundle to your project's vendor/xiidea directory.

2. Enable the Bundle

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Xiidea\EasyAuditBundle\XiideaEasyAuditBundle(),
    );
}

3. Create audit_log entity class

The XiideaEasyAuditBundle supports Doctrine ORM by default. However, you must provide a concrete AuditLog class. Follow the instructions to set up the class:

4. Configure config.yml

You can find sample config data in Resources/config/config-sample.yml file

# app/config/config.yml
xiidea_easy_audit:
    #resolver: xiidea.easy_audit.default_event_resolver                           #Optional
    #entity_class : MyProject\Bundle\MyBundle\Entity\AuditLog                     #Required
    #entity_event_resolver : xiidea.easy_audit.default_entity_event_resolver      #Optional
    #default_logger : true                                                        #Optional
    
    #user property to use as actor of an event
    #valid value will be any valid property of your user class
    user_property : ~ # or username                            #Optional

    #List of doctrine entity:event you wish to track or set to false to disable logs for doctrine events
    # valid events are = [created, updated, deleted]
    #doctrine_entities :                                              #Optional
    #     MyProject\Bundle\MyBundle\Entity\MyEntity : [created, updated, deleted]
    #     MyProject\Bundle\MyBundle\Entity\MyEntity2 : []

    #List all events you want to track  (Optional from v1.2.1 you can now use subscriber to define it)
    events :                                                   #Optional
        - security.interactive_login

    #List all custom resolver for event
    #custom_resolvers :
    #       security.interactive_login : user.event_resolver
    #       security.authentication.failure : user.event_resolver

    #logger_channel:
    #    xiidea.easy_audit.logger.service: ["info", "debug"]
    #    file.logger: ["!info", "!debug"]

    #Custom Event Resolver Service
services:
    #user.event_resolver:
    #     class: Xiidea\EasyAuditBundle\Resolver\UserEventResolver
    #     calls:
    #        - [ setContainer,[ @service_container ] ]

5. Update Database Schema

As all setup done, now you need to update your database schema. To do so,run the following command from your project directory

$ php app/console doctrine:schema:update --force

Core Concepts

Logger:

Logger is the core service which are responsible for persist the event info. You can define as many logger as you like. EasyAudit Bundled with a logger service xiidea.easy_audit.logger.service which is the default logger service. You can easily disable the service by setting default_logger: false in configuration.

Resolver:

Resolver is like translator for an event. It used to translate an event to AuditLog entity. EasyAudit bundled with two(2) resolver services xiidea.easy_audit.default_event_resolver, xiidea.easy_audit.default_entity_event_resolver. And a custom EventResolver class UserEventResolver to illustrate how the transformation works. You can define as many resolver service as you want and use them to handle different event. Here is the place you can set the severity level for a event. Default level is Psr\Log\LogLevel::INFO. Custom severity levels are not available. EasyAudit supports the logging levels described by PSR-3. These values are present for basic filtering purposes. You can use this value as channel to register different logger to handle different event. If you add any other field to your AuditLog object, this is the place to add those extra information (tags, metadata, etc..)

Channel

It is now possible to register logger for specific channel. channel is refers to log level. you can configure EasyAudit logger services to handle only specific level of event.

Warning - BC Breaking Changes

  • Since v1.2.2 `pre_persist_listener` option has been removed. You can use this cookbook to achieve the same functionality
  • Since v1.2.2 `EventResolverInterface` been split into `EmbeddedEventResolverInterface` and `EventResolverInterface`
  • Since v1.3.x The new Event object has been adapted. And the signature of `EmbeddedEventResolverInterface` and `EventResolverInterface` also changed. Now it expects extra $eventName parameter

Cookbook

Look the cookbook for another interesting things.

  Files folder image Files  
File Role Description
Files folder imageAnnotation (1 file)
Files folder imageCommon (1 file)
Files folder imageController (1 file)
Files folder imageDependencyInjection (2 files, 1 directory)
Files folder imageEntity (1 file)
Files folder imageEvents (2 files)
Files folder imageException (3 files)
Files folder imageListener (1 file)
Files folder imageLogger (4 files)
Files folder imageResolver (6 files, 1 directory)
Files folder imageResources (3 directories)
Files folder imageSubscriber (3 files)
Files folder imageTests (3 files, 10 directories)
Files folder imageTraits (2 files)
Accessible without login Plain text file .coveralls.yml Data Auxiliary data
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Plain text file XiideaEasyAuditBundle.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:104
This week:0
All time:9,344
This week:270Up

For more information send a message to info at phpclasses dot org.