Register Plugin
If you want to use default logger Bartlett\Reflect\Plugin\Log\DefaultLogger
,
skip this section.
If you want to use your own version of log plugin, use following pattern.
<?php
namespace YourNamespace;
use Bartlett\Reflect\Plugin\LogPlugin as BaseLogPlugin;
class LogPlugin extends BaseLogPlugin
{
// all additional code you need
}
And the configuration in JSON file :
{
"source-providers": [
],
"plugins": [
{
"name": "Logger",
"class": "YourNamespace\\LogPlugin",
"options": []
}
],
"analysers" : [
],
"services": [
]
}
Default logger
Use a solution similar to ErrorLogHandler of Monolog project.
{
"source-providers": [
],
"plugins": [
{
"name": "Logger",
"class": "Bartlett\\Reflect\\Plugin\\LogPlugin",
"options": []
}
],
"analysers" : [
],
"services": [
]
}
It logs records at Psr\Log\LogLevel::INFO
level or highter, identified
by channel name DefaultLoggerChannel
.
Using your private logger
Use your own logger, that must be compatible PSR-3.
<?php
namespace YourNamespace;
use Psr\Log\AbstractLogger;
class YourLogger extends AbstractLogger
{
public function log($level, $message, array $context = array())
{
}
}
And identify it in the JSON config file, as follow
{
"source-providers": [
],
"plugins": [
{
"name": "Logger",
"class": "YourNamespace\\LogPlugin"
}
],
"analysers" : [
],
"services": [
]
}
Or even
{
"source-providers": [
],
"plugins": [
{
"name": "Logger",
"class": "Bartlett\\Reflect\\Plugin\\LogPlugin",
"options": "YourNamespace\\YourLogger"
}
],
"analysers" : [
],
"services": [
]
}
Using Monolog
Use one of the most famous logging solution compatible PSR-3.
If you want to use Monolog with CompatInfo on CLI mode,
then you should use a wrapper like this.
<?php
namespace YourNamespace;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
class YourLogger extends Logger
{
public function __construct($name = 'YourLoggerChannel')
{
$stream = new StreamHandler('/var/logs/phpcompatinfo.log');
parent::__construct($name, array($stream));
}
}
And with JSON config file as follow
{
"source-providers": [
],
"plugins": [
{
"name": "Logger",
"class": "Bartlett\\Reflect\\Plugin\\LogPlugin",
"options": "YourNamespace\\YourLogger"
}
],
"analysers" : [
],
"services": [
]
}