PHPackages                             yapro/monolog2db - 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. yapro/monolog2db

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

yapro/monolog2db
================

The handler writes a log record to a database

01PHP

Since Aug 19Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

monolog2db
==========

[](#monolog2db)

The handler writes a log record to a database

If your database is down OR your app has an incorrect password to your database:

- LogRecordHandler will not write to your database
- LogRecordHandler will write to LOG\_FILE\_FOR\_UNEXPECTED\_ERRORS=/your/file.log

Installation
------------

[](#installation)

Register the env variables:

```
MYSQL_VERSION=8
MYSQL_HOST=mysql
MYSQL_PORT=3306
MYSQL_DATABASE=database_name
MYSQL_USERNAME=database_username
MYSQL_PASSWORD=database_password
MYSQL_TABLE_OPTIONALLY=system_log
LOG_FILE_FOR_UNEXPECTED_ERRORS=php://stderr
```

Register the log handler:

```
services:
  YaPro\Monolog2db\LogRecordHandler:
        arguments:
            - '%env(MYSQL_HOST)%'
            - '%env(MYSQL_PORT)%'
            - '%env(MYSQL_DATABASE)%'
            - '%env(MYSQL_USERNAME)%'
            - '%env(MYSQL_PASSWORD)%'
            - '%env(LOG_FILE_FOR_UNEXPECTED_ERRORS)%'
            - '%env(MYSQL_TABLE_OPTIONALLY)%'
```

Configure the monolog ( example from a file config/packages/prod/monolog.yaml )

```
monolog:
    handlers:
        main:
            type: service
            id: YaPro\Monolog2db\LogRecordHandler
        console:
            type: console
            process_psr_3_messages: false
            channels: ["!event", "!doctrine"]
```

Prepare database schema

```
CREATE TABLE system_log (
    id INT AUTO_INCREMENT NOT NULL,
    project_name varchar(255) not null,
    source_name varchar(255) not null,
    level_name varchar(255) not null,
    message TEXT not null,
    datetime DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
    http_request_id varchar(255) not null,
    channel varchar(255) not null,
    context LONGTEXT not null,
    extra LONGTEXT not null,
    PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB;
```

In order for the doctrine to ignore the system\_log table, it is necessary to specify it:

```
doctrine:
    dbal:
        default_connection: connection_mysql
        connections:
            connection_mysql:
                # игнорируем таблицы начинающиеся с префикса monolog https://symfony.com/bundles/DoctrineMigrationsBundle/current/index.html#manual-tables
                schema_filter: ~^(?!system_log)~
                # для нескольких таблиц попробовать: ~^(?!(monolog|sessions))~
                # альтернатива: app/console doctrine:migrations:diff --filter-expression=/^prefix_/
```

And don`t forget to delete the table before starting migrations:

```
# create db schemes:
bin/console doctrine:schema:drop --full-database --force -v
bin/console dbal:run-sql "drop table if exists system_log;"
bin/console doctrine:migrations:migrate --no-interaction -v
```

Tests
-----

[](#tests)

```
docker build -t yapro/monolog2db:latest -f ./Dockerfile ./
docker run --rm -v $(pwd):/app yapro/monolog2db:latest bash -c "cd /app \
  && composer install --optimize-autoloader --no-scripts --no-interaction \
  && /app/vendor/bin/phpunit /app/tests"
```

Dev
---

[](#dev)

```
docker build -t yapro/monolog2db:latest -f ./Dockerfile ./
docker run -it --rm -v $(pwd):/app -w /app yapro/monolog2db:latest bash
composer install -o
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

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.

### Community

Maintainers

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

---

Top Contributors

[![yapro](https://avatars.githubusercontent.com/u/263248?v=4)](https://github.com/yapro "yapro (14 commits)")

### Embed Badge

![Health badge](/badges/yapro-monolog2db/health.svg)

```
[![Health](https://phpackages.com/badges/yapro-monolog2db/health.svg)](https://phpackages.com/packages/yapro-monolog2db)
```

###  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.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

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

41838.2M137](/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)
