iamthom/audit-log
Composer 安装命令:
composer require iamthom/audit-log
包简介
Logging Plugin for CakePHP
README 文档
README
A logging plugin for CakePHP. The included AuditableBehavior creates an audit history for each instance of a model to which it's attached.
The behavior tracks changes on two levels. It takes a snapshot of the fully hydrated object after a change is complete and it also records each individual change in the case of an update action.
Features
- Support for CakePHP 2.0. Thanks, @jasonsnider.
- Tracks object snapshots as well as individual property changes.
- Allows each revision record to be attached to a source -- usually a user -- of responsibility for the change.
- Allows developers to ignore changes to specified properties. Properties named
created,updatedandmodifiedare ignored by default, but these values can be overwritten. - Handles changes to HABTM associations.
- Fully compatible with the
PolymorphicBehavior. - Does not require or rely on the existence of explicit models revisions (
AuditLog) and deltas (AuditLogDeltas).
Installation
CakePHP >= 2.0
As an Archive
- Click the big ol' Downloads button next to the project description.
- Extract the archive to
app/Plugin/AuditLog.
As a Submodule
$ git submodule add git://github.com/robwilkerson/CakePHP-Audit-Log-Plugin.git <path_to>/app/Plugin/AuditLog$ git submodule init$ git submodule update
To create tables you can use schema shell. To create tables execute:
cd <path_to>/app/
chmod +x ./Console/cake
./Console/cake schema create -p AuditLog
CakePHP 1.3.x
For use with CakePHP 1.3.x, be sure to use code from the 1.3 branch and follow the instructions in that README file.
Next Steps
-
Run the
install.sqlfile on your CakePHP application database. This will create theauditsandaudit_deltastables that will store each object's relevant change history. -
Create a
currentUser()method, if desired.The
AuditableBehavioroptionally allows each changeset to be "owned" by a "source" -- typically the user responsible for the change. Since user and authentication models vary widely, the behavior supports a callback method that should return the value to be stored as the source of the change, if any.The
currentUser()method must be available to every model that cares to track a source of changes, so I recommend that a copy of CakePHP'sapp_model.phpfile be created and the method added there. Keep it DRY, right?Storing the changeset source can be a little tricky if the core
Authcomponent is being used since user data isn't readily available at the model layer where behaviors lie. One option is to forward that data from the controller. One means of doing this is to include the following code inAppController::beforeFilter():if( !empty( $this->data ) && empty( $this->data[$this->Auth->userModel] ) ) { $this->data[$this->Auth->userModel] = $this->currentUser(); }The behavior expects the
currentUser()method to return an associative array with anidkey. Continuing from the example above, the following code might appear in theAppModel:protected function currentUser() { $user = $this->Auth->user(); return $user[$this->Auth->userModel]; # Return the complete user array } -
Attach the behavior to any desired model and configure.
Usage
Applying the AuditableBehavior to a model is essentially the same as applying any other CakePHP behavior. The behavior does offer a few configuration options:
- `ignore`
- An array of property names to be ignored when records are created in the deltas table.
- `habtm`
- An array of models that have a HABTM relationship with the acting model and whose changes should be monitored with the model. If the HABTM model is auditable in its own right, don't include it here. This option is for related models whose changes are _only_ tracked relative to the acting model.
Syntax
# Simple syntax accepting default options
class Task extends AppModel {
public $actsAs = array( 'AuditLog.Auditable' );
#
# Additional model code.
#
}
# Syntax with explicit options
class Task extends AppModel {
public $actsAs = array(
'AuditLog.Auditable' => array(
'ignore' => array( 'active', 'name', 'updated' ),
'habtm' => array( 'Type', 'Project' )
)
);
#
# Additional model code.
#
}
Limitations
- The master branch is not backwards compatible with CakePHP <=1.3.x. If you need compatibility with these version please install the code from the
1.3branch and follow the instructions in that README.
License
This code is licensed under the MIT license.
Notes
Feel free to submit bug reports or suggest improvements in a ticket or fork this project and improve upon it yourself. Contributions welcome.
iamthom/audit-log 适用场景与选型建议
iamthom/audit-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.98k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2013 年 12 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「log」 「logging」 「Audit」 「auditlog」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 iamthom/audit-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 iamthom/audit-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 iamthom/audit-log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Log adding/updating/deleting of elements
Doctrine ORM provider for the auditor audit-log library.
A Zend Framework module that sets up Monolog for logging in applications.
PB Web Media Audit Bundle for Symfony
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 2.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-12-26