PHP code example of leon19910505 / laralog

1. Go to this page and download the library: Download leon19910505/laralog library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leon19910505 / laralog example snippets


    $middleware = [
        ...
        \Leon19910505\Laralog\Http\Middleware\CaptureRequestLifecycle::class,
    ];
    

    '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,
    ],
    

    return [
        'except' => [
            'password',
            'password_information',
            'password_confirm',
            'something_to_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 ?? '';
        },
    ],

    ];

    
sh
        php artisan vendor:publish --provider="Leon19910505\Laralog\ServiceProvider"
        
dotenv
    LOG_API=api