Yii Logging Library - DB Target

dev-master / 3.0.x-dev 2021-03-23 22:51 UTC

This package is auto-updated.

Last update: 2021-03-23 22:59:40 UTC



Yii Logging Library - DB Target

Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage

This package provides the Database target for the yiisoft/log library.


The package could be installed with composer:

composer require yiisoft/log-target-db

General usage

Creating a target:

$dbTarget = new \Yiisoft\Log\Target\Db\DbTarget($db, $table);
  • $db (\Yiisoft\Db\Connection\ConnectionInterface) - The database connection instance.
  • $table (string) - The name of the database table to store the log messages. Defaults to "log".

Creating a logger:

$logger = new \Yiisoft\Log\Logger([$dbTarget]);

You can use multiple databases to store log messages:

 * @var \Yiisoft\Db\Connection\ConnectionInterface $mysqlDb
 * @var \Yiisoft\Db\Connection\ConnectionInterface $redisDb

$logger = new \Yiisoft\Log\Logger([
    new \Yiisoft\Log\Target\Db\DbTarget($mysqlDb),
    new \Yiisoft\Log\Target\Db\DbTarget($redisDb),

For a description of using the logger, see the yiisoft/log package.

For use in the Yii framework, see the configuration files:

You need to set up a database connection and run this console command to create tables to store the log messages:

./yii migrate/up

See Yii guide to logging for more info.

Unit testing

The package is tested with PHPUnit. To run tests:


Mutation testing

The package tests are checked with Infection mutation framework. To run it:


Static analysis

The code is statically analyzed with Psalm. To run static analysis:


Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack


The Yii Logging Library - DB Target is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.