yiisoft / log-target-db
Yii Logging Library - DB Target
Fund package maintenance!
Open Collective
yiisoft
Installs: 143
Dependents: 0
Suggesters: 1
Security: 0
Stars: 10
Watchers: 14
Forks: 3
Open Issues: 2
Requires
- php: ^8.0
- ext-pdo: *
- psr/log: ^3.0
- yiisoft/db: ^3.0@dev
- yiisoft/log: ^2.0
- yiisoft/yii-db-migration: ^1.0@dev
Requires (Dev)
- maglnet/composer-require-checker: ^4.2
- phpunit/phpunit: ^9.5
- rector/rector: ^0.15.1
- roave/infection-static-analysis-plugin: ^1.25
- spatie/phpunit-watcher: ^1.23
- vimeo/psalm: ^4.30|^5.2
- yiisoft/db-sqlite: ^3.0@dev
- yiisoft/di: ^1.0
- yiisoft/test-support: ^3.0
- yiisoft/yii-event: ^1.0@dev
This package is auto-updated.
Last update: 2023-03-14 15:17:36 UTC
README
Yii Logging Library - DB Target
This package provides the Database target for the yiisoft/log library.
Requirements
- PHP 8.0 or higher.
PDO
PHP extension.
Installation
The package could be installed with composer:
composer require yiisoft/log-target-db --prefer-dist
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.
Testing
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 with Infection Static Analysis Plugin. To run it:
./vendor/bin/roave-infection-static-analysis-plugin
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.