mbt/laravel-log-reader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mbt/laravel-log-reader

Composer 安装命令:

composer require mbt/laravel-log-reader

包简介

A Laravel package for reading Laravel log files and returning structured JSON logs.

README 文档

README

A small Laravel package that reads Laravel .log files, parses entries like storage/logs/laravel.log, and returns them as JSON.

Install Locally

If this package lives beside or inside a Laravel app, add it to the app's composer.json:

{
    "repositories": [
        {
            "type": "path",
            "url": "../laravelLog"
        }
    ],
    "require": {
        "mbt/laravel-log-reader": "*"
    }
}

Then run:

composer update mbt/laravel-log-reader

Laravel package discovery will register the service provider automatically.

Usage

By default, the package exposes:

GET /api/logs

Example response:

{
    "logs": [
        {
            "level": "info",
            "date": "2026-07-06 19:13:44",
            "file": "",
            "line": "",
            "message": "User logged in",
            "stacktrace": ""
        }
    ],
    "meta": {
        "current_page": 1,
        "from": 1,
        "last_page": 1,
        "per_page": 25,
        "to": 1,
        "total": 1,
        "search": null,
        "level": null,
        "order": "desc"
    },
    "links": {
        "prev": null,
        "next": null
    }
}

For exceptions, file, line, and stacktrace are filled when they can be detected from the log content.

Search And Pagination

The /api/logs endpoint accepts these query parameters:

?search=payment
?level=error
?page=2
?per_page=25
?order=desc

Examples:

GET /api/logs?search=payment
GET /api/logs?level=error&page=1&per_page=10
GET /api/logs?order=asc

search checks the log level, date, file, line, message, and stack trace. level filters by exact log level, such as info, warning, or error.

Configuration

Publish the config:

php artisan vendor:publish --tag=laravel-log-reader-config

Available options:

return [
    'path' => storage_path('logs/laravel.log'),
    'route' => [
        'enabled' => true,
        'prefix' => 'api',
        'path' => 'logs',
        'middleware' => ['api'],
    ],
    'authorization' => [
        'ability' => null,
    ],
    'pagination' => [
        'per_page' => 25,
        'max_per_page' => 100,
        'order' => 'desc',
    ],
];

Authentication And Authorization

Use authentication middleware before exposing this route outside development. Laravel logs can contain secrets, tokens, emails, SQL queries, and stack traces.

For a token-based API using Sanctum, publish the config and update the middleware:

'route' => [
    'enabled' => true,
    'prefix' => 'api',
    'path' => 'logs',
    'middleware' => ['api', 'auth:sanctum'],
],

Then request the route with a bearer token:

curl -H "Authorization: Bearer YOUR_TOKEN" http://127.0.0.1:8000/api/logs

To add authorization too, define a Gate in your Laravel app's app/Providers/AppServiceProvider.php:

use App\Models\User;
use Illuminate\Support\Facades\Gate;

public function boot(): void
{
    Gate::define('viewLaravelLogs', function (User $user) {
        return (bool) $user->is_admin;
    });
}

Then enable that ability in config/laravel-log-reader.php:

'authorization' => [
    'ability' => 'viewLaravelLogs',
],

Now /api/logs requires both a valid authenticated user and permission from the viewLaravelLogs Gate.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固