承接 moe-mizrak/laravel-log-reader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

moe-mizrak/laravel-log-reader

Composer 安装命令:

composer require moe-mizrak/laravel-log-reader

包简介

Lightweight Laravel package for reading, searching, and filtering logs from both file and database sources.

README 文档

README

Lightweight Laravel package for searching and filtering logs from both file and database sources.

This package provides the core log reading functionality used by the Laravel MCP Log (MCP tool for Laravel log analysing with AI.).

Installation

You can install the package (that you created with this template) via composer:

composer require moe-mizrak/laravel-log-reader

You can publish and run the migrations with:

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

Usage

You can use the package to read, search, and filter logs from both file and database sources.

If your logs are stored in files (laravel.log), in the config file (laravel-log-reader.php) set the driver to file as:

'driver' => env('LOG_READER_DRIVER', LogDriverType::FILE->value), // in .env file LOG_READER_DRIVER=file

And set the log file path as:

'path' => env('LOG_FILE_PATH', storage_path('logs/laravel.log')), // in .env file LOG_FILE_PATH=/full/path/to/laravel.log

And also you can set a limit, chunk size as:

'chunk_size' => env('LOG_READER_FILE_CHUNK_SIZE', 512 * 1024), // 512KB for file reading
'limit' => env('LOG_READER_FILE_QUERY_LIMIT', 10000),

Service provider automatically resolves the correct log reader (FileLogReader) and you can use it as:

use MoeMizrak\LaravelLogReader\Facades\LogReader;
use MoeMizrak\LaravelLogReader\Enums\FilterKeyType;

$query = 'User authentication';
$filters = [FilterKeyType::LEVEL->value => 'info'];

$result = LogReader::search($query)->filter($filters)->chunk()->execute();

If your logs are stored in database (log_entries table), in the config file (laravel-log-reader.php) set the driver to db as:

'driver' => env('LOG_READER_DRIVER', LogDriverType::DB->value), // in .env file LOG_READER_DRIVER=db

Set the connection and table name as:

'table' => env('LOG_DB_TABLE', 'log_entries'), // in .env file LOG_DB_TABLE=log_entries
'connection' => env('LOG_DB_CONNECTION'), // in .env file LOG_DB_CONNECTION=mysql

And set the database columns mapping and searchable columns as:

// Column mapping: maps DB columns to LogData properties
'columns' => [
    LogTableColumnType::ID->value => 'id',
    LogTableColumnType::LEVEL->value => 'level', // e.g. 'ERROR', 'INFO'
    LogTableColumnType::MESSAGE->value => 'message', // main log message
    LogTableColumnType::TIMESTAMP->value => 'created_at', // time of the log entry (e.g. 'created_at' or 'logged_at')
    LogTableColumnType::CHANNEL->value => 'channel', // e.g. 'production', 'local'
    LogTableColumnType::CONTEXT->value => 'context', // additional context info, often JSON e.g. '{"action":"UserLogin"}'
    LogTableColumnType::EXTRA->value => 'extra', // any extra data, often JSON e.g. '{"ip":172.0.0.1, "session_id":"abc", "user_id":123}'
],
       
'searchable_columns' => [
    ['name' => LogTableColumnType::MESSAGE->value, 'type' => ColumnType::TEXT->value],
    ['name' => LogTableColumnType::CONTEXT->value, 'type' => ColumnType::JSON->value],
    ['name' => LogTableColumnType::EXTRA->value, 'type' => ColumnType::JSON->value],
],

And also you can set a limit, chunk size as:

'limit' => env('LOG_READER_DB_QUERY_LIMIT', 10000), // max number of records to fetch in queries
'chunk_size' => env('LOG_READER_DB_CHUNK_SIZE', 500), // number of records per chunk when chunking is enabled

And you can use it as:

use MoeMizrak\LaravelLogReader\Facades\LogReader;
use MoeMizrak\LaravelLogReader\Enums\FilterKeyType;

$query = 'User authentication';
$filters = [FilterKeyType::DATE_FROM->value => '2025-01-01', FilterKeyType::DATE_TO->value => '2025-12-31'];

$result = LogReader::search($query)->filter($filters)->chunk()->execute();

Note: You can chain the search, filter, and chunk methods in any order before calling execute. The search method performs a search on searchable fields (like message, context, etc.) based on the provided query (in config we have searchable_columns so that it can be customized).

TODO

  • Add a log_insights migration/table which will be a normalized, summarized, and searchable table.
  • It unifies different log mechanisms into a single canonical format, enabling faster lookups over large data.
  • A background task should sync new log data periodically, basically everyday it summarizes the previous day's logs and inserts them into log_insights.
  • Be aware that summarization may lose some details (e.g., exact errors or stack traces).
  • Add support for cloud log readers (AWS CloudWatch, Azure Monitor, Google Cloud Logging).
  • Add streaming responses, either as a parameter to search/filter methods or as a new method like searchStream using cursors, yields, or $builder->lazy($chunkSize).
  • Use a cheap/free model to summarize large log files before search/filter (experimental approach).
  • Refine LOG_PATTERN in FileLogReader to handle more real-world log formats.
  • Move user_id, request_id, and ip_address into dedicated columns instead of using the extra field.

Contributing

Your contributions are welcome! If you'd like to improve this project, simply create a pull request with your changes. Your efforts help enhance its functionality and documentation.

If you find this project useful, please consider ⭐ it to show your support!

Authors

This project is created and maintained by Moe Mizrak.

License

Laravel Package Template is an open-sourced software licensed under the MIT license.

moe-mizrak/laravel-log-reader 适用场景与选型建议

moe-mizrak/laravel-log-reader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 61 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「laravel-log-reader」 「php 8」 「Moe Mizrak」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 moe-mizrak/laravel-log-reader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 moe-mizrak/laravel-log-reader 我们能提供哪些服务?
定制开发 / 二次开发

基于 moe-mizrak/laravel-log-reader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-14