bayfrontmedia/monolog-pdo

Monolog handler used to write log files to a MySQL database.

v1.0.0 2023-08-18 04:59 UTC

This package is auto-updated.

Last update: 2024-05-18 06:45:32 UTC


README

Monolog handler used to write log files to a MySQL database.

License

This project is open source and available under the MIT License.

Author

Bayfront Media

Requirements

  • PHP >= 8.0
  • PDO PHP extension

Installation

composer require bayfrontmedia/monolog-pdo

Usage

Before pushing this handler to a Logger instance, you must first create the necessary database table to store the records.

The table can be created using the up method, and removed using the down method.

The constructor requires a PDO instance, and the table name you wish to use:

use Bayfront\MonologPDO\PDOHandler;

/** @var PDO $pdo */
$handler = new PDOHandler($pdo, 'table_name');

$handler->up();

Once the table has been created, the handler can be pushed to a Logger instance:

use Bayfront\MonologPDO\PDOHandler;
use Monolog\Logger;

$log = new Logger('channel_name');

/** @var PDO $pdo */
$handler = new PDOHandler($pdo, 'table_name');

$log->pushHandler($handler);

From here, your log records should appear in the MySQL table.