dovutuan/lalog

Logging query laravel

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/dovutuan/lalog

1.0.0 2025-08-15 15:54 UTC

This package is auto-updated.

Last update: 2026-01-12 03:39:31 UTC


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.