承接 hesamrad/laravel-sql-logger 相关项目开发

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

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

hesamrad/laravel-sql-logger

Composer 安装命令:

composer require hesamrad/laravel-sql-logger

包简介

A lightweight package to log SQL queries in your Laravel application

README 文档

README

A lightweight package to log SQL queries in your Laravel application; perfect for debugging and performance analysis during development.

Installation

Install via Composer:

composer require hesamrad/laravel-sql-logger --dev

The package will automatically register its service provider.

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="HesamRad\LaravelSqlLogger\LaravelSqlLoggerServiceProvider"

This will create config/sql-logger.php config file.

Usage

Once installed and configured, SQL logging will automatically start based on your configuration.

Viewing Logs

SQL queries are logged to storage/logs/sql.log by default. You can view them with:

# Tail the log file (Linux/Mac)
tail -f storage/logs/sql.log

# View entire log
cat storage/logs/sql.log

Example Output

[2024-01-15 10:30:45] [2.5ms] select * from `users` where `email` = ? ["user@example.com"]
[2024-01-15 10:30:45] [1.2ms] select * from `posts` where `user_id` = ? [1]
[2024-01-15 10:30:45] [0.8ms] select * from `comments` where `post_id` in (?, ?, ?) [1, 2, 3]
------------------------------------------------------------
[2024-01-15 10:31:12] [3.1ms] insert into `users` (`name`, `email`) values (?, ?) ["John Doe", "john@example.com"]
[2024-01-15 10:31:12] [1.5ms] select * from `users` where `id` = ? [42]
------------------------------------------------------------

Troubleshooting

Log file not created

  1. Check storage/logs directory permissions:
    chmod 775 storage/logs
    chown www-data:www-data storage/logs
  2. Verify APP_DEBUG=true in your .env
  3. Check current environment is in allowed_envs
  4. Ensure not running in console mode

Empty or incomplete logs

  1. Try disabling file locking:
    'file_lock' => false,
  2. Check disk space
  3. Verify PHP has write permissions

Performance issues

  1. Set file_lock' => false
  2. Only enable in specific environments
  3. Monitor log file size

Multiple separator lines

This indicates the service provider is being instantiated multiple times. Ensure:

  • You're using the latest version
  • static $attached property is working correctly
  • Only one instance of the provider exists

Security Considerations

⚠️ Important Security Notes:

  1. Never enable in production unless absolutely necessary
  2. SQL logs may contain sensitive data (emails, passwords, personal info)
  3. Secure the log file:
    chmod 640 storage/logs/sql.log
    chown www-data:www-data storage/logs/sql.log
  4. Regularly rotate and delete old logs

Support

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Search existing issues
  3. Create a new issue

License

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

Credits

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固