PHPackages                             edquint/sql-logger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. edquint/sql-logger

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

edquint/sql-logger
==================

Library for generating SQL logs from ORMs and raw queries

v1.1.0(9mo ago)04MITPHPPHP &gt;=5.2.4

Since Aug 3Pushed 9mo agoCompare

[ Source](https://github.com/edquint/sql-logger)[ Packagist](https://packagist.org/packages/edquint/sql-logger)[ RSS](/packages/edquint-sql-logger/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (6)Used By (0)

📄 Leia esta documentação em [Português 🇧🇷](README.pt.md)

[![Maintainer](https://camo.githubusercontent.com/b8bfb910eeaea97d54217226b16168bc471aa777821913f80c4283f3f1f27986/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6d61696e7461696e65722d4065647175696e742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://github.com/edquint)[![PHP from Packagist](https://camo.githubusercontent.com/7136b05a0396dfb5380dd0dc391117cfb372ccd5b84e5f3fafa34da57101e43e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f65647175696e742f73716c2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/edquint/sql-logger)[![Latest Version](https://camo.githubusercontent.com/09fd710e40821b725194b820fe935bb81dc07c5bb261ba0d74b376c9a61c8650/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f65647175696e742f73716c2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://github.com/edquint/sql-logger/releases/)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/edquint/sql-logger/blob/main/LICENSE)[![Total Downloads](https://camo.githubusercontent.com/756a23928523a4cc7d762f1c0b507ec1a1f274384e12f712a40f922156a06870/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f65647175696e742f73716c2d6c6f676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/edquint/sql-logger)

PHP SQL Logger
==============

[](#php-sql-logger)

A simple library to generate SQL query logs and write them to log files.
Useful for inspecting how queries are being built, whether using **ORMs** like **Doctrine 1**, **Doctrine 2**, and **Eloquent**, or **raw** SQL queries.

📦 Installation
--------------

[](#-installation)

Add the library to your project via Composer:

```
composer require edquint/sql-logger
```

🚀 Features
----------

[](#-features)

- Automatically captures queries generated by popular ORMs.
- Supports **raw** queries.
- Saves logs to files in a configurable way.
- Easy integration into PHP projects.

#### Supported ORMs

[](#supported-orms)

- Doctrine 1
- Doctrine 2
- Eloquent

⚙️ Configuration
----------------

[](#️-configuration)

Configuration is done through the **`LoggerConfig`** class, where you define:

- Directory for the log files.
- Name of the log file.
- Additional options.

Example:

```
use SqlLogger\Settings\LoggerConfig;

LoggerConfig::setLogPath(__DIR__ . '/logs'); // Path where logs will be saved
LoggerConfig::setFileName('queries.log');    // Log file name
```

✅ How to Use
------------

[](#-how-to-use)

The main class for generating logs is **`LogSql`**.

### 1. Logging ORM queries

[](#1-logging-orm-queries)

If you're using a supported ORM, simply pass the query instance to the `orm` method:

```
use SqlLogger\LogSql;

// Example with an ORM query (Doctrine, Eloquent, etc.)
LogSql::orm($query);

// Alternatively, using the global helper function
sql_logger($query);
```

This will convert the query to a formatted string and save it to the configured file.

---

### 2. Logging RAW (manual) queries

[](#2-logging-raw-manual-queries)

For manual SQL queries, just pass the query and parameters to the `raw` method:

```
use SqlLogger\LogSql;

$params = ['id' => 10];
$sql = "SELECT * FROM users WHERE id = :id";

LogSql::raw($sql, $params);

// Alternatively, using the global helper function
sql_logger($sql, $params);
```

🔍 Log Output
------------

[](#-log-output)

The log will be saved in the configured directory in the following format:

```
[2025-08-02 19:00:00] Sql Query:
SELECT
  *
FROM
  users
WHERE
  id = 10

```

---

### 📄 License

[](#-license)

This project is licensed under the **MIT** license. You can view the full license text in the [`LICENSE`](./LICENSE) file.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance61

Regular maintenance activity

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

276d ago

PHP version history (2 changes)v1.0.1PHP &gt;=5.0

v1.1.0PHP &gt;=5.2.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/45cf2d314fe49e9827582c2e523684a6b87a12db3ecfd01c8270ec1093bf7e18?d=identicon)[edquint](/maintainers/edquint)

---

Top Contributors

[![edquint](https://avatars.githubusercontent.com/u/22418438?v=4)](https://github.com/edquint "edquint (7 commits)")

### Embed Badge

![Health badge](/badges/edquint-sql-logger/health.svg)

```
[![Health](https://phpackages.com/badges/edquint-sql-logger/health.svg)](https://phpackages.com/packages/edquint-sql-logger)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.1k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M93](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M136](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
