idlab / loggable
Allows you to log updates occurring on entities
Package info
github.com/idlab-geneve/loggable-bundle
Type:symfony-bundle
pkg:composer/idlab/loggable
Requires
- php: ^8.2
- symfony/security-bundle: ^6.4|^7.0|^8.0
Requires (Dev)
- doctrine/doctrine-bundle: ^2.7
- doctrine/orm: ^2.14
- friendsofphp/php-cs-fixer: ^3.93
- phpunit/phpunit: ^9.6
- symfony/framework-bundle: ^6.4|^7.0|^8.0
- symfony/yaml: ^6.4|^7.0|^8.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This bundle supports Symfony 6.4, 7.x, and 8.x on PHP 8.2 or newer. Symfony 8 requires PHP 8.4 or newer.
Configuration in doctrine.yaml
To set under the wished connection configuration :
doctrine: orm: entity_manager: default: idlab_loggable: prefix: Idlab\Loggable\Entity dir: "%kernel.project_dir%/vendor/idlab/loggable/src/Entity"
NOTE: If you are using the short syntax for the ORM configuration, the
mappingskey is directly underorm:
Package file configuration
You can add a config file name "idlab_loggable.yaml" in config/packages in you Symfony project :
idlab_loggable: enabled: true logs_target_connection_name: 'default' table_prefix: 'example_table_prefix_' disallowed_namespaces: [ 'App\Entity\IgnoredByNamespace' ], disallowed_classes: [ 'App\Entity\IgnoredByClass' ]
Add IdlabLoggable attribute
Import : use Idlab\Loggable\Mapping\Attributes\IdlabLoggable; #[IdlabLoggable] public ?string $value = null;
To log all Doctrine-mapped properties of an entity, put the attribute on the
class. Exclude individual properties with IdlabLoggableExclude:
use Idlab\Loggable\Mapping\Attributes\IdlabLoggable; use Idlab\Loggable\Mapping\Attributes\IdlabLoggableExclude; #[IdlabLoggable] class Order { private string $status; #[IdlabLoggableExclude] private string $internalNote; }
Property-level IdlabLoggable remains supported for selective logging. A
property exclusion takes precedence over both class-level and property-level
logging attributes. Backed enums are logged using their backing value; pure
enums are logged using their case name.
Deprecated accessors
Version 2 renamed the log entry properties and database columns from
createdAt/createdBy to loggedAt/username. The old accessors remain
available for compatibility but are deprecated:
| Deprecated | Use instead |
|---|---|
getCreatedAt() |
getLoggedAt() |
getCreatedBy() |
getUsername() |
Update application code to use the replacement methods. The deprecated accessors may be removed in a future major version.
EntityLogEntry is immutable after construction. Version 2 removes all
setters from the entity so persisted audit records cannot be changed through
the entity API. Doctrine can hydrate the private fields without setters.