PHPackages                             detain/monolog-mydb - 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. [Database &amp; ORM](/categories/database)
4. /
5. detain/monolog-mydb

ActiveLibrary[Database &amp; ORM](/categories/database)

detain/monolog-mydb
===================

A handler for Monolog that sends messages to MySQL

v3.0.0(6y ago)4143MITPHPCI failing

Since Sep 13Pushed 2y agoCompare

[ Source](https://github.com/detain/monolog-mysql)[ Packagist](https://packagist.org/packages/detain/monolog-mydb)[ Docs](https://github.com/detain/monolog-mysql)[ RSS](/packages/detain-monolog-mydb/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (9)Used By (0)

monolog-mysql
=============

[](#monolog-mysql)

MySQL Handler for Monolog, which allows to store log messages in a MySQL Table. It can log text messages to a specific table, and creates the table automatically if it does not exist. The class further allows to dynamically add extra attributes, which are stored in a separate database field, and can be used for later analyzing and sorting.

HELP WANTED
===========

[](#help-wanted)

As I do not use this project myself anymore and I do not find the time to maintain this project as it deserves I would be happy to find someone taking it over. Please contact me at  if you'd be interesting to take over that project. Thanks!

Installation
============

[](#installation)

monolog-mysql is available via composer. Just add the following line to your required section in composer.json and do a `php composer.phar update`.

```
"wazaari/monolog-mysql": ">1.0.0"

```

Usage
=====

[](#usage)

Just use it as any other Monolog Handler, push it to the stack of your Monolog Logger instance. The Handler however needs some parameters:

- **$pdo** PDO Instance of your database. Pass along the PDO instantiation of your database connection with your database selected.
- **$table** The table name where the logs should be stored
- **$additionalFields** simple array of additional database fields, which should be stored in the database. The columns are created automatically, and the fields can later be used in the extra context section of a record. See examples below. *Defaults to an empty array()*
- **$level** can be any of the standard Monolog logging levels. Use Monologs statically defined contexts. *Defaults to Logger::DEBUG*
- **$bubble** *Defaults to true*
- **$skipDatabaseModifications** Defines whether we should skip any attempts to sync current database state with what's requested by the code (includes creating the table and adding / dropping fields). *Defaults to false*

If $skipDatabaseModifications is set to true, please use the following query as a template to create the log table (with additional fields, if necessary)

```
CREATE TABLE `log` (
    id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, channel VARCHAR(255), level INTEGER, message LONGTEXT, time INTEGER UNSIGNED, INDEX(channel) USING HASH, INDEX(level) USING HASH, INDEX(time) USING BTREE
)
```

Examples
========

[](#examples)

Given that $pdo is your database instance, you could use the class as follows:

```
//Import class
use MySQLHandler\MySQLHandler;

//Create MysqlHandler
$mySQLHandler = new MySQLHandler($pdo, "log", array('username', 'userid'), \Monolog\Logger::DEBUG);

//Create logger
$logger = new \Monolog\Logger($context);
$logger->pushHandler($mySQLHandler);

//Now you can use the logger, and further attach additional information
$logger->addWarning("This is a great message, woohoo!", array('username'  => 'John Doe', 'userid'  => 245));
```

License
=======

[](#license)

This tool is free software and is distributed under the MIT license. Please have a look at the LICENSE file for further information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~313 days

Recently: every ~430 days

Total

7

Last Release

2378d ago

Major Versions

v1.0.4 → v2.0.02019-11-05

v2.0.0 → v3.0.02019-11-05

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![waza-ari](https://avatars.githubusercontent.com/u/4508976?v=4)](https://github.com/waza-ari "waza-ari (29 commits)")[![youaresodalgona](https://avatars.githubusercontent.com/u/32331576?v=4)](https://github.com/youaresodalgona "youaresodalgona (13 commits)")[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (8 commits)")[![stefandoorn](https://avatars.githubusercontent.com/u/4903082?v=4)](https://github.com/stefandoorn "stefandoorn (6 commits)")[![kovenant](https://avatars.githubusercontent.com/u/3716657?v=4)](https://github.com/kovenant "kovenant (2 commits)")[![kermorgant](https://avatars.githubusercontent.com/u/10561580?v=4)](https://github.com/kermorgant "kermorgant (2 commits)")[![squirrelcrmhub](https://avatars.githubusercontent.com/u/21302229?v=4)](https://github.com/squirrelcrmhub "squirrelcrmhub (1 commits)")[![mend-bolt-for-github[bot]](https://avatars.githubusercontent.com/in/16809?v=4)](https://github.com/mend-bolt-for-github[bot] "mend-bolt-for-github[bot] (1 commits)")[![dzuelke](https://avatars.githubusercontent.com/u/27900?v=4)](https://github.com/dzuelke "dzuelke (1 commits)")[![lpotherat](https://avatars.githubusercontent.com/u/380424?v=4)](https://github.com/lpotherat "lpotherat (1 commits)")[![clement-garrigou](https://avatars.githubusercontent.com/u/10114508?v=4)](https://github.com/clement-garrigou "clement-garrigou (1 commits)")[![nickgravel](https://avatars.githubusercontent.com/u/918742?v=4)](https://github.com/nickgravel "nickgravel (1 commits)")[![sashotoster](https://avatars.githubusercontent.com/u/17530843?v=4)](https://github.com/sashotoster "sashotoster (1 commits)")

---

Tags

logloggingdatabasemysqlmonolog

### Embed Badge

![Health badge](/badges/detain-monolog-mydb/health.svg)

```
[![Health](https://phpackages.com/badges/detain-monolog-mydb/health.svg)](https://phpackages.com/packages/detain-monolog-mydb)
```

###  Alternatives

[wazaari/monolog-mysql

A handler for Monolog that sends messages to MySQL

140884.1k6](/packages/wazaari-monolog-mysql)[danielme85/laravel-log-to-db

Custom Laravel Log channel handler that can store log events to SQL or MongoDB databases. Uses Laravel native logging functionality.

135934.5k1](/packages/danielme85-laravel-log-to-db)[bradmkjr/monolog-wordpress

A handler for Monolog that sends messages to MySQL via WordPress Functions

2817.1k](/packages/bradmkjr-monolog-wordpress)[karelwintersky/monolog-pdo-handler

A handler for Monolog that stores data via PDO driver to Database

109.0k1](/packages/karelwintersky-monolog-pdo-handler)

PHPackages © 2026

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