xiidea/easy-audit
Composer 安装命令:
composer require xiidea/easy-audit
包简介
A Symfony Bundle To Log Selective Events. It is easy to configure and easy to customize for your need
README 文档
README
A Symfony Bundle To Log Selective Events. It is easy to configure and easy to customize for your need.
Versions
| Symfony | PHP | EasyAuditBundle | Support |
|---|---|---|---|
| 5.4-8.x | >=8.1 | 3.x.x | New Features / Bugs |
| 5.x | >=7.2.5 | 2.x.x | Bugs |
| 2.7-4.4 | ^5.6,^7.0 | 1.4.x | - |
| <=2.8 | ^5.4-7.3 | 1.3.x | - |
| <=2.4 | ^5.4 | 1.2.x | - |
Install
- Add EasyAuditBundle in your composer.json
- Enable the Bundle
- Create audit_log entity class
- Configure config.yml
- Update Database Schema
1. Add EasyAuditBundle in your composer.json
Add EasyAuditBundle in your composer.json:
{
"require": {
"xiidea/easy-audit": "^3.0"
}
}
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/MongoDB 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 #audit_log_class : MyProject\Bundle\MyBundle\Entity\AuditLog #Required #doctrine_event_resolver : xiidea.easy_audit.default_doctrine_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_objects : #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 #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_doctrine_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_listeneroption has been removed. You can use this cookbook to achieve the same functionality -
Since v1.2.2
EventResolverInterfacebeen split intoEmbeddedEventResolverInterfaceandEventResolverInterface -
Since v1.3.x The new Event object has been adapted. And the signature of
EmbeddedEventResolverInterfaceandEventResolverInterfacealso changed. Now it expects extra $eventName parameter -
Since v1.4.7
EntityEventResolverbeen refactored to a simplified version, if your code directly depends on older version of the implementation you are advised to copy the content of old implementation from here -
Since v2.0 The FosUserBundle Events are removed from
UserEventResolverand Event class usingSymfony\Contracts\*namespace -
Since v3.0 As
Symfony\Component\Security\Core\Event\AuthenticationEventnot exists anymore,security.authentication.failureresolver also removed.
Cookbook
Look the cookbook for another interesting things.
xiidea/easy-audit 适用场景与选型建议
xiidea/easy-audit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 182.49k 次下载、GitHub Stars 达 91, 最近一次更新时间为 2013 年 11 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Symfony2」 「psr-3」 「Event Log」 「Audit Log」 「audit trail」 「symfony3」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xiidea/easy-audit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xiidea/easy-audit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xiidea/easy-audit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PSR-3 compatible logger with dynamic file naming and hourly rotation, powered by Monolog
Chronolog is a tool that allows you to send logs to files, sockets, mailboxes, databases, etc.
Symfony bundle for broadway/broadway.
Wide logging implementation for PHP - one comprehensive, context-rich event per request
High-performance, zero-dependency PSR-3 logger for MonkeysLegion with structured logging, handlers, processors, and PHP 8.4 features.
Symfony2 Barcode Generator Bundle with Twig function extension
统计信息
- 总下载量: 182.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 91
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-11-16