subjective-php / psr-log-mongodb
A concrete implementation of the PSR LoggerInterface using mongo
Installs: 11 267
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.0||^8.0
- ext-mongodb: *
- mongodb/mongodb: ^1.0
- psr/log: ^1.0
- subjective-php/psr-log-helper: ^3.0
- subjective-php/util-exceptions: ^4.0
Requires (Dev)
- phpunit/phpunit: >=6.5
- squizlabs/php_codesniffer: ^3.3
Provides
This package is auto-updated.
Last update: 2024-11-08 22:14:27 UTC
README
This is an implementation of PSR-3 using MongoDB as backend storage.
Document Structure
Each mongo document constructed will have the following fields.
- timestamp The current UTC date/time
- level The RFC-5424 Log Level
- message The log message
- context Extraneous information that does not fit well in a string
Example Document
{ "_id" : ObjectId("57fc0050fc77ae5c017e52b1"), "timestamp" : ISODate("2016-10-08T02:02:12.944Z"), "level" : "info", "message" : "api access", "context" : { "method" : "GET", "resource" : "/widgets/123", "status" : 200 } }
The logger does not handle log retention. Expire Data from Collections by Setting TTL
Basic Usage
<?php use SubjectivePHP\Psr\Log\MongoLogger; use MongoDB\Client; $collection = (new Client())->selectDatabase('testing')->selectCollection('logs'); $logger = new MongoLogger($collection); $logger->debug('Some debug info');
Message/Context Interpolation
The message may contain placeholders which can be replaced with values from the context array. In the example below the final logged message will be
User chadicus was created
<?php use SubjectivePHP\Psr\Log\MongoLogger; use MongoDB\Client; $collection = (new Client())->selectDatabase('testing')->selectCollection('logs'); $logger = new MongoLogger($collection); $logger->info('User {username} was created', ['username' => 'chadicus']);
Requirements
PSR Log MongoDB requires PHP 7.0 (or later).
Composer
To add the library as a local, per-project dependency use Composer! Simply add a dependency on subjective-php/psr-log-mongodb
to your project's composer.json
.
composer require subjective-php/psr-log-mongodb
Contact
Developers may be contacted at:
Run Build
With a checkout of the code get Composer in your PATH and run:
composer install ./vendor/bin/phpunit ./vendor/bin/phpcs