PHPackages                             whitedigital-eu/audit-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. whitedigital-eu/audit-service

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

whitedigital-eu/audit-service
=============================

Audit Service

0.7.2(2y ago)08851[5 issues](https://github.com/whitedigital-eu/audit-service/issues)2MITPHPPHP &gt;=8.1.0

Since Dec 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/whitedigital-eu/audit-service)[ Packagist](https://packagist.org/packages/whitedigital-eu/audit-service)[ RSS](/packages/whitedigital-eu-audit-service/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (10)Dependencies (20)Versions (25)Used By (2)

Audit Service
=============

[](#audit-service)

> **IMPORTANT**: When migrating from `0.4` (or earlier) to `0.5`, configuration and usage has changed slightly:
>
> 1. When used outside of this package, `AuditService` can now be accessed as `WhiteDigital\Audit\Contracts\AuditServiceInterface` instead of `WhiteDigital\Audit\Service\AuditServiceLocator`. `AuditServiceLocator`class has been removed.
> 2. Configuration has changed and now it is one level higher:
>     **Old version**:
>
> ```
> whitedigital:
>     audit:
>         enable: true
>         audit_entity_manager: audit
>         default_entity_manager: default
> ```
>
>
>
> ```
> use Symfony\Config\WhitedigitalConfig;
>
> return static function (WhitedigitalConfig $config): void {
>     $config
>         ->audit()
>             ->enabled(true)
>             ->auditEntityManager('audit')
>             ->defaultEntityManager('default');
> };
> ```
>
>
>
> **New version**:
>
> ```
> audit:
>     audit_entity_manager: audit
>     default_entity_manager: default
> ```
>
>
>
> If used in php config, it is now `AuditConfig` instead of `WhitedigitalConfig`
>
> ```
> use Symfony\Config\AuditConfig;
>
> return static function (AuditConfig $config): void {
>     $config
>         ->auditEntityManager('audit')
>         ->defaultEntityManager('default');
> };
> ```
>
>
>
> As this bundle now comes enabled, `enabled` parameter has been removed

### What is it?

[](#what-is-it)

Audit is service needed to audit (log) events into database. For now package only ships with doctrine implementation to save data, but you can easily extend functionality (see below) to use other means of storage.

### System Requirements

[](#system-requirements)

PHP 8.1+
Symfony 6.3+

### Project Requirements

[](#project-requirements)

**2 separate Doctrine entity managers (*if using provided AuditService*)**

### Installation

[](#installation)

The recommended way to install is via Composer:

```
composer require whitedigital-eu/audit-service
```

---

### Configuration

[](#configuration)

**Configuration differs between default setup and overridden one.** If you are interested in configuration for overriding part of package, scroll down to appropriate section.

```
audit:
    audit_entity_manager: audit
    default_entity_manager: default
```

```
use Symfony\Config\AuditConfig;

return static function (AuditConfig $config): void {
    $config
        ->auditEntityManager('audit')
        ->defaultEntityManager('default');
};
```

> `audit_entity_manager` is entity manager used for audit
> `default_entity_manager` is entity manager you use for database operations

Logic is split between 2 managers because it is easier to audit database exception this way. If done with one entity manager, a lot extra steps need to be taken (opening closed entity manager, checking status of operations, etc.)

After this, you need to update your database schema to use Audit entity.
If using migrations:

```
bin/console doctrine:migrations:diff
bin/console doctrine:migrations:migrate
```

If by schema update:

```
bin/console doctrine:schema:update --force
```

This is it, now you can use audit. It is configured and autowired as `AuditServiceInterface`.

```
use WhiteDigital\Audit\Contracts\AuditType;
use WhiteDigital\Audit\Contracts\AuditServiceInterface;

public function __construct(private AuditServiceInterface $audit){}

$this->audit->audit(AuditType::EXCEPTION, 'something happened');

try {
    somefunction();
} catch (Exception $exception){
    $this->audit->auditException($exception);
}
```

---

Audit service comes with 2 event subscribers: one for exceptions and one for database events.

**Exception subscriber**:
By default exception subscriber audits all exceptions, except 404 response code. you can override this logic by:

```
audit:
    excluded:
        response_codes:
            - 404
            - 405
```

```
use Symfony\Config\AuditConfig;
use Symfony\Component\HttpFoundation\Response;

return static function (AuditConfig $config): void {
    $config
        ->excluded()
            ->responseCodes([
                Response::HTTP_NOT_FOUND,
                Response::HTTP_METHOD_NOT_ALLOWED,
            ]);
};
```

By default exception subscriber audits all exceptions on all routes and paths. you can override this logic by: Path:

```
audit:
    excluded:
        paths:
            - '/test'
```

```
use Symfony\Config\AuditConfig;
use Symfony\Component\HttpFoundation\Response;

return static function (AuditConfig $config): void {
    $config
        ->excluded()
            ->paths([
                '/test',
            ]);
};
```

Route:

```
audit:
    excluded:
        routes:
            - 'app_test'
```

```
use Symfony\Config\AuditConfig;
use Symfony\Component\HttpFoundation\Response;

return static function (AuditConfig $config): void {
    $config
        ->excluded()
            ->routes([
                'app_test',
            ]);
};
```

---

### Allowed Audit types

[](#allowed-audit-types)

To not to create chaos within audit records, it is only allowed to use specified audit types.
**Default values are: `AUTHENTICATION`, `DATABASE`, `ETL_PIPELINE`, `EXCEPTION` and `EXTERNAL_CALL`.**

> If you don't have any custom types, you can use `WhiteDigital\Audit\Contracts\AuditType` class for default constants.

If you wish to add more types, configure new types as so:

```
audit:
    additional_audit_types:
        - test1
        - test2
```

```
use Symfony\Config\AuditConfig;

return static function (AuditConfig $config): void {
    $config
        ->additionalAuditTypes([
            'test1',
            'test2',
        ]);
};
```

It is possible to run symfony command that generates interface based on default and added types for easier code complete:

```
bin/console make:audit-types
```

This command will generate new file based on package configuration. By default, this command will make `App\Audit\AuditType` class. You can override this name in configuration:

```
audit:
    audit_type_interface_namespace: 'App\Audit'
    audit_type_interface_class_name: 'AuditType'
```

```
use Symfony\Config\AuditConfig;

return static function (AuditConfig $config): void {
    $config
        ->auditTypeInterfaceNamespace('App\Audit')
        ->auditTypeInterfaceClassName('AuditType');
};
```

> If you have this defined interface and want to add more allowed types, you can just add new types to it without adding types to package configuration. Allowed types will be merged from configuration and interface.

---

### Api Resource

[](#api-resource)

This package comes with AuditResource for api-platform, it's iri is `/api/audits`.

---

### Overriding parts of bundle

[](#overriding-parts-of-bundle)

**Overriding audit service**
If you wish not to use audit service this package comes with, you can override it with your own.
To do so, implement `AuditServiceInterface` into your service:

```
use WhiteDigital\Audit\Contracts\AuditServiceInterface;

class YourAuditService implements AuditServiceInterface {
    public function audit(string $type, string $message, array $data = [], string $class = ''): void
    {
    }

    public function auditException(Throwable $exception, ?string $url = null, string $class = ''): void
    {
    }

    public static function getDefaultPriority(): int
    {
        return 2;
    }
}
```

> AuditService in this package comes with priority of 1. To override it, make sure to add priority higher than that.

If your custom AuditService does not use database as an audit storage, you need to disable part of this package that requires 2 entity managers. You can do it like this:

```
audit:
    custom_configuration: true
```

```
use Symfony\Config\AuditConfig;

return static function (AuditConfig $config): void {
    $config
        ->customConfiguration(true);
};
```

---

**Overriding default api resource (and therefore api endpoints)**

By default, Audit resource is based on `AuditResource`
If you wish not to use this resource and not expose the api endpoints it provides, just set a custom api resource path with a configuration value. If you set it as `null`, api platform will not register api resource located within this package.

```
audit:
    custom_api_resource_path: '%kernel.project_dir%/src/MyCustomPath'
#    custom_api_resource_path: null
```

```
use Symfony\Config\AuditConfig;

return static function (AuditConfig $config): void {
    $config
        ->customApiResourcePath('%kernel.project_dir%/src/MyCustomPath')
        // or  ->customApiResourcePath(null);
};
```

After overriding default api resource, do not forget to update ClassMapperConfigurator configuration that is used for resource &lt;-&gt; entity mapping in `whitedigital-eu/entity-resource-mapper-bundle`

```
use App\ApiResource\Admin\AuditResource;
use WhiteDigital\Audit\Entity\Audit;
use WhiteDigital\EntityResourceMapper\Mapper\ClassMapper;
use WhiteDigital\EntityResourceMapper\Mapper\ClassMapperConfiguratorInterface;

final class ClassMapperConfigurator implements ClassMapperConfiguratorInterface
{
    public function __invoke(ClassMapper $classMapper): void
    {
        $classMapper->registerMapping(AuditResource::class, Audit::class);
    }
}
```

---

**Overriding default entity**
By default, Audit entity is based on `BaseEntity` that comes from `whitedigital-eu/entity-resource-mapper-bundle`.
If you wish not to use this base at all, you need to create new Entity and implement `AuditEntityInterface` into it:

```
use Doctrine\ORM\Mapping as ORM;
use WhiteDigital\Audit\Contracts\AuditEntityInterface;

#[ORM\Entity]
class AuditEntity implements AuditEntityInterface {}
```

or you can use Model from package:

```
use Doctrine\ORM\Mapping as ORM;
use WhiteDigital\Audit\Model\Audit;

#[ORM\Entity]
class AuditEntity extends Audit {}
```

If you wish to add new properties or, maybe, use different name for Audit entity that comes from package:

```
use Doctrine\ORM\Mapping as ORM;
use WhiteDigital\Audit\Entity\Audit as BaseAudit;

#[ORM\Entity]
#[ORM\Table('new_audit_table_name')]
class AuditEntity extends BaseAudit {}
```

Now when you use `audit()` or `auditException()` functions in your project, you need to tell service to use your entity:

```
use WhiteDigital\Audit\Contracts\AuditType;
use WhiteDigital\Audit\Contracts\AuditServiceInterface;

use App\Entity\AuditEntity; // example

public function __construct(private AuditServiceInterface $audit){}

$this->audit->audit(AuditType::EXTERNAL, 'something happened', [], AuditEntity::class);

$this->audit->audit(AuditType::ETL, 'something happened', class: AuditEntity::class);

try {
    somefunction();
} catch (Exception $exception){
    $this->audit->auditException($exception, '', AuditEntity::class);

    $this->audit->auditException($exception, class: AuditEntity::class);
}
```

This bundle automatically adds `WhiteDigital\Audit\Entity` namespace to both given entity managers. If you wish to not it to do it, for example, if you don't use default entity or maybe don't store audits in database at all, you need to configure this to disable it:

```
audit:
    set_doctrine_mappings: false
```

```
use Symfony\Config\AuditConfig;

return static function (AuditConfig $config): void {
    $config
        ->setDoctrineMappings(false);
};
```

---

**Overriding auditing of entity events**
You can disable entity event auditing in runtime by calling setIsEnabled setter for entity event subscriber

```
use WhiteDigital\Audit\EventSubscriber\AuditDoctrineEventSubscriber;

public function __construct(private AuditDoctrineEventSubscriber $subscriber){}

$this->subscriber->setIsEnabled(false);
someFunction();
$this->subscriber->setIsEnabled(true);
```

---

### PHP CS Fixer

[](#php-cs-fixer)

> **IMPORTANT**: When running php-cs-fixer, make sure not to format files in `skeleton` folder. Otherwise maker command will stop working.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~47 days

Total

22

Last Release

772d ago

PHP version history (2 changes)0.1.0PHP &gt;=8.1.0

0.8.x-devPHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/38725938?v=4)[Dāvis Zālītis](/maintainers/k0d3r1s)[@k0d3r1s](https://github.com/k0d3r1s)

![](https://www.gravatar.com/avatar/d54d4c03974bdc6923785b90b54575e77570057e72fd6b9915e06656e60b842e?d=identicon)[andis.cirulis](/maintainers/andis.cirulis)

---

Top Contributors

[![k0d3r1s](https://avatars.githubusercontent.com/u/38725938?v=4)](https://github.com/k0d3r1s "k0d3r1s (63 commits)")[![acirulis](https://avatars.githubusercontent.com/u/27766961?v=4)](https://github.com/acirulis "acirulis (20 commits)")[![raraworks](https://avatars.githubusercontent.com/u/18421085?v=4)](https://github.com/raraworks "raraworks (7 commits)")

---

Tags

phpsymfony-bundlephpsymfonyAuditSymfony Bundleapi-platform

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/whitedigital-eu-audit-service/health.svg)

```
[![Health](https://phpackages.com/badges/whitedigital-eu-audit-service/health.svg)](https://phpackages.com/packages/whitedigital-eu-audit-service)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M376](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M196](/packages/sulu-sulu)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9317.2k55](/packages/open-dxp-opendxp)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.8M712](/packages/sylius-sylius)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1615.6k12](/packages/2lenet-crudit-bundle)[pimcore/pimcore

Content &amp; Product Management Framework (CMS/PIM/E-Commerce)

3.8k3.8M462](/packages/pimcore-pimcore)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
