yiisoft/log-target-db

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


README

68747470733a2f2f796969736f66742e6769746875622e696f2f646f63732f696d616765732f7969695f6c6f676f2e737667

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.

Installation

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:

./vendor/bin/phpunit

Mutation testing

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

./vendor/bin/infection

Static analysis

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

./vendor/bin/psalm

Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack

License

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.