PHPackages                             tourze/doctrine-track-bundle - 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. [Database &amp; ORM](/categories/database)
4. /
5. tourze/doctrine-track-bundle

ActiveLibrary[Database &amp; ORM](/categories/database)

tourze/doctrine-track-bundle
============================

Doctrine 实体变更跟踪和日志记录 Bundle

1.1.0(6mo ago)028.0k20MITPHPCI passing

Since Mar 29Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/doctrine-track-bundle)[ Packagist](https://packagist.org/packages/tourze/doctrine-track-bundle)[ RSS](/packages/tourze-doctrine-track-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (37)Versions (15)Used By (20)

Doctrine Track Bundle
=====================

[](#doctrine-track-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/adb86c3bc52dd82a44656e22831d04cac04a1f71b3a22c9073a9dc67c73dfcc1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f646f637472696e652d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-track-bundle)[![PHP Version](https://camo.githubusercontent.com/7526ec7963dc575117844b788d42117610fe043535a8342c51fe55d08a40edb2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f646f637472696e652d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-track-bundle)[![License](https://camo.githubusercontent.com/f6853eb1d8090c2657ef7f7f7f2ec07ddac2ccb9172c917b0e29a54e4fee7367/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f646f637472696e652d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](LICENSE)

[![Build Status](https://camo.githubusercontent.com/0346e18af1343d739d0405776c07b83798d5bb0200e3efcfdf657e5e662f6403/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f7068702d6d6f6e6f7265706f2f63692e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/tourze/php-monorepo/actions)[![Code Coverage](https://camo.githubusercontent.com/6ce0146325478eb7cebae4cc6139b2af2c161735dd0e3c6ff6802f2c5a708179/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f3f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/php-monorepo)[![Total Downloads](https://camo.githubusercontent.com/45900661e524e1741fcf33689d96ed3fc6d406ddefef7a0b5bfc29ab99572f2e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f646f637472696e652d747261636b2d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-track-bundle)

A Symfony bundle for tracking and auditing entity changes with automatic logging of create, update, and delete operations to help maintain data integrity and compliance requirements.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Dependencies](#dependencies)
- [Required Bundles](#required-bundles)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
    - [Environment Variables](#environment-variables)
    - [Service Configuration](#service-configuration)
- [Advanced Usage](#advanced-usage)
    - [Custom Entity Requirements](#custom-entity-requirements)
    - [Understanding Log Data](#understanding-log-data)
    - [Performance Considerations](#performance-considerations)
- [Contributing](#contributing)
- [License](#license)
- [Changelog](#changelog)

Features
--------

[](#features)

- **Selective Tracking**: Only tracks fields explicitly marked with `#[TrackColumn]` attribute
- **Complete Audit Trail**: Records entity class, ID, action type, changed data, user, IP, and request ID
- **Asynchronous Logging**: Non-blocking log persistence for better performance
- **Automatic Cleanup**: Built-in scheduled cleanup with configurable retention period
- **User Context**: Automatically captures user information when available
- **Request Tracking**: Associates changes with request IDs for better debugging

Dependencies
------------

[](#dependencies)

- PHP &gt;= 8.1
- Symfony &gt;= 6.4
- Doctrine ORM &gt;= 3.0
- Doctrine Bundle &gt;= 2.13

Required Bundles
----------------

[](#required-bundles)

- `tourze/doctrine-async-insert-bundle`: For asynchronous log insertion
- `tourze/request-id-bundle`: For request ID tracking
- `tourze/doctrine-user-bundle`: For user context tracking
- `tourze/doctrine-ip-bundle`: For IP address tracking
- `tourze/doctrine-timestamp-bundle`: For timestamp management

Installation
------------

[](#installation)

Install via Composer:

```
composer require tourze/doctrine-track-bundle
```

If you're not using Symfony Flex, manually register the bundle in `config/bundles.php`:

```
return [
    // ...
    Tourze\DoctrineTrackBundle\DoctrineTrackBundle::class => ['all' => true],
];
```

Run database migrations to create the tracking table:

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

Quick Start
-----------

[](#quick-start)

1. **Mark fields to track** with the `#[TrackColumn]` attribute:

```
