dovutuan/lalog 问题修复 & 功能扩展

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

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

dovutuan/lalog

最新稳定版本:1.0.0

Composer 安装命令:

composer require dovutuan/lalog

包简介

Logging query laravel

README 文档

README

Latest Version License Latest Stable Version Total Downloads Latest Unstable Version License

A simple and efficient Laravel package for logging database queries with automatic file rotation and customizable storage options.

Features

  • 📜 Logs all executed queries with bindings and execution time.
  • 📅 Daily log files with automatic rotation based on file size.
  • ⚙️ Configurable log storage disk, directory, and formatting.
  • 🔄 Supports Laravel versions 7.x → 12.x.
  • 🚀 Easy integration via Service Provider.

📦 Installation

Install via Composer:

composer require --dev dovutuan/lalog

Publish the configuration file:

php artisan vendor:publish --provider="Dovutuan\Lalog\ServiceProvider" --tag="lalog"

⚙️ Configuration

Edit config/lalog.php to customize your logging preferences:

<?php

return [
    'enabled' => env('LALOG_QUERY', false),
    'disk' => env('LALOG_DISK', 'local'),
    'storage' => [
        'directory_path' => env('LALOG_DIRECTORY', 'query-logs'),
        'max_file_size_bytes' => env('LALOG_MAX_SIZE', 2097152), // 2MB
    ],
    'formatting' => [
        'log_file_date_format' => 'Y-m-d',         // File name format
        'query_timestamp_format' => 'Y-m-d H:i:s', // Log entry format
    ],
];

🚀 Basic Usage

Enable query logging by setting the environment variable in your .env file:

LALOG_QUERY=true

That's it! Your Laravel application will now automatically log all database queries.

🔍 Sample Output

Query logs will be formatted like this:

---------- QUERY LOG START ----------
Execution Time: 2023-05-15 14:30:45
Duration: 5.2 ms
Query: SELECT * FROM users WHERE id = '1';
---------- QUERY LOG END ----------

📂 Log Rotation

When a log file reaches the maximum size (default 2MB), a new file is automatically created with an incrementing index:

query-logs/
  ├── sql-2023-05-15.sql
  ├── sql-2023-05-15-1.sql
  └── sql-2023-05-15-2.sql

🛠 Advanced Usage

Using the Facade

You can manually record queries using the LaLog facade:

use Dovutuan\Lalog\Facades\LaLog;

LaLog::recordQuery($query);

Custom Storage Disk

Configure a custom disk for query logs in config/filesystems.php:

'disks' => [
    'query-logs' => [
        'driver' => 'local',
        'root' => storage_path('logs/queries'),
    ],
],

Then update your .env file:

LALOG_DISK=query-logs

Environment Variables

Available environment variables for configuration:

Variable Default Description
LALOG_QUERY false Enable/disable query logging
LALOG_DISK local Storage disk to use
LALOG_DIRECTORY query-logs Directory name for log files
LALOG_MAX_SIZE 2097152 Maximum file size in bytes (2MB)

🧪 Testing

Run the test suite:

composer test

🤝 Contributing

Pull requests are welcome! Please see CONTRIBUTING.md for details on how to contribute to this project.

📜 License

This package is open-sourced software licensed under the MIT license.

🐛 Issues

If you discover any security vulnerabilities or bugs, please report them via the GitHub Issues page.

📈 Changelog

Please see CHANGELOG.md for more information on what has changed recently.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-15