A middleware which could collect the log with json format of laravel application, including everyone request information。It's very friendly to harvest of filebeat
leon19910505/laralog is a Laravel package for a middleware which could collect the log with json format of laravel application, including everyone request information。it's very friendly to harvest of filebeat.
It currently has 0 GitHub stars and 154 downloads on Packagist (latest version v1.1.5).
Install it with composer require leon19910505/laralog.
Discover more Laravel packages by leon19910505
or browse all Laravel packages to compare alternatives.
Last updated
JSON 格式记录到日志文件中JSON 化格式组件,可以无缝使用 Filebeat 采集日志到 ES 中,避免做格式优化方式一
Leon19910505/laralog 包声明到工程项目的 composer.json 文件中composer install 命令安装方式二
$ composer require Leon19910505/laralog
配置文件发布
config 资源文件
php artisan vendor:publish --provider="Leon19910505\Laralog\ServiceProvider"
Laravel Http 中间件app\Http\Kernel.php 文件中,找到 protected $middleware 属性,添加如下声明。
$middleware = [
...
\Leon19910505\Laralog\Http\Middleware\CaptureRequestLifecycle::class,
];
在 .env 配置中设置laralog专用的log channel LOG_API
LOG_API=api
在 config/logging.php 中,设置laralog日志频道 channel 为 api 的日志组件,添加如下配置声明
'api' => [
// Monolog 提供的 driver,保留不变
'driver' => 'daily',
// channel 名称,要与数组键名保持一致
'name' => 'daily',
// 日志存储路径,及日志文件命名
'path' => env('DAILY_LARALOG_STORAGE_PATH', storage_path('logs/api.log')),
// 指定使用的日志格式化组件类
'tap' => [\Leon19910505\Laralog\Formatter\LaralogFormatter::class],
'level' => 'info',
// 日志文件保留天数
'days' => 7,
// 在写日志文件前获得锁,避免并发写入造成的争抢,写错行
'locking'=> true,
],
配置过滤敏感信息的键值,如需新增过滤的敏感信息,在 config/laralog.php 中 except 键对应的数组中,增加待过滤的请求参数键值
return [
'except' => [
'password',
'password_information',
'password_confirm',
'something_to_except',
],
];
配置过滤敏感信息的键值,如需新增过滤的敏感信息,在 config/laralog.php 中 except 键对应的数组中,增加待过滤的请求参数键值
return [
//except 是过滤request参数里不需要的字段
'except' => [
'password',
'password_information',
'password_confirm',
],
//exclude 是过滤返回结构里不要的字段
'exclude' => [
'os',
'performance',
'msg',
'response',
'extra',
'headers',
'hostname',
'version',
'platform',
'end',
'start',
'tag',
],
// extra 是添加额外的字段(业务定制),这里是写入了token的用户信息
'extra' => [
'auth-student' => function () {
return auth()->user()->id ?? '';
},
'auth-teacher' => function () {
return auth('teacher')->user()->id ?? '';
},
],
];
配置日志存储路径,在 .env 文件中新增配置 DAILY_LARALOG_STRORAGE_PATH=/path/to/laralog