yiisoft / log-target-db
Yii Logging Library - DB Target
Fund package maintenance!
Open Collective
yiisoft
Requires
- php: ^7.4|^8.0
- yiisoft/db: ^3.0@dev
- yiisoft/log: ^1.0
- yiisoft/yii-db-migration: ^1.0@dev
Requires (Dev)
- phpunit/phpunit: ^9.4
- roave/infection-static-analysis-plugin: ^1.6
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.4
- yiisoft/db-sqlite: ^3.0@dev
- yiisoft/di: ^3.0@dev
This package is auto-updated.
Last update: 2021-03-23 22:59:40 UTC
README
Yii Logging Library - DB Target
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
Follow updates
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.