protechstudio/oplogger
Composer 安装命令:
composer require protechstudio/oplogger
包简介
It offers a convenient way to create a user operation log for any Laravel 5 application. Supports parameters and writes log to database by default but can also be linked to different repositories.
README 文档
README
It offers a convenient and fast way to create a user operation log for any Laravel 5 application. It supports parameters and writes log to database by default but can also be used with a custom repository.
Installation
Require this package with composer using the following command:
composer require protechstudio/oplogger
After updating composer, add the service provider to the providers array in config/app.php
Protechstudio\Oplogger\OploggerProvider::class,
You may also add the Facade in the aliases array in config/app.php
'Oplogger' => Protechstudio\Oplogger\Facades\Oplogger::class,
Finally publish the configuration and migration files using the artisan command
php artisan vendor:publish --provider="Protechstudio\Oplogger\OploggerProvider"
You may also publish only the configuration file or the migration using the associated config and migrations tags
php artisan vendor:publish --provider="Protechstudio\Oplogger\OploggerProvider" --tag="config"
php artisan vendor:publish --provider="Protechstudio\Oplogger\OploggerProvider" --tag="migrations"
Run the migration ( only needed if you intend to use the internal repository )
php artisan migrate
Configuration
Open the published configuration file at config/oplogger.php:
return [ 'types' => [ 'test' => 'Basic operation for testing purposes.' ], 'repository' => Protechstudio\Oplogger\Repositories\LogRepository::class ];
Then populate the types array with all operation types with their specific message.
If you intend to use a custom repository you must edit the repository element.
Using a custom repository
The custom repository must implement the LogRepositoryContract as in the example below:
... use Protechstudio\Oplogger\Repositories\LogRepositoryContract; class CustomRepository implements LogRepositoryContract { //your custom repository implementation }
Usage
You may use the Oplogger service in two ways:
Using the dependency or method injection
... use Protechstudio\Oplogger\Oplogger; class FooController extends Controller { private $oplogger; public function __construct(Oplogger $oplogger) { $this->oplogger = $oplogger; } public function bar() { $this->oplogger->write('test'); } }
Using the Facade
... use Oplogger; public function bar() { Oplogger::write('test'); }
Adding parameters to the operation string
The write method uses the vsprintf function internally so you may easily add any parameter you need to the type operation string in the config/oplogger.php
'types' => [ 'test' => 'Basic operation for testing purposes.', 'myoperation' => 'Has made %d operations using %s', ],
Then you can pass an array of parameters as the second argument of the write method
Oplogger::write('myoperation',[4,'parameters']); // Result will be: 'Has made 4 operations using parameters'
For advance use of parameters please check the vsprintf documentation.
Operation associated user
Oplogger automatically retrieves the logged in user using the Laravel Auth system. If you prefer you may also force to log the operation with a specific user passing the user id as the third argument
$userid=5; Oplogger::write('test',[],$userid);
The internal repository
If you are using the internal repository, running the published migration will create a logs table with user_id, operation and laravel timestamp fields.
Please note that if you are not using the laravel default users table for users you should edit the migration accordingly or an exception will be thrown due to the user_id foreign key constraint.
You may access the underlying Log model adding use Protechstudio\Oplogger\Models\Log; to the use statements.
Exceptions
Typing a wrong operation type key
If the operation key you type in the write method is not present in your configuration types array an OploggerKeyNotFoundException exception will be thrown.
Not providing a user for the operation
If you don't provide a specific user for the operation and the user is not logged in an OploggerUserNotLoggedException exception will be thrown.
protechstudio/oplogger 适用场景与选型建议
protechstudio/oplogger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 291 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 protechstudio/oplogger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 protechstudio/oplogger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 291
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-13